This allows to show only units with specified LOAD or SUB or ACTIVE state. Signed-off-by: Maciej Wereski <m.were...@partner.samsung.com> --- changes since v4: * removed help information about deprecated behaviour
Sorry, that I've forgot about this in previous patch! regards, Maciej --- man/systemctl.xml | 29 ++++++++++++----------------- src/systemctl/systemctl.c | 40 +++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/man/systemctl.xml b/man/systemctl.xml index f550215..9820517 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -94,19 +94,13 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. <listitem> <para>The argument should be a comma-separated list of unit types such as <option>service</option> and - <option>socket</option>, or unit load states such as - <option>loaded</option> and <option>masked</option> - (types and states can be mixed).</para> + <option>socket</option>. + </para> <para>If one of the arguments is a unit type, when listing units, limit display to certain unit types. Otherwise, units of all types will be shown.</para> - <para>If one of the arguments is a unit load state, when - listing units, limit display to certain unit - types. Otherwise, units of in all load states will be - shown.</para> - <para>As a special case, if one of the arguments is <option>help</option>, a list of allowed values will be printed and the program will exit.</para> @@ -114,6 +108,16 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. </varlistentry> <varlistentry> + <term><option>--state=</option></term> + + <listitem> + <para>Argument should be a comma-separated list of unit LOAD + or SUB or ACTIVE states. When listing units show only those + with specified LOAD or SUB or ACTIVE state.</para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>-p</option></term> <term><option>--property=</option></term> @@ -166,15 +170,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. </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> <term><option>-l</option></term> <term><option>--full</option></term> diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index b3b679e..c15d099 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -93,13 +93,13 @@ static bool arg_quiet = false; static bool arg_full = false; static int arg_force = 0; static bool arg_ask_password = true; -static bool arg_failed = false; static bool arg_runtime = false; static char **arg_wall = NULL; static const char *arg_kill_who = NULL; static int arg_signal = SIGTERM; static const char *arg_root = NULL; static usec_t arg_when = 0; +static char **arg_state = NULL; static enum action { ACTION_INVALID, ACTION_SYSTEMCTL, @@ -301,8 +301,8 @@ static int compare_unit_info(const void *a, const void *b) { static bool output_show_unit(const struct unit_info *u) { const char *dot; - if (arg_failed) - return streq(u->active_state, "failed"); + if (!strv_isempty(arg_state)) + return strv_contains(arg_state, u->load_state) || strv_contains(arg_state, u->sub_state) || strv_contains(arg_state, u->active_state); return (!arg_types || ((dot = strrchr(u->id, '.')) && strv_find(arg_types, dot+1))) && @@ -4705,12 +4705,12 @@ static int systemctl_help(void) { " -h --help Show this help\n" " --version Show package version\n" " -t --type=TYPE List only units of a particular type\n" + " --state=STATE Show only units with particular LOAD or SUB or ACTIVE state\n" " -p --property=NAME Show only properties by this name\n" " -a --all Show all loaded units/properties, including dead/empty\n" " ones. To list all units installed on the system, use\n" " the 'list-unit-files' command instead.\n" " --reverse Show reverse dependencies with 'list-dependencies'\n" - " --failed Show only failed units\n" " -l --full Don't ellipsize unit names on output\n" " --fail When queueing a new job, fail if conflicting jobs are\n" " pending\n" @@ -4896,13 +4896,6 @@ static int help_types(void) { puts(t); } - puts("\nAvailable unit load states: "); - for(i = 0; i < _UNIT_LOAD_STATE_MAX; i++) { - t = unit_load_state_to_string(i); - if (t) - puts(t); - } - return 0; } @@ -4931,7 +4924,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) { ARG_FAILED, ARG_RUNTIME, ARG_FORCE, - ARG_PLAIN + ARG_PLAIN, + ARG_STATE }; static const struct option options[] = { @@ -4970,6 +4964,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { { "lines", required_argument, NULL, 'n' }, { "output", required_argument, NULL, 'o' }, { "plain", no_argument, NULL, ARG_PLAIN }, + { "state", required_argument, NULL, ARG_STATE }, { NULL, 0, NULL, 0 } }; @@ -5131,7 +5126,12 @@ static int systemctl_parse_argv(int argc, char *argv[]) { break; case ARG_FAILED: - arg_failed = true; + if (!strv_contains(arg_state, "failed")) { + int r; + r = strv_extend(&arg_state, "failed"); + if (r < 0) + return r; + } break; case 'q': @@ -5201,6 +5201,20 @@ static int systemctl_parse_argv(int argc, char *argv[]) { arg_plain = true; break; + case ARG_STATE: { + char *word, *state; + size_t size; + FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) { + if (!strv_contains(arg_state, word)) { + int r; + r = strv_push(&arg_state, word); + if (r < 0) + return r; + } + } + break; + } + case '?': return -EINVAL; -- 1.8.3.3 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel