From: David Goulet Date: Wed, 23 Jan 2013 18:44:12 +0000 (-0500) Subject: Use utils mkdir recursive in runas.c X-Git-Tag: v2.2.0-rc1~85 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3fd15a7429ca3f5307a783e264155ae0218511ec;p=lttng-tools.git Use utils mkdir recursive in runas.c Signed-off-by: David Goulet --- diff --git a/src/common/runas.c b/src/common/runas.c index 5bd43e65b..d75eb2102 100644 --- a/src/common/runas.c +++ b/src/common/runas.c @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -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