diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2012-07-10 18:03:03 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-07-10 18:05:47 +0200 |
commit | c147dc42f8b3383a3ced69aaa75e21df4fe75a96 (patch) | |
tree | 210941651fe208730ca542d9232963854ac678e6 /src | |
parent | f69614f811b133ececad4394e88f9549a017bd4e (diff) |
systemctl: filter shown units by their load state
E.g. systemctl --all -t masked gives the list of masked units.
The -t/--type option is reused. This is possible because unit types
and unit load states are called differently, so it is possible to
distinguish what the user meant. Using the same option also means that
the interface is user for the user: less options to remember.
Diffstat (limited to 'src')
-rw-r--r-- | src/systemctl/systemctl.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index a9681798dd..6ab92cebf0 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -65,6 +65,7 @@ #include "path-util.h" static const char *arg_type = NULL; +static const char *arg_load_state = NULL; static char **arg_property = NULL; static bool arg_all = false; static const char *arg_job_mode = "replace"; @@ -337,7 +338,9 @@ static bool output_show_unit(const struct unit_info *u) { 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); + (!arg_load_state || streq(u->load_state, arg_load_state)) && + (arg_all || !(streq(u->active_state, "inactive") + || u->following[0]) || u->job_id > 0); } static void output_units_list(const struct unit_info *unit_infos, unsigned c) { @@ -4650,13 +4653,17 @@ static int systemctl_parse_argv(int argc, char *argv[]) { return 0; case 't': - if (unit_type_from_string(optarg) < 0) { - log_error("Invalid unit type '%s'.", optarg); - return -EINVAL; + if (unit_type_from_string(optarg) >= 0) { + arg_type = optarg; + break; } - arg_type = optarg; - break; - + if (unit_load_state_from_string(optarg) >= 0) { + arg_load_state = optarg; + break; + } + log_error("Unkown unit type or load state '%s'.", + optarg); + return -EINVAL; case 'p': { char **l; |