]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: Make libcgroup use rentrant functions
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Mon, 21 Jul 2008 12:54:45 +0000 (12:54 +0000)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Mon, 21 Jul 2008 12:54:45 +0000 (12:54 +0000)
This patch converts functions which have reentrant versions to
use those versions.

Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Paul Menage <menage@google.com>
Cc: Dan Smith <danms@us.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@109 4f4bb910-9a46-0410-90c8-c897d4f1cd53

api.c

diff --git a/api.c b/api.c
index 2d4490d9c015d76be34c5993b71cf11823b8706b..ce263e6487eaf33d302bd657998dfaf2df4008c7 100644 (file)
--- a/api.c
+++ b/api.c
@@ -120,7 +120,7 @@ static int cgroup_test_subsys_mounted(const char *name)
 int cgroup_init()
 {
        FILE *proc_mount;
-       struct mntent *ent;
+       struct mntent *ent, *temp_ent;
        int found_mnt = 0;
        int ret = 0;
        static char *controllers[CG_CONTROLLER_MAX];
@@ -131,6 +131,8 @@ int cgroup_init()
        char *mntopt;
        int err;
        char *buf;
+       char mntent_buffer[4 * FILENAME_MAX];
+       char *strtok_buffer;
 
        proc_cgroup = fopen("/proc/cgroups", "r");
 
@@ -164,11 +166,15 @@ int cgroup_init()
                return EIO;
        }
 
-       while ((ent = getmntent(proc_mount)) != NULL) {
+       temp_ent = (struct mntent *) malloc(sizeof(struct mntent));
+
+       while ((ent = getmntent_r(proc_mount, temp_ent,
+                                       mntent_buffer,
+                                       sizeof(mntent_buffer))) != NULL) {
                if (!strncmp(ent->mnt_type, "cgroup", strlen("cgroup"))) {
                        for (i = 0; controllers[i] != NULL; i++) {
                                mntopt = hasmntopt(ent, controllers[i]);
-                               mntopt = strtok(mntopt, ",");
+                               mntopt = strtok_r(mntopt, ",", &strtok_buffer);
                                if (mntopt &&
                                        strcmp(mntopt, controllers[i]) == 0) {
                                        dbg("matched %s:%s\n", mntopt,
@@ -202,13 +208,17 @@ int cgroup_init()
 static int cg_test_mounted_fs()
 {
        FILE *proc_mount;
-       struct mntent *ent;
+       struct mntent *ent, *temp_ent;
+       char mntent_buff[4 * FILENAME_MAX];
 
        proc_mount = fopen("/proc/mounts", "r");
        if (proc_mount == NULL) {
                return -1;
        }
-       ent = getmntent(proc_mount);
+
+       temp_ent = (struct mntent *) malloc(sizeof(struct mntent));
+       ent = getmntent_r(proc_mount, temp_ent, mntent_buff,
+                                               sizeof(mntent_buff));
 
        while (strcmp(ent->mnt_type, "cgroup") !=0) {
                ent = getmntent(proc_mount);