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

2013-07-16 Thread Lennart Poettering
On Fri, 17.05.13 12:09, m.were...@partner.samsung.com 
(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.

Sounds like a worthwile addition. Sorry for the way too late review. But
in cse you are still interested:

We already support filtering for load states via --type= which is
overloaded for both load states and unit types. I think it would
probably be nicer to have --type= as you suggest, and then overload it
with load state, active state, and sub state. These three namespaces are
closer to each other so that we can avoid clashes easier.

 +static const char *arg_state = NULL;
 +static const char *const failed_str = failed;

You can just use failed insted of failed_str where you need it, no
need to define this.

  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));

No need for the surrounding parenthesis.

  
  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

Please move this up to the other filter switches like --type=.

I'd really like to see support for passing multiple states at once, the
same way as we support filtering for multiple types at once.

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] [PATCHv2] systemctl, man: option to list units by state

2013-05-17 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
---
 changes since v1:
 - remove additional space
 - add missing pipe in or

 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..edf1cc2 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:
-