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

2013-05-17 Thread Maciej Wereski

Hello,

16.05.2013 at 12:02 m.were...@partner.samsung.com wrote:


From: Maciej Wereski m.were...@partner.samsung.com

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


I've found 2 typos. I'll upload patch v2 soon.

--
Maciej Wereski
Samsung RD Institute Poland
Samsung Electronics
m.were...@partner.samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2013-05-16 Thread m . wereski
From: Maciej Wereski m.were...@partner.samsung.com

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

Signed-off-by: Maciej Wereski m.were...@partner.samsung.com
---
 man/systemctl.xml | 14 --
 src/systemctl/systemctl.c | 22 +++---
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 0afb0cc..7f000a8 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -169,8 +169,9 @@ along with systemd; If not, see 
http://www.gnu.org/licenses/.
 termoption--failed/option/term
 
 listitem
-  paraWhen listing units, show only failed units. Do not
-  confuse with option--fail/option./para
+  paraWhen listing units, show only failed units.
+  This is the same as option--state=/optionfailed.
+  Do not confuse with option--fail/option./para
 /listitem
   /varlistentry
 
@@ -502,6 +503,15 @@ along with systemd; If not, see 
http://www.gnu.org/licenses/.
 /listitem
   /varlistentry
 
+  varlistentry
+termoption--state=/option/term
+
+  listitem
+paraWhen listing units show only those with specified
+sub or active state./para
+  /listitem
+  /varlistentry
+
 /variablelist
   /refsect1
 
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 3cca861..c3b433e 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -93,13 +93,14 @@ 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 const char *arg_state = NULL;
+static const char * const failed_str = failed;
 static enum action {
 ACTION_INVALID,
 ACTION_SYSTEMCTL,
@@ -300,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 (arg_state != NULL)
+return (streq(u-sub_state, arg_state) | 
streq(u-active_state, arg_state));
 
 return (!arg_types || ((dot = strrchr(u-id, '.')) 
strv_find(arg_types, dot+1))) 
@@ -4503,7 +4504,7 @@ static int systemctl_help(void) {
  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
+--failed Show only failed units (the same as 
--state=failed)\n
 --full   Don't ellipsize unit names on output\n
 --fail   When queueing a new job, fail if 
conflicting jobs are\n
  pending\n
@@ -4536,7 +4537,8 @@ static int systemctl_help(void) {
 --runtimeEnable unit files only temporarily until 
next reboot\n
  -n --lines=INTEGER  Journal entries to show\n
  -o --output=STRING  Change journal output mode (short, 
short-monotonic,\n
- verbose, export, json, json-pretty, 
json-sse, cat)\n\n
+ verbose, export, json, json-pretty, 
json-sse, cat)\n
+--state=STATEShow only units with particular sub or 
active state\n\n
Unit Commands:\n
  list-units  List loaded units\n
  start [NAME...] Start (activate) one or more 
units\n
@@ -4727,7 +4729,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[] = {
@@ -4766,6 +4769,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 }
 };
 
@@ -4927,7 +4931,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
 break;
 
 case ARG_FAILED:
-arg_failed = true;
+arg_state =