diff options
author | Jan Safranek <jsafrane@redhat.com> | 2009-10-29 15:48:06 +0100 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-11-01 03:09:09 +0530 |
commit | c97161d985b99fea161272185085c4e23c1de951 (patch) | |
tree | 24b2d4978c6019809f3fc9edb34e368f29aaf0a5 | |
parent | bcbe0a35334e08fd1aa5dbb7b96dd1fbd847955a (diff) | |
download | libcg-c97161d985b99fea161272185085c4e23c1de951.tar.gz libcg-c97161d985b99fea161272185085c4e23c1de951.tar.xz libcg-c97161d985b99fea161272185085c4e23c1de951.zip |
Allow cgcreate to create unlimited nr. of groups
Don't limit the number of groups cgcreate can create, allocate them
dynamically. The size of allocated space for the group is only aproximate, but
still should be better than hard CG_HIER_MAX.
Signed-off-by: Jan Safranek <jsafrane@redhat.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
-rw-r--r-- | src/tools/cgcreate.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/tools/cgcreate.c b/src/tools/cgcreate.c index dc8305c..6204cfb 100644 --- a/src/tools/cgcreate.c +++ b/src/tools/cgcreate.c @@ -28,10 +28,13 @@ int main(int argc, char *argv[]) uid_t tuid = CGRULE_INVALID, auid = CGRULE_INVALID; gid_t tgid = CGRULE_INVALID, agid = CGRULE_INVALID; - struct cgroup_group_spec *cgroup_list[CG_HIER_MAX]; + struct cgroup_group_spec **cgroup_list; struct cgroup *cgroup; struct cgroup_controller *cgc; + /* approximation of max. numbers of groups that will be created */ + int capacity = argc; + /* no parametr on input */ if (argc < 2) { fprintf(stderr, "Usage is %s " @@ -40,8 +43,12 @@ int main(int argc, char *argv[]) argv[0]); return -1; } + cgroup_list = calloc(capacity, sizeof(struct cgroup_group_spec *)); + if (cgroup_list == NULL) { + fprintf(stderr, "%s: out of memory\n", argv[0]); + return -1; + } - memset(cgroup_list, 0, sizeof(cgroup_list)); /* parse arguments */ while ((c = getopt(argc, argv, "a:t:g:")) > 0) { switch (c) { @@ -113,8 +120,7 @@ int main(int argc, char *argv[]) } break; case 'g': - ret = parse_cgroup_spec(cgroup_list, optarg, - CG_HIER_MAX); + ret = parse_cgroup_spec(cgroup_list, optarg, capacity); if (ret) { fprintf(stderr, "%s: " "cgroup controller and path" @@ -151,7 +157,7 @@ int main(int argc, char *argv[]) } /* for each new cgroup */ - for (i = 0; i < CG_HIER_MAX; i++) { + for (i = 0; i < capacity; i++) { if (!cgroup_list[i]) break; @@ -198,9 +204,12 @@ int main(int argc, char *argv[]) cgroup_free(&cgroup); } err: - for (i = 0; i < CG_HIER_MAX; i++) { - if (cgroup_list[i]) - cgroup_free_group_spec(cgroup_list[i]); + if (cgroup_list) { + for (i = 0; i < capacity; i++) { + if (cgroup_list[i]) + cgroup_free_group_spec(cgroup_list[i]); + } + free(cgroup_list); } return ret; } |