From bcbe0a35334e08fd1aa5dbb7b96dd1fbd847955a Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Thu, 29 Oct 2009 15:47:59 +0100 Subject: Allow cgdelete to process unlimited nr. of groups Don't limit the number of groups cgdelete can remove, allocate them dynamically. Signed-off-by: Jan Safranek Signed-off-by: Dhaval Giani --- src/tools/cgdelete.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/tools/cgdelete.c b/src/tools/cgdelete.c index 260d2fc..af1cb7e 100644 --- a/src/tools/cgdelete.c +++ b/src/tools/cgdelete.c @@ -31,8 +31,9 @@ int main(int argc, char *argv[]) char c; int flags = 0; int final_ret = 0; + int capacity = 0; - struct cgroup_group_spec *cgroup_list[CG_HIER_MAX]; + struct cgroup_group_spec **cgroup_list = NULL; struct cgroup *cgroup; struct cgroup_controller *cgc; @@ -44,8 +45,6 @@ int main(int argc, char *argv[]) return -1; } - memset(cgroup_list, 0, sizeof(cgroup_list)); - /* * Parse arguments */ @@ -80,9 +79,17 @@ int main(int argc, char *argv[]) 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], CG_HIER_MAX); + ret = parse_cgroup_spec(cgroup_list, argv[i], capacity); if (ret != 0) { fprintf(stderr, "%s: error parsing cgroup '%s'\n", argv[0], argv[i]); @@ -92,7 +99,7 @@ int main(int argc, char *argv[]) } /* for each cgroup to delete */ - for (i = 0; i < CG_HIER_MAX; i++) { + for (i = 0; i < capacity; i++) { if (!cgroup_list[i]) break; @@ -137,9 +144,12 @@ int main(int argc, char *argv[]) ret = final_ret; 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; } -- cgit