]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgls: add --user-unit to show user units
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 1 Feb 2017 20:20:46 +0000 (15:20 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 2 Feb 2017 03:31:41 +0000 (22:31 -0500)
man/systemd-cgls.xml
src/cgls/cgls.c

index 91d0c0b1bb63ce4527725f93a45892bfe88e38a8..219514b18356a1bcc8f035d8cce0752801ea15b7 100644 (file)
@@ -57,7 +57,7 @@
     <cmdsynopsis>
       <command>systemd-cgls</command>
       <arg choice="opt" rep="repeat">OPTIONS</arg>
-      <arg choice="plain"><option>--unit</option></arg>
+      <arg choice="plain"><option>--unit</option>|<option>--user-unit</option></arg>
       <arg choice="opt" rep="repeat">UNIT</arg>
     </cmdsynopsis>
   </refsynopsisdiv>
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--user-unit</option></term>
+
+        <listitem><para>Show cgroup subtrees for the specified user units.</para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><option>-k</option></term>
 
index 83e47170d8d981297cd74ef771bfaac7e46efd5c..b64a0df54203e975b2962669b77e2d4c960e1e43 100644 (file)
 static bool arg_no_pager = false;
 static bool arg_kernel_threads = false;
 static bool arg_all = false;
-static bool arg_unit = false;
+
+static enum {
+        SHOW_UNIT_NONE,
+        SHOW_UNIT_SYSTEM,
+        SHOW_UNIT_USER,
+} arg_show_unit = SHOW_UNIT_NONE;
+
 static int arg_full = -1;
 static char* arg_machine = NULL;
 
@@ -51,7 +57,8 @@ static void help(void) {
                "     --version        Show package version\n"
                "     --no-pager       Do not pipe output into a pager\n"
                "  -a --all            Show all groups, including empty\n"
-               "  -u --unit           Show the subtrees of specifified units\n"
+               "  -u --unit           Show the subtrees of specifified system units\n"
+               "     --user-unit      Show the subtrees of specifified user units\n"
                "  -l --full           Do not ellipsize output\n"
                "  -k                  Include kernel threads in output\n"
                "  -M --machine=       Show container\n"
@@ -63,16 +70,18 @@ static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_NO_PAGER = 0x100,
                 ARG_VERSION,
+                ARG_USER_UNIT,
         };
 
         static const struct option options[] = {
-                { "help",      no_argument,       NULL, 'h'          },
-                { "version",   no_argument,       NULL, ARG_VERSION  },
-                { "no-pager",  no_argument,       NULL, ARG_NO_PAGER },
-                { "all",       no_argument,       NULL, 'a'          },
-                { "full",      no_argument,       NULL, 'l'          },
-                { "machine",   required_argument, NULL, 'M'          },
-                { "unit",      no_argument,       NULL, 'u'          },
+                { "help",      no_argument,       NULL, 'h'           },
+                { "version",   no_argument,       NULL, ARG_VERSION   },
+                { "no-pager",  no_argument,       NULL, ARG_NO_PAGER  },
+                { "all",       no_argument,       NULL, 'a'           },
+                { "full",      no_argument,       NULL, 'l'           },
+                { "machine",   required_argument, NULL, 'M'           },
+                { "unit",      no_argument,       NULL, 'u'           },
+                { "user-unit", no_argument,       NULL, ARG_USER_UNIT },
                 {}
         };
 
@@ -101,7 +110,11 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case 'u':
-                        arg_unit = true;
+                        arg_show_unit = SHOW_UNIT_SYSTEM;
+                        break;
+
+                case ARG_USER_UNIT:
+                        arg_show_unit = SHOW_UNIT_USER;
                         break;
 
                 case 'l':
@@ -123,8 +136,8 @@ static int parse_argv(int argc, char *argv[]) {
                         assert_not_reached("Unhandled option");
                 }
 
-        if (arg_machine && arg_unit) {
-                log_error("Cannot combine --unit with --machine.");
+        if (arg_machine && arg_show_unit != SHOW_UNIT_NONE) {
+                log_error("Cannot combine --unit or --user-unit with --machine.");
                 return -EINVAL;
         }
 
@@ -169,13 +182,15 @@ int main(int argc, char *argv[]) {
                 for (i = optind; i < argc; i++) {
                         int q;
 
-                        if (arg_unit) {
+                        if (arg_show_unit != SHOW_UNIT_NONE) {
                                 /* Command line arguments are unit names */
                                 _cleanup_free_ char *cgroup = NULL;
 
                                 if (!bus) {
                                         /* Connect to the bus only if necessary */
-                                        r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL, false, &bus);
+                                        r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL,
+                                                                          arg_show_unit == SHOW_UNIT_USER,
+                                                                          &bus);
                                         if (r < 0) {
                                                 log_error_errno(r, "Failed to create bus connection: %m");
                                                 goto finish;