]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: Fix up rentrant functions patch.
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Wed, 23 Jul 2008 06:11:38 +0000 (06:11 +0000)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Wed, 23 Jul 2008 06:11:38 +0000 (06:11 +0000)
Some errors were not handled, this patch handles those errors.

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

api.c

diff --git a/api.c b/api.c
index a3ce5576048d786b5b404d78ebd34c50911de1f8..acc00e56f85aa2f8acd78d921954de89aa02e368 100644 (file)
--- a/api.c
+++ b/api.c
@@ -175,16 +175,21 @@ int cgroup_init()
 
        proc_mount = fopen("/proc/mounts", "r");
        if (proc_mount == NULL) {
-               ret = EIO;
+               ret = ECGFAIL;
                goto unlock_exit;
        }
 
        temp_ent = (struct mntent *) malloc(sizeof(struct mntent));
 
+       if (!temp_ent) {
+               ret = ECGFAIL;
+               goto unlock_exit;
+       }
+
        while ((ent = getmntent_r(proc_mount, temp_ent,
                                        mntent_buffer,
                                        sizeof(mntent_buffer))) != NULL) {
-               if (!strncmp(ent->mnt_type, "cgroup", strlen("cgroup"))) {
+               if (!strcmp(ent->mnt_type, "cgroup")) {
                        for (i = 0; controllers[i] != NULL; i++) {
                                mntopt = hasmntopt(ent, controllers[i]);
                                mntopt = strtok_r(mntopt, ",", &strtok_buffer);
@@ -234,11 +239,20 @@ static int cg_test_mounted_fs()
        }
 
        temp_ent = (struct mntent *) malloc(sizeof(struct mntent));
+       if (!temp_ent) {
+               /* We just fail at the moment. */
+               return 0;
+       }
+
        ent = getmntent_r(proc_mount, temp_ent, mntent_buff,
                                                sizeof(mntent_buff));
 
+       if (!ent)
+               return 0;
+
        while (strcmp(ent->mnt_type, "cgroup") !=0) {
-               ent = getmntent(proc_mount);
+               ent = getmntent_r(proc_mount, temp_ent, mntent_buff,
+                                               sizeof(mntent_buff));
                if (ent == NULL)
                        return 0;
        }