X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Frunas.c;h=d75eb21027ce0ae2b7df768698d8c913bb4297ea;hp=5bd43e65b7c072b5ea40e1f6e16807f594986fe4;hb=3fd15a7429ca3f5307a783e264155ae0218511ec;hpb=4d513a5063879aa41c5ce27d245a7c56ecaa6e79 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