summaryrefslogtreecommitdiffstats
path: root/wrapper.c
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2008-08-22 16:44:17 +0000
committerBalbir Singh <balbir@linux.vnet.ibm.com>2008-08-22 16:44:17 +0000
commit2124f1ea16bcc12482928c45689c1fa4d92a74a1 (patch)
treee5e51d88f8907e8d38b70b327f4d7a387b74b4b7 /wrapper.c
parent3efa319b43fb1f66a96e5001c9e5cba51f854370 (diff)
downloadlibcg-2124f1ea16bcc12482928c45689c1fa4d92a74a1.tar.gz
libcg-2124f1ea16bcc12482928c45689c1fa4d92a74a1.tar.xz
libcg-2124f1ea16bcc12482928c45689c1fa4d92a74a1.zip
This patch adds cgroup_create_cgroup_from_parent() API. I've tested it
with a modified version of libcg_ba (basic acceptance tests), that I'll send out later. I've also fixed a couple of bugs, I'll list them in order and if desired, I'll split out the patches so that the enhancements can be separate from the bug fixes 1. Fix cg_create_control_group() to succeed if the directory already exists 2. We can't always append a control_file, we need to open it "r+" 3. It's OK for writing values to a control_file to fail, since some of them are read-only and some may not exist in hierarchies below the root 4. Skip over directories while trying to read control file's name value pairs 5. In cg_rd_ctlr_file we don't allocate any memory to value, directly fscanf into it, that's been fixed 6. There might be more fixes that might already be present in trunk, since I hope I've not redone a lot of the fixes, I had branched of trunk very recently Changelog v2 ------------ 1. Refactor cgroup_free_controllers() and use it in cgroup_create_cgroup_from_parent() 2. Check for strdup failure 3. Check if dst == src TODO: 1. Use cg_add_controller() API 2. Use cg_add_value_string() API I'll send out patches for the TODOs later. I've also updated the basic acceptance test (libcg_ba.cpp) Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@165 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/wrapper.c b/wrapper.c
index c53a874..24a641d 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -70,9 +70,18 @@ struct cgroup_controller *cgroup_add_controller(struct cgroup *cgroup,
return controller;
}
-void cgroup_free(struct cgroup **cgroup)
+void cgroup_free_controllers(struct cgroup *cgroup)
{
int i, j;
+ for (i = 0; i < cgroup->index; i++) {
+ for (j = 0; j < cgroup->controller[i]->index; j++)
+ free(cgroup->controller[i]->values[j]);
+ free(cgroup->controller[i]);
+ }
+}
+
+void cgroup_free(struct cgroup **cgroup)
+{
struct cgroup *cg = *cgroup;
/*
@@ -81,12 +90,7 @@ void cgroup_free(struct cgroup **cgroup)
if (!cg)
return;
- for (i = 0; i < cg->index; i++) {
- for (j = 0; j < cg->controller[i]->index; j++)
- free(cg->controller[i]->values[j]);
- free(cg->controller[i]);
- }
-
+ cgroup_free_controllers(cg);
free(cg);
*cgroup = NULL;
}