From 01ec61cea57eaf6c20cce540efc3fed08c416c07 Mon Sep 17 00:00:00 2001 From: Dhaval Giani Date: Wed, 23 Jul 2008 06:11:38 +0000 Subject: libcgroup: Fix up rentrant functions patch. Some errors were not handled, this patch handles those errors. Signed-off-by: Dhaval Giani git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@114 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- api.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'api.c') diff --git a/api.c b/api.c index a3ce557..acc00e5 100644 --- 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; } -- cgit