]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c | 23 +++++++++++++++--------
authorBalbir Singh <balbir@linux.vnet.ibm.com>
Wed, 16 Apr 2008 10:53:55 +0000 (10:53 +0000)
committerBalbir Singh <balbir@linux.vnet.ibm.com>
Wed, 16 Apr 2008 10:53:55 +0000 (10:53 +0000)
 libcg.h            |    4 ++--
 tests/libcg_ba.cpp |    2 +-

Added additional parameters for create and destroy cgroup. Fixed a cg_init
segfault (faulty, if-else check)

Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/branches/balbir@15 4f4bb910-9a46-0410-90c8-c897d4f1cd53

api.c
libcg.h
tests/libcg_ba.cpp

diff --git a/api.c b/api.c
index 8dbeab99df74e5f32d0cd21c36a8f5a8b1a6aa8f..c2d6ef9863251a08f9072535b01ad701e318c159 100644 (file)
--- a/api.c
+++ b/api.c
@@ -121,7 +121,7 @@ int cg_init()
         */
        if (!found_mnt)
                ret = ECGROUPNOTMOUNTED;
-       if (found_mnt > 1)
+       else if (found_mnt > 1)
                ret = ECGROUPMULTIMOUNTED;
        else {
                /*
@@ -340,7 +340,7 @@ err:
  * returns 0 on success. We recommend calling cg_delete_cgroup
  * if this routine fails. That should do the cleanup operation.
  */
-int cg_create_cgroup(struct cgroup *cgroup)
+int cg_create_cgroup(struct cgroup *cgroup, int ignore_ownership)
 {
        char *fts_path[2], base[FILENAME_MAX], *path;
        int i;
@@ -359,7 +359,12 @@ int cg_create_cgroup(struct cgroup *cgroup)
 
        strcpy(base, path);
 
-       cg_chown_recursive(fts_path, cgroup->control_uid, cgroup->control_gid);
+       if (!ignore_ownership)
+               error = cg_chown_recursive(fts_path, cgroup->control_uid,
+                                               cgroup->control_gid);
+
+       if (error)
+               goto err;
 
        for (i = 0; i < CG_CONTROLLER_MAX && cgroup->controller[i];
                                                i++, strcpy(path, base)) {
@@ -378,9 +383,11 @@ int cg_create_cgroup(struct cgroup *cgroup)
                }
        }
 
-       strcpy(path, base);
-       strcat(path, "/tasks");
-       chown(path, cgroup->tasks_uid, cgroup->tasks_gid);
+       if (!ignore_ownership) {
+               strcpy(path, base);
+               strcat(path, "/tasks");
+               chown(path, cgroup->tasks_uid, cgroup->tasks_gid);
+       }
 err:
        free(path);
        return error;
@@ -391,7 +398,7 @@ err:
  *
  *  returns 0 on success.
  */
-int cg_delete_cgroup(struct cgroup *cgroup, int force)
+int cg_delete_cgroup(struct cgroup *cgroup, int ignore_migration)
 {
        FILE *delete_tasks, *base_tasks;
        int tids;
@@ -424,7 +431,7 @@ int cg_delete_cgroup(struct cgroup *cgroup, int force)
 del_open_err:
        fclose(base_tasks);
 base_open_err:
-       if (force) {
+       if (ignore_migration) {
                cg_build_path(cgroup->name, path);
                error = rmdir(path);
        }
diff --git a/libcg.h b/libcg.h
index 5b6f4a24c890f115244e30ad8d94286e8d7cb7af..88f5a45a202423104998e109dbb7be95202ddeb1 100644 (file)
--- a/libcg.h
+++ b/libcg.h
@@ -161,8 +161,8 @@ struct cgroup {
 int cg_init(void);
 int cg_attach_task(struct cgroup *cgroup);
 int cg_modify_cgroup(struct cgroup *cgroup);
-int cg_create_cgroup(struct cgroup *cgroup);
-int cg_delete_cgroup(struct cgroup *cgroup, int force);
+int cg_create_cgroup(struct cgroup *cgroup, int ignore_ownership);
+int cg_delete_cgroup(struct cgroup *cgroup, int ignore_migration);
 
 __END_DECLS
 
index 873f12f7da3b4a615132960c0e7e8336d2120978..6406dda6c401ae2495e18a09f827d5a7f9f58692 100644 (file)
@@ -98,7 +98,7 @@ struct cgroup *cg::makenode(const string &name, const string &task_uid,
        ccg->control_uid = cuid;
        ccg->control_gid = cgid;
 
-       ret = cg_create_cgroup(ccg);
+       ret = cg_create_cgroup(ccg, 1);
        if (ret) {
                cout << "cg create group failed " << errno << endl;
                ret = cg_delete_cgroup(ccg, 1);