Most of the tools use <controllers>:<path> together with -g option
(cgcreate, cgget and cgclassify), this patch adds this option to

Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>
---

 src/tools/lscgroup.c |   55 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/src/tools/lscgroup.c b/src/tools/lscgroup.c
index 82e0117..0b3e502 100644
--- a/src/tools/lscgroup.c
+++ b/src/tools/lscgroup.c
@@ -45,9 +45,13 @@ static void usage(int status, const char *program_name)
                        " try %s -h' for more information.\n",
                        program_name);
        } else {
-               fprintf(stdout, "Usage: %s [<controllers>:<path>] [...]\n",
-                       program_name);
-               fprintf(stdout, "list all cgroups\n");
+               fprintf(stdout, "Usage: %s [-h] [[-g] <controllers>:<path>] "\
+                       "[...]\n", program_name);
+               fprintf(stdout, "  -g <controllers>:<path>   Control group "\
+                       "to be displayed (-g is optional)\n");
+               fprintf(stdout, "  -h, --help                Display "\
+                       "this help\n");
+               fprintf(stdout, "List all cgroups\n");
        }
 }
 
@@ -249,6 +253,7 @@ int main(int argc, char *argv[])
 
        int ret = 0;
        int c;
+       int i;
 
        int flags = 0;
 
@@ -256,27 +261,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 +304,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;
 }


------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to