Most of the tools use <controllers>:<path> together with -g option (cgcreate, cgget and cgclassify), this patch adds this option to cgdelete.
The patch also create more verbose help output Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com> --- src/tools/cgdelete.c | 72 ++++++++++++++++++++++++++------------------------ 1 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/tools/cgdelete.c b/src/tools/cgdelete.c index ba8e75f..cb3d570 100644 --- a/src/tools/cgdelete.c +++ b/src/tools/cgdelete.c @@ -29,6 +29,7 @@ static struct option const long_options[] = { {"recursive", no_argument, NULL, 'r'}, {"help", no_argument, NULL, 'h'}, + {"group", required_argument, NULL, 'g'}, {NULL, 0, NULL, 0} }; @@ -39,8 +40,14 @@ static void usage(int status, const char *program_name) " try %s --help' for more information.\n", program_name); else { - printf("Usage: %s [-h ] [-r ] [<controllers>:<path>] ...\n", - program_name); + fprintf(stdout, "Usage: %s [-h] [-r] "\ + "[[-g] <controllers>:<path>] ...\n", program_name); + fprintf(stdout, "Remove control group(s)\n"); + fprintf(stdout, " -g <controllers>:<path> Control group "\ + "to be removed (-g is optional)\n"); + fprintf(stdout, " -h, --help Display this help\n"); + fprintf(stdout, " -r, --recursive Recursively remove "\ + "all subgroups\n"); } } @@ -52,21 +59,31 @@ int main(int argc, char *argv[]) int c; int flags = 0; int final_ret = 0; - int capacity = 0; struct cgroup_group_spec **cgroup_list = NULL; struct cgroup *cgroup; struct cgroup_controller *cgc; - if (argc < 2) { - usage(1, argv[0]); - return -1; + /* initialize libcg */ + ret = cgroup_init(); + if (ret) { + fprintf(stderr, "%s: " + "libcgroup initialization failed: %s\n", + argv[0], cgroup_strerror(ret)); + goto err; + } + + cgroup_list = calloc(argc, sizeof(struct cgroup_group_spec *)); + if (cgroup_list == NULL) { + fprintf(stderr, "%s: out of memory\n", argv[0]); + ret = -1; + goto err; } /* * Parse arguments */ - while ((c = getopt_long(argc, argv, "rh", + while ((c = getopt_long(argc, argv, "rhg:", long_options, NULL)) > 0) { switch (c) { case 'r': @@ -76,6 +93,15 @@ int main(int argc, char *argv[]) usage(0, argv[0]); ret = 0; goto err; + case 'g': + ret = parse_cgroup_spec(cgroup_list, optarg, argc); + if (ret != 0) { + fprintf(stderr, "%s: error parsing cgroup '%s'\n", + argv[0], optarg); + ret = -1; + goto err; + } + break; default: usage(1, argv[0]); ret = -1; @@ -83,32 +109,9 @@ int main(int argc, char *argv[]) } } - if (optind >= argc) { - usage(1, argv[0]); - ret = -1; - goto err; - } - - /* initialize libcg */ - ret = cgroup_init(); - if (ret) { - fprintf(stderr, "%s: " - "libcgroup initialization failed: %s\n", - argv[0], cgroup_strerror(ret)); - goto err; - } - - capacity = argc - optind; - cgroup_list = calloc(capacity, sizeof(struct cgroup_group_spec *)); - if (cgroup_list == NULL) { - fprintf(stderr, "%s: out of memory\n", argv[0]); - ret = -1; - goto err; - } - /* parse groups on command line */ for (i = optind; i < argc; i++) { - ret = parse_cgroup_spec(cgroup_list, argv[i], capacity); + ret = parse_cgroup_spec(cgroup_list, argv[i], argc); if (ret != 0) { fprintf(stderr, "%s: error parsing cgroup '%s'\n", argv[0], argv[i]); @@ -117,8 +120,9 @@ int main(int argc, char *argv[]) } } - /* for each cgroup to delete */ - for (i = 0; i < capacity; i++) { + /* for each cgroup to be deleted */ + + for (i = 0; i < argc; i++) { if (!cgroup_list[i]) break; @@ -164,7 +168,7 @@ int main(int argc, char *argv[]) ret = final_ret; err: if (cgroup_list) { - for (i = 0; i < capacity; i++) { + for (i = 0; i < argc; i++) { if (cgroup_list[i]) cgroup_free_group_spec(cgroup_list[i]); } ------------------------------------------------------------------------------ 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