summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Safranek <jsafrane@redhat.com>2009-10-29 15:47:59 +0100
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2009-11-01 03:09:08 +0530
commitbcbe0a35334e08fd1aa5dbb7b96dd1fbd847955a (patch)
tree12d04a61fc645d32906815b95b284583a10a788a
parent4efb9b682b6133a13044c1f70aa96de1fd64c36c (diff)
downloadlibcg-bcbe0a35334e08fd1aa5dbb7b96dd1fbd847955a.tar.gz
libcg-bcbe0a35334e08fd1aa5dbb7b96dd1fbd847955a.tar.xz
libcg-bcbe0a35334e08fd1aa5dbb7b96dd1fbd847955a.zip
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 <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
-rw-r--r--src/tools/cgdelete.c26
1 files 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;
}