diff options
author | Jan Safranek <jsafrane@redhat.com> | 2009-10-29 15:47:52 +0100 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-11-01 03:09:08 +0530 |
commit | 4efb9b682b6133a13044c1f70aa96de1fd64c36c (patch) | |
tree | d6e83dbb60f6350c1b8c3e5d78cc349e86d2a731 | |
parent | a05baf9beb7c3a87b286c36553db3f5377a9d2de (diff) | |
download | libcg-4efb9b682b6133a13044c1f70aa96de1fd64c36c.tar.gz libcg-4efb9b682b6133a13044c1f70aa96de1fd64c36c.tar.xz libcg-4efb9b682b6133a13044c1f70aa96de1fd64c36c.zip |
Remove the CG_HIER_MAX from tools-common
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>
-rw-r--r-- | src/tools/cgclassify.c | 4 | ||||
-rw-r--r-- | src/tools/cgcreate.c | 4 | ||||
-rw-r--r-- | src/tools/cgdelete.c | 2 | ||||
-rw-r--r-- | src/tools/cgexec.c | 4 | ||||
-rw-r--r-- | src/tools/lscgroup.c | 4 | ||||
-rw-r--r-- | src/tools/tools-common.c | 9 | ||||
-rw-r--r-- | src/tools/tools-common.h | 6 |
7 files changed, 22 insertions, 11 deletions
diff --git a/src/tools/cgclassify.c b/src/tools/cgclassify.c index 74d5bec..b2d6f18 100644 --- a/src/tools/cgclassify.c +++ b/src/tools/cgclassify.c @@ -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; diff --git a/src/tools/cgcreate.c b/src/tools/cgcreate.c index 78665e7..dc8305c 100644 --- a/src/tools/cgcreate.c +++ b/src/tools/cgcreate.c @@ -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", diff --git a/src/tools/cgdelete.c b/src/tools/cgdelete.c index 51d8922..260d2fc 100644 --- a/src/tools/cgdelete.c +++ b/src/tools/cgdelete.c @@ -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]); diff --git a/src/tools/cgexec.c b/src/tools/cgexec.c index a036870..2c92964 100644 --- a/src/tools/cgexec.c +++ b/src/tools/cgexec.c @@ -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; diff --git a/src/tools/lscgroup.c b/src/tools/lscgroup.c index 5164d35..ca846e0 100644 --- a/src/tools/lscgroup.c +++ b/src/tools/lscgroup.c @@ -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]); diff --git a/src/tools/tools-common.c b/src/tools/tools-common.c index db46f6e..4beffcd 100644 --- a/src/tools/tools-common.c +++ b/src/tools/tools-common.c @@ -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; } diff --git a/src/tools/tools-common.h b/src/tools/tools-common.h index 65d87c7..752eb57 100644 --- a/src/tools/tools-common.h +++ b/src/tools/tools-common.h @@ -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. |