* Dhaval Giani <[email protected]> [2009-02-20 12:59:38]:

> On Fri, Feb 20, 2009 at 09:37:20AM +0530, Balbir Singh wrote:
> > 
> > From: Balbir Singh <[email protected]>
> > 
> > cgroup_create_cgroup() can return -1, which causes cgroup_strerror() to
> > assert. This patch fixes that problem and another one where we incorrectly
> > return -1 if we fail to open /proc/mounts. We should return 0 there.
> > 
> > The patch also fixes a potential security issue. We were freeing path
> > and using asprintf, but path is set to fts_path[0], which we use for
> > changing permissions recursively. I don't understand why that was done or
> > why we use asprintf there in the first place.
> 
> Can you please split this patch into two (or three), there are too many
> things happening in it. :(

[snip]

How does this look?


Impact: Bug fix, fix incorrect return values

From: Balbir Singh <[email protected]>

This patch fixes incorrect return value of -1 being returned from
some call sites. Please review, comment. printf's are ugly, so they've
been converted to dbg.

Signed-off-by: Balbir Singh <[email protected]>
---

 api.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)


diff --git a/api.c b/api.c
index 72f8c69..91b26e0 100644
--- a/api.c
+++ b/api.c
@@ -138,6 +138,10 @@ static int cg_chown_file(FTS *fts, FTSENT *ent, uid_t 
owner, gid_t group)
                break;
        }
 fail_chown:
+       if (ret < 0) {
+               last_errno = errno;
+               ret = ECGOTHER;
+       }
        return ret;
 }
 
@@ -680,7 +684,7 @@ static int cg_test_mounted_fs()
 
        proc_mount = fopen("/proc/mounts", "r");
        if (proc_mount == NULL) {
-               return -1;
+               return 0;
        }
 
        temp_ent = (struct mntent *) malloc(sizeof(struct mntent));
@@ -937,15 +941,18 @@ static int cg_mkdir_p(const char *path)
                i = j;
                ret = chdir(wd);
                if (ret) {
-                       printf("could not chdir to child directory (%s)\n", wd);
+                       dbg("could not chdir to child directory (%s)\n", wd);
                        break;
                }
                free(wd);
        } while (real_path[i]);
 
        ret = chdir(buf);
-       if (ret)
-               printf("could not go back to old directory (%s)\n", cwd);
+       if (ret) {
+               last_errno = errno;
+               ret = ECGOTHER;
+               dbg("could not go back to old directory (%s)\n", cwd);
+       }
 
 done:
        free(real_path);

-- 
        Balbir

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to