Use utils mkdir recursive in runas.c
authorDavid Goulet <dgoulet@efficios.com>
Wed, 23 Jan 2013 18:44:12 +0000 (13:44 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 23 Jan 2013 18:44:12 +0000 (13:44 -0500)
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/common/runas.c

index 5bd43e65b7c072b5ea40e1f6e16807f594986fe4..d75eb21027ce0ae2b7df768698d8c913bb4297ea 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/signal.h>
 
 #include <common/error.h>
+#include <common/utils.h>
 #include <common/compat/mman.h>
 #include <common/compat/clone.h>
 
@@ -84,56 +85,12 @@ int _mkdir_recursive(void *_data)
 {
        struct run_as_mkdir_data *data = _data;
        const char *path;
-       char *p, tmp[PATH_MAX];
-       struct stat statbuf;
        mode_t mode;
-       size_t len;
-       int ret;
 
        path = data->path;
        mode = data->mode;
 
-       ret = snprintf(tmp, sizeof(tmp), "%s", path);
-       if (ret < 0) {
-               PERROR("snprintf mkdir");
-               goto error;
-       }
-
-       len = ret;
-       if (tmp[len - 1] == '/') {
-               tmp[len - 1] = 0;
-       }
-
-       for (p = tmp + 1; *p; p++) {
-               if (*p == '/') {
-                       *p = 0;
-                       ret = stat(tmp, &statbuf);
-                       if (ret < 0) {
-                               ret = mkdir(tmp, mode);
-                               if (ret < 0) {
-                                       if (!(errno == EEXIST)) {
-                                               PERROR("mkdir recursive");
-                                               ret = -errno;
-                                               goto error;
-                                       }
-                               }
-                       }
-                       *p = '/';
-               }
-       }
-
-       ret = mkdir(tmp, mode);
-       if (ret < 0) {
-               if (!(errno == EEXIST)) {
-                       PERROR("mkdir recursive last piece");
-                       ret = -errno;
-               } else {
-                       ret = 0;
-               }
-       }
-
-error:
-       return ret;
+       return utils_mkdir_recursive(path, mode);
 }
 
 static
This page took 0.035083 seconds and 4 git commands to generate.