From: Lennart Poettering Date: Wed, 16 Feb 2011 19:34:59 +0000 (+0100) Subject: systemctl: introduce --failed to show only failed services X-Git-Tag: v18~2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=30732560c415f52d2a58fc8fab10b602a40c7274 systemctl: introduce --failed to show only failed services --- diff --git a/TODO b/TODO index 65a102c4f..aa405e6b5 100644 --- a/TODO +++ b/TODO @@ -5,8 +5,6 @@ Bugs: * when plymouth is disabled the console password entry stuff seems to be borked https://bugzilla.redhat.com/show_bug.cgi?id=655538 -* systemctl default is started when we type "reboot" at rescue mode prompt - * exclude java hsp files by default https://bugzilla.redhat.com/show_bug.cgi?id=527425 @@ -14,8 +12,6 @@ Features: * add --ignore-deps to systemctl -* add --failed to systemctl - * increase password timeout * look up crypto partition mount points via fstab to show to the user when prompting for a password diff --git a/man/systemctl.xml b/man/systemctl.xml index c21ed8556..c45b11a51 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -126,6 +126,15 @@ they are set or not. + + + + When listing units, + show only failed units. Do not confuse + with + . + + @@ -144,7 +153,9 @@ unfinished job, fail the command. If this is not specified the requested operation will replace the pending job, - if necessary. + if necessary. Do not confuse + with + . diff --git a/src/systemctl-bash-completion.sh b/src/systemctl-bash-completion.sh index 3e3380c8e..834e11dbe 100644 --- a/src/systemctl-bash-completion.sh +++ b/src/systemctl-bash-completion.sh @@ -42,7 +42,7 @@ _systemctl () { local verb comps local -A OPTS=( - [STANDALONE]='--all -a --defaults --fail --force -f --full --global + [STANDALONE]='--all -a --defaults --fail --failed --force -f --full --global --help -h --no-ask-password --no-block --no-reload --no-wall --order --require --quiet -q --system --user --version' [ARG]='--kill-mode --kill-who --property -p --signal -s --type -t' diff --git a/src/systemctl.c b/src/systemctl.c index dfa952ed4..df4fccc14 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -76,6 +76,7 @@ static bool arg_full = false; static bool arg_force = false; static bool arg_defaults = false; static bool arg_ask_password = false; +static bool arg_failed = false; static char **arg_wall = NULL; static const char *arg_kill_who = NULL; static const char *arg_kill_mode = NULL; @@ -347,9 +348,12 @@ static int compare_unit_info(const void *a, const void *b) { return strcasecmp(u->id, v->id); } -static bool output_show_job(const struct unit_info *u) { +static bool output_show_unit(const struct unit_info *u) { const char *dot; + if (arg_failed) + return streq(u->active_state, "failed"); + return (!arg_type || ((dot = strrchr(u->id, '.')) && streq(dot+1, arg_type))) && (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0); @@ -364,7 +368,7 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) { job_len = sizeof("JOB")-1; for (u = unit_infos; u < unit_infos + c; u++) { - if (!output_show_job(u)) + if (!output_show_unit(u)) continue; active_len = MAX(active_len, strlen(u->active_state)); @@ -388,7 +392,7 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) { const char *on_loaded, *off_loaded; const char *on_active, *off_active; - if (!output_show_job(u)) + if (!output_show_unit(u)) continue; n_shown++; @@ -4190,6 +4194,7 @@ static int systemctl_help(void) { " -t --type=TYPE List only units of a particular type\n" " -p --property=NAME Show only properties by this name\n" " -a --all Show all units/properties, including dead/empty ones\n" + " --failed Show only failed units\n" " --full Don't ellipsize unit names on output\n" " --fail When queueing a new job, fail if conflicting jobs are\n" " pending\n" @@ -4344,7 +4349,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) { ARG_DEFAULTS, ARG_KILL_MODE, ARG_KILL_WHO, - ARG_NO_ASK_PASSWORD + ARG_NO_ASK_PASSWORD, + ARG_FAILED }; static const struct option options[] = { @@ -4353,6 +4359,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { { "type", required_argument, NULL, 't' }, { "property", required_argument, NULL, 'p' }, { "all", no_argument, NULL, 'a' }, + { "failed", no_argument, NULL, ARG_FAILED }, { "full", no_argument, NULL, ARG_FULL }, { "fail", no_argument, NULL, ARG_FAIL }, { "user", no_argument, NULL, ARG_USER }, @@ -4456,6 +4463,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) { arg_full = true; break; + case ARG_FAILED: + arg_failed = true; + break; + case 'q': arg_quiet = true; break;