X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcommon%2Futils.c;h=ecac5381f061fb65c89bda64de0ad86e5be37f6f;hb=07b86b528dc279d59cdf16e6cb946c144fe773f2;hp=38f78a7e8e7d40cd6fcebefd297e5bb240c52aaf;hpb=cfa9a5a2b4a96e0d6a9eeddd2622a6d7c173b7ac;p=lttng-tools.git diff --git a/src/common/utils.c b/src/common/utils.c index 38f78a7e8..ecac5381f 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -22,8 +22,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -32,6 +32,7 @@ #include #include "utils.h" +#include "defaults.h" /* * Return the realpath(3) of the path even if the last directory token does not @@ -248,7 +249,6 @@ LTTNG_HIDDEN int utils_mkdir_recursive(const char *path, mode_t mode) { char *p, tmp[PATH_MAX]; - struct stat statbuf; size_t len; int ret; @@ -276,15 +276,12 @@ int utils_mkdir_recursive(const char *path, mode_t mode) ret = -1; goto error; } - ret = stat(tmp, &statbuf); + ret = mkdir(tmp, mode); if (ret < 0) { - ret = mkdir(tmp, mode); - if (ret < 0) { - if (errno != EEXIST) { - PERROR("mkdir recursive"); - ret = -errno; - goto error; - } + if (errno != EEXIST) { + PERROR("mkdir recursive"); + ret = -errno; + goto error; } } *p = '/'; @@ -311,7 +308,7 @@ error: * Return 0 on success or else a negative value. */ LTTNG_HIDDEN -int utils_create_stream_file(char *path_name, char *file_name, uint64_t size, +int utils_create_stream_file(const char *path_name, char *file_name, uint64_t size, uint64_t count, int uid, int gid) { int ret, out_fd, flags, mode; @@ -584,3 +581,17 @@ int utils_get_count_order_u32(uint32_t x) return fls_u32(x - 1); } + +/** + * Obtain the value of LTTNG_HOME environment variable, if exists. + * Otherwise returns the value of HOME. + */ +char *utils_get_home_dir(void) +{ + char *val = NULL; + val = getenv(DEFAULT_LTTNG_HOME_ENV_VAR); + if (val != NULL) { + return val; + } + return getenv(DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR); +}