X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=f253e797fae641e31ef98abcf4e829655feb8dfc;hb=feb0f3e5900ff58202ea0c3f227de3c1b8291952;hp=38f78a7e8e7d40cd6fcebefd297e5bb240c52aaf;hpb=cfa9a5a2b4a96e0d6a9eeddd2622a6d7c173b7ac;p=lttng-tools.git diff --git a/src/common/utils.c b/src/common/utils.c index 38f78a7e8..f253e797f 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 = '/'; @@ -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); +}