]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: Change how cgroup_get_cgroup works
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Mon, 29 Sep 2008 14:14:51 +0000 (14:14 +0000)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Mon, 29 Sep 2008 14:14:51 +0000 (14:14 +0000)
Since we will not deprecate API now, and will do so with the
next release, let's include this one in and get the API right.

With this pathc, we now return int type, and the pointer passed
as the argument redirects to the cgroup we are reading.

Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@202 4f4bb910-9a46-0410-90c8-c897d4f1cd53

api.c
libcgroup.h

diff --git a/api.c b/api.c
index ff2a30a24fa87f8d1a36384f2143d6679ef4898a..c11d83d684c58a83337f5eb87a2e3c26adfd15cc 100644 (file)
--- a/api.c
+++ b/api.c
@@ -1215,7 +1215,7 @@ int cgroup_create_cgroup_from_parent(struct cgroup *cgroup,
        if (!parent_cgroup)
                goto err_nomem;
 
-       if (cgroup_get_cgroup(parent_cgroup) == NULL)
+       if (cgroup_get_cgroup(parent_cgroup))
                goto err_parent;
 
        dbg("got parent group for %s\n", parent_cgroup->name);
@@ -1430,12 +1430,12 @@ fill_error:
 }
 
 /*
- * cgroup_get_cgroup returns the cgroup data from the filesystem.
+ * cgroup_get_cgroup reads the cgroup data from the filesystem.
  * struct cgroup has the name of the group to be populated
  *
- * return succesfully filled cgroup data structure on success.
+ * return 0 on success.
  */
-struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup)
+int cgroup_get_cgroup(struct cgroup *cgroup)
 {
        int i;
        char path[FILENAME_MAX];
@@ -1446,12 +1446,12 @@ struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup)
 
        if (!cgroup_initialized) {
                /* ECGROUPNOTINITIALIZED */
-               return NULL;
+               return ECGROUPNOTINITIALIZED;
        }
 
        if (!cgroup) {
                /* ECGROUPNOTALLOWED */
-               return NULL;
+               return ECGROUPNOTALLOWED;
        }
 
        pthread_rwlock_rdlock(&cg_mount_table_lock);
@@ -1489,15 +1489,19 @@ struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup)
                 */
 
                control_path = malloc(strlen(path) + strlen("tasks") + 1);
-               strcpy(control_path, path);
 
-               if (!control_path)
+               if (!control_path) {
+                       error = ECGOTHER;
                        goto unlock_error;
+               }
+
+               strcpy(control_path, path);
 
                strcat(control_path, "tasks");
 
                if (stat(control_path, &stat_buffer)) {
                        free(control_path);
+                       error = ECGOTHER;
                        goto unlock_error;
                }
 
@@ -1508,12 +1512,14 @@ struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup)
 
                cgc = cgroup_add_controller(cgroup,
                                cg_mount_table[i].name);
-               if (!cgc)
+               if (!cgc) {
+                       error = ECGINVAL;
                        goto unlock_error;
+               }
 
                dir = opendir(path);
                if (!dir) {
-                       /* error = ECGROUPSTRUCTERROR; */
+                       error = ECGOTHER;
                        goto unlock_error;
                }
 
@@ -1534,16 +1540,22 @@ struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup)
        }
 
        /* Check if the group really exists or not */
-       if (!cgroup->index)
+       if (!cgroup->index) {
+               error = ECGROUPNOTEXIST;
                goto unlock_error;
+       }
 
        pthread_rwlock_unlock(&cg_mount_table_lock);
-       return cgroup;
+       return 0;
 
 unlock_error:
        pthread_rwlock_unlock(&cg_mount_table_lock);
+       /*
+        * XX: Need to figure out how to cleanup? Cleanup just the stuff
+        * we added, or the whole structure.
+        */
        cgroup = NULL;
-       return NULL;
+       return error;
 }
 
 /** cg_prepare_cgroup
index 93258461e8ae4fd4435acd867c31af3a54791e10..2a93022e2f02d69163e82ee18df45de29c275e5f 100644 (file)
@@ -114,7 +114,7 @@ int cgroup_modify_cgroup(struct cgroup *cgroup);
 int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership);
 int cgroup_delete_cgroup(struct cgroup *cgroup, int ignore_migration);
 int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid);
-struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup);
+int cgroup_get_cgroup(struct cgroup *cgroup);
 int cgroup_create_cgroup_from_parent(struct cgroup *cgroup, int ignore_ownership);
 int cgroup_copy_cgroup(struct cgroup *dst, struct cgroup *src);