]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Make cg_mkdir_p() function compatible with read-only fs
authorPeter Schiffer <pschiffe@redhat.com>
Thu, 16 May 2013 15:10:32 +0000 (17:10 +0200)
committerPeter Schiffer <pschiffe@redhat.com>
Thu, 16 May 2013 15:10:32 +0000 (17:10 +0200)
mkdir(2) function returns EROFS error even when the path already exists on
the read only file system, so it is impossible to determine whether the path
already exists on this kind of fs only be return code from the mkdir(2). To make
cg_mkdir_p() compatible with the ro fs, the function checks whether the
path exists with stat(2) before trying to create it.

Signed-off-by: Peter Schiffer <pschiffe@redhat.com>
Acked-By: Jan Safranek <jsafrane@redhat.com>
src/api.c

index ee18797bfe1f7265ed60b867ca2677b670055eb5..c42047503a5ed6e3791dea66fdb74aae577c3518 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -1292,7 +1292,8 @@ int cg_mkdir_p(const char *path)
        char *real_path = NULL;
        int i = 0;
        char pos;
-       int ret = 0;
+       int ret = 0, stat_ret;
+       struct stat st;
 
        real_path = strdup(path);
        if (!real_path) {
@@ -1320,6 +1321,14 @@ int cg_mkdir_p(const char *path)
                                ret = ECGROUPNOTOWNER;
                                goto done;
                        default:
+                               /* Check if path exists */
+                               real_path[i] = '\0';
+                               stat_ret = stat(real_path, &st);
+                               real_path[i] = pos;
+                               if (stat_ret == 0) {
+                                       ret = 0;        /* Path exists */
+                                       break;
+                               }
                                ret = ECGROUPNOTALLOWED;
                                goto done;
                        }