From 5c3948a042a7cd4114f4d3eceaa1f134f52424b1 Mon Sep 17 00:00:00 2001 From: Ivana Hutarova Varekova Date: Mon, 9 May 2011 10:40:09 +0200 Subject: [PATCH] lscgroup: add the possibility to use -g : Most of the tools use : together with -g option (cgcreate, cgget and cgclassify), this patch adds this option to lscgroups tool Signed-off-by: Ivana Hutarova Varekova Signed-off-by: Jan Safranek --- doc/man/lscgroup.1 | 2 +- src/tools/lscgroup.c | 45 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/doc/man/lscgroup.1 b/doc/man/lscgroup.1 index 0950af38..08b60d42 100644 --- a/doc/man/lscgroup.1 +++ b/doc/man/lscgroup.1 @@ -7,7 +7,7 @@ lscgroup \- list all cgroups .SH SYNOPSIS -\fBlscgroup\fR [<\fIcontrollers>:] [...] +\fBlscgroup\fR [[\fB-g\fR] <\fIcontrollers>:] [...] .br \fBlscgroup\fR [\fB-h|--help\fR] diff --git a/src/tools/lscgroup.c b/src/tools/lscgroup.c index 82e0117f..e6b1d09e 100644 --- a/src/tools/lscgroup.c +++ b/src/tools/lscgroup.c @@ -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; } -- 2.47.2