]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgdelete: add the possibility to use -g <controllers>:<path>
authorIvana Hutarova Varekova <varekova@redhat.com>
Mon, 9 May 2011 08:39:41 +0000 (10:39 +0200)
committerJan Safranek <jsafrane@redhat.com>
Mon, 9 May 2011 09:40:38 +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
cgdelete.

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

index f1e17a7be06739829ef97bb2a2c1e4b092c1b145..a6adf1fae12ce6d5903e9cc091bc649467fb8e7d 100644 (file)
@@ -7,16 +7,19 @@
 cgdelete \- remove control group(s)
 
 .SH SYNOPSIS
-\fBcgdelete\fR [\fB-h\fR] [\fB-r\fR] [<\fIcontrollers\fR>:\fI<path\fR>] ...
+\fBcgdelete\fR [\fB-h\fR] [\fB-r\fR] [[\fB-g\fR]
+<\fIcontrollers\fR>:\fI<path\fR>] ...
 
 .SH DESCRIPTION
 The \fBcgdelete\fR
 program removes all specified control groups.
 
 .TP
-.B <controllers>:<path>
+.B [-g] <controllers>:<path>
 Defines control group to delete. There can be multiple control
 groups specified.
+.B -g
+is optional.
 
 .TP
 .B -h, --help
index ba8e75f9fa3698c2c05ea408d5deee3ecc97dcb9..c7b47212392015ff61bdaa4443e0800f24373d52 100644 (file)
@@ -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,7 +40,8 @@ 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",
+               printf("Usage: %s [-h ] [-r ] "
+                       "\[[-g] <controllers>:<path>] ...\n",
                        program_name);
        }
 }
@@ -52,26 +54,46 @@ 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':
                        flags |= CGFLAG_DELETE_RECURSIVE;
                        break;
+               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;
                case 'h':
                        usage(0, argv[0]);
                        ret = 0;
@@ -83,32 +105,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 +116,8 @@ 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 +163,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]);
                }