]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Remove the CG_HIER_MAX from tools-common
authorJan Safranek <jsafrane@redhat.com>
Thu, 29 Oct 2009 14:47:52 +0000 (15:47 +0100)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Sat, 31 Oct 2009 21:39:08 +0000 (03:09 +0530)
Some libcgroup tools are limited to CG_HIER_MAX arguments. This hard limit
is suitable only to some of the tools, namely cgdelete and cgcreate should not
be limited to any particular numbers of groups to create/delete.

This patches removes the hard limit from tools-common.c and puts it to the
individual tools.

Signed-off-by: Jan Safranek <jsafrane@redhat.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
src/tools/cgclassify.c
src/tools/cgcreate.c
src/tools/cgdelete.c
src/tools/cgexec.c
src/tools/lscgroup.c
src/tools/tools-common.c
src/tools/tools-common.h

index 74d5bec5d304158e0b1752c5e093642978c55969..b2d6f1885af7ff55549e68e9926e07b3d0ccb9e3 100644 (file)
@@ -118,7 +118,9 @@ int main(int argc, char *argv[])
        while ((c = getopt_long(argc, argv, "+g:s", longopts, NULL)) > 0) {
                switch (c) {
                case 'g':
-                       if (parse_cgroup_spec(cgroup_list, optarg)) {
+                       ret = parse_cgroup_spec(cgroup_list, optarg,
+                                       CG_HIER_MAX);
+                       if (ret) {
                                fprintf(stderr, "cgroup controller and path"
                                                "parsing failed\n");
                                return -1;
index 78665e745f7bdeaa76348334f71d6134e2d84e19..dc8305c3dab2253471fedf12dd39a6db0869f578 100644 (file)
@@ -113,7 +113,9 @@ int main(int argc, char *argv[])
                        }
                        break;
                case 'g':
-                       if (parse_cgroup_spec(cgroup_list, optarg)) {
+                       ret = parse_cgroup_spec(cgroup_list, optarg,
+                                       CG_HIER_MAX);
+                       if (ret) {
                                fprintf(stderr, "%s: "
                                        "cgroup controller and path"
                                        "parsing failed (%s)\n",
index 51d89221159cbd9fb7aa5640a7e0c8bbaa45a404..260d2fc4455123e346d1b566b9d36c640fec3d13 100644 (file)
@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
 
        /* parse groups on command line */
        for (i = optind; i < argc; i++) {
-               ret = parse_cgroup_spec(cgroup_list, argv[i]);
+               ret = parse_cgroup_spec(cgroup_list, argv[i], CG_HIER_MAX);
                if (ret != 0) {
                        fprintf(stderr, "%s: error parsing cgroup '%s'\n",
                                        argv[0], argv[i]);
index a0368703b02ee0fd48708cdf8aaff2cb25ab3bc8..2c9296499671d69a301497094d771e49e0d50e1d 100644 (file)
@@ -59,7 +59,9 @@ int main(int argc, char *argv[])
        while ((c = getopt_long(argc, argv, "+g:s", longopts, NULL)) > 0) {
                switch (c) {
                case 'g':
-                       if (parse_cgroup_spec(cgroup_list, optarg)) {
+                       ret = parse_cgroup_spec(cgroup_list, optarg,
+                                       CG_HIER_MAX);
+                       if (ret) {
                                fprintf(stderr, "cgroup controller and path"
                                                "parsing failed\n");
                                return -1;
index 5164d353ce10d869ff29284429f8116ceaf0b2a1..ca846e079d23827441797740b6ae136e9f3eb491 100644 (file)
@@ -280,7 +280,9 @@ int main(int argc, char *argv[])
 
        /* read the list of controllers */
        while (optind < argc) {
-               if (parse_cgroup_spec(cgroup_list, argv[optind])) {
+               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], argv[optind]);
index db46f6e885234e370bfd58821e37755199d51156..4beffcd32cf2c8f89f863cea19ab5c9b12554769 100644 (file)
@@ -22,7 +22,8 @@
 #include <libcgroup.h>
 #include "tools-common.h"
 
-int parse_cgroup_spec(struct cgroup_group_spec *cdptr[], char *optarg)
+int parse_cgroup_spec(struct cgroup_group_spec **cdptr, char *optarg,
+               int capacity)
 {
        struct cgroup_group_spec *ptr;
        int i, j;
@@ -31,15 +32,15 @@ int parse_cgroup_spec(struct cgroup_group_spec *cdptr[], char *optarg)
        ptr = *cdptr;
 
        /* Find first free entry inside the cgroup data array */
-       for (i = 0; i < CG_HIER_MAX; i++, ptr++) {
+       for (i = 0; i < capacity; i++, ptr++) {
                if (!cdptr[i])
                        break;
        }
 
-       if (i == CG_HIER_MAX) {
+       if (i == capacity) {
                /* No free slot found */
                fprintf(stderr, "Max allowed hierarchies %d reached\n",
-                               CG_HIER_MAX);
+                               capacity);
                return -1;
        }
 
index 65d87c76fb8b11a44d6c9da9a61e1ea5ab50ae44..752eb57b32d25339db5ccaf16354a119098e2ab6 100644 (file)
@@ -41,14 +41,16 @@ struct cgroup_group_spec {
  * The option must have form of 'controller1,controller2,..:group_name'.
  *
  * The parsed list of controllers and group name is added at the end of
- * provided cdptr.
+ * provided cdptr, i.e. on place of first NULL cgroup_group_spec*.
  *
  * @param cdptr Target data structure to fill. New item is allocated and added
  *             at the end.
  * @param optarg Argument to parse.
+ * @param capacity Capacity of the cdptr array.
  * @return 0 on success, != 0 on error.
  */
-int parse_cgroup_spec(struct cgroup_group_spec *cdptr[], char *optarg);
+int parse_cgroup_spec(struct cgroup_group_spec **cdptr, char *optarg,
+               int capacity);
 
 /**
  * Free a single cgroup_group_spec structure.