systemctl: introduce --failed to show only failed services

This commit is contained in:
Lennart Poettering 2011-02-16 20:34:59 +01:00
parent 70db8e3a0b
commit 30732560c4
4 changed files with 28 additions and 10 deletions

4
TODO
View File

@ -5,8 +5,6 @@ Bugs:
* when plymouth is disabled the console password entry stuff seems to be borked * when plymouth is disabled the console password entry stuff seems to be borked
https://bugzilla.redhat.com/show_bug.cgi?id=655538 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 * exclude java hsp files by default
https://bugzilla.redhat.com/show_bug.cgi?id=527425 https://bugzilla.redhat.com/show_bug.cgi?id=527425
@ -14,8 +12,6 @@ Features:
* add --ignore-deps to systemctl * add --ignore-deps to systemctl
* add --failed to systemctl
* increase password timeout * increase password timeout
* look up crypto partition mount points via fstab to show to the user when prompting for a password * look up crypto partition mount points via fstab to show to the user when prompting for a password

View File

@ -126,6 +126,15 @@
they are set or not.</para></listitem> they are set or not.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--failed</option></term>
<listitem><para>When listing units,
show only failed units. Do not confuse
with
<option>--fail</option>.</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>--full</option></term> <term><option>--full</option></term>
@ -144,7 +153,9 @@
unfinished job, fail the command. If unfinished job, fail the command. If
this is not specified the requested this is not specified the requested
operation will replace the pending job, operation will replace the pending job,
if necessary.</para></listitem> if necessary. Do not confuse
with
<option>--failed</option>.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -42,7 +42,7 @@ _systemctl () {
local verb comps local verb comps
local -A OPTS=( 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 --help -h --no-ask-password --no-block --no-reload --no-wall
--order --require --quiet -q --system --user --version' --order --require --quiet -q --system --user --version'
[ARG]='--kill-mode --kill-who --property -p --signal -s --type -t' [ARG]='--kill-mode --kill-who --property -p --signal -s --type -t'

View File

@ -76,6 +76,7 @@ static bool arg_full = false;
static bool arg_force = false; static bool arg_force = false;
static bool arg_defaults = false; static bool arg_defaults = false;
static bool arg_ask_password = false; static bool arg_ask_password = false;
static bool arg_failed = false;
static char **arg_wall = NULL; static char **arg_wall = NULL;
static const char *arg_kill_who = NULL; static const char *arg_kill_who = NULL;
static const char *arg_kill_mode = 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); 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; const char *dot;
if (arg_failed)
return streq(u->active_state, "failed");
return (!arg_type || ((dot = strrchr(u->id, '.')) && return (!arg_type || ((dot = strrchr(u->id, '.')) &&
streq(dot+1, arg_type))) && streq(dot+1, arg_type))) &&
(arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0); (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; job_len = sizeof("JOB")-1;
for (u = unit_infos; u < unit_infos + c; u++) { for (u = unit_infos; u < unit_infos + c; u++) {
if (!output_show_job(u)) if (!output_show_unit(u))
continue; continue;
active_len = MAX(active_len, strlen(u->active_state)); 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_loaded, *off_loaded;
const char *on_active, *off_active; const char *on_active, *off_active;
if (!output_show_job(u)) if (!output_show_unit(u))
continue; continue;
n_shown++; n_shown++;
@ -4190,6 +4194,7 @@ static int systemctl_help(void) {
" -t --type=TYPE List only units of a particular type\n" " -t --type=TYPE List only units of a particular type\n"
" -p --property=NAME Show only properties by this name\n" " -p --property=NAME Show only properties by this name\n"
" -a --all Show all units/properties, including dead/empty ones\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" " --full Don't ellipsize unit names on output\n"
" --fail When queueing a new job, fail if conflicting jobs are\n" " --fail When queueing a new job, fail if conflicting jobs are\n"
" pending\n" " pending\n"
@ -4344,7 +4349,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
ARG_DEFAULTS, ARG_DEFAULTS,
ARG_KILL_MODE, ARG_KILL_MODE,
ARG_KILL_WHO, ARG_KILL_WHO,
ARG_NO_ASK_PASSWORD ARG_NO_ASK_PASSWORD,
ARG_FAILED
}; };
static const struct option options[] = { static const struct option options[] = {
@ -4353,6 +4359,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
{ "type", required_argument, NULL, 't' }, { "type", required_argument, NULL, 't' },
{ "property", required_argument, NULL, 'p' }, { "property", required_argument, NULL, 'p' },
{ "all", no_argument, NULL, 'a' }, { "all", no_argument, NULL, 'a' },
{ "failed", no_argument, NULL, ARG_FAILED },
{ "full", no_argument, NULL, ARG_FULL }, { "full", no_argument, NULL, ARG_FULL },
{ "fail", no_argument, NULL, ARG_FAIL }, { "fail", no_argument, NULL, ARG_FAIL },
{ "user", no_argument, NULL, ARG_USER }, { "user", no_argument, NULL, ARG_USER },
@ -4456,6 +4463,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
arg_full = true; arg_full = true;
break; break;
case ARG_FAILED:
arg_failed = true;
break;
case 'q': case 'q':
arg_quiet = true; arg_quiet = true;
break; break;