]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
lscgroup: add the possibility to use -g <controllers>:<path>
authorIvana Hutarova Varekova <varekova@redhat.com>
Mon, 9 May 2011 08:40:09 +0000 (10:40 +0200)
committerJan Safranek <jsafrane@redhat.com>
Mon, 9 May 2011 09:40:39 +0000 (11:40 +0200)
Most of the tools use <controllers>:<path> together with -g option
(cgcreate, cgget and cgclassify), this patch adds this option to
lscgroups tool

Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com>
Signed-off-by: Jan Safranek <jsafrane@redhat.com>
doc/man/lscgroup.1
src/tools/lscgroup.c

index 0950af38f43472dd10b8c743de1a85d0b0cb28b0..08b60d42904c48161f6a1f574713db6fb25dc88f 100644 (file)
@@ -7,7 +7,7 @@
 lscgroup \- list all cgroups
 
 .SH SYNOPSIS
-\fBlscgroup\fR [<\fIcontrollers>:<path\fR>] [...]
+\fBlscgroup\fR [[\fB-g\fR] <\fIcontrollers>:<path\fR>] [...]
 .br
 \fBlscgroup\fR [\fB-h|--help\fR]
 
index 82e0117f50f922713b564ccb9a05b16b4af122ee..e6b1d09eba849aaf9374813c3f8209be9dc8feba 100644 (file)
@@ -249,6 +249,7 @@ int main(int argc, char *argv[])
 
        int ret = 0;
        int c;
+       int i;
 
        int flags = 0;
 
@@ -256,27 +257,36 @@ int main(int argc, char *argv[])
 
        static struct option options[] = {
                {"help", 0, 0, 'h'},
+               {"group", required_argument, NULL, 'g'},
                {0, 0, 0, 0}
        };
 
+       memset(cgroup_list, 0, sizeof(cgroup_list));
+
        /* parse arguments */
-       while ((c = getopt_long(argc, argv, "h", options, NULL)) > 0) {
+       while ((c = getopt_long(argc, argv, "hg:", options, NULL)) > 0) {
                switch (c) {
                case 'h':
                        usage(0, argv[0]);
-                       return 0;
+                       ret = 0;
+                       goto err;
+               case 'g':
+                       ret = parse_cgroup_spec(cgroup_list, optarg,
+                               CG_HIER_MAX);
+                       if (ret) {
+                               fprintf(stderr, "%s: cgroup controller"
+                                       " and path parsing failed (%s)\n",
+                                       argv[0], optarg);
+                               return ret;
+                       }
+                       break;
                default:
                        usage(1, argv[0]);
-                       return -1;
+                       ret = 1;
+                       goto err;
                }
        }
 
-       memset(cgroup_list, 0, sizeof(cgroup_list));
-
-       /* no cgroup on input */
-       if (optind < argc)
-               flags |= FL_LIST;
-
        /* read the list of controllers */
        while (optind < argc) {
                ret = parse_cgroup_spec(cgroup_list, argv[optind],
@@ -290,8 +300,23 @@ int main(int argc, char *argv[])
                optind++;
        }
 
-       /* print the information, based on list of input cgroups and flags */
+       if (cgroup_list[0] != NULL) {
+               /* cgroups on input */
+               flags |= FL_LIST;
+       }
+
+       /* print the information
+          based on list of input cgroups and flags */
        ret = cgroup_list_cgroups(argv[0], cgroup_list, flags);
 
+err:
+       if (cgroup_list[0]) {
+               for (i = 0; i < CG_HIER_MAX; i++) {
+                       if (cgroup_list[i])
+                               cgroup_free_group_spec(cgroup_list[i]);
+               }
+       }
+
+
        return ret;
 }