Re: [systemd-devel] [PATCHv5] systemctl, man: option to list units by state

2013-07-18 Thread Lennart Poettering
On Thu, 18.07.13 13:24, Maciej Wereski (m.were...@partner.samsung.com) wrote:

> This allows to show only units with specified LOAD or SUB or ACTIVE state.

Thanks! Applied (with some changes, got rid of the arg_load_states
strv which is kinda unnecessary if we have arg_states now).

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCHv5] systemctl, man: option to list units by state

2013-07-18 Thread Maciej Wereski
This allows to show only units with specified LOAD or SUB or ACTIVE state.

Signed-off-by: Maciej Wereski 
---
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 
.
 
   The argument should be a comma-separated list of unit
   types such as service and
-  socket, or unit load states such as
-  loaded and masked
-  (types and states can be mixed).
+  socket.
+  
 
   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.
 
-  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.
-
   As a special case, if one of the arguments is
   help, a list of allowed values will be
   printed and the program will exit.
@@ -114,6 +108,16 @@ along with systemd; If not, see 
.
   
 
   
+--state=
+
+
+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.
+
+  
+
+  
 -p
 --property=
 
@@ -166,15 +170,6 @@ along with systemd; If not, see 
.
   
 
   
---failed
-
-
-  When listing units, show only failed units. Do not
-  confuse with --fail.
-
-  
-
-  
 -l
 --full
 
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"
" --versionShow package version\n"
"  -t --type=TYPE  List only units of a particular type\n"
+   " --state=STATEShow only units with particular LOAD or 
SUB or ACTIVE state\n"
"  -p --property=NAME  Show only properties by this name\n"
"  -a --allShow 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"
" --reverseShow 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
+