From: David Goulet Date: Thu, 10 Jul 2014 20:02:02 +0000 (-0400) Subject: Fix: add a get HOME dir fallback to getpwuid X-Git-Tag: v2.6.0-rc1~151 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=04135dbd279d3d0de6a6527b9b933e59de5cb495;p=lttng-tools.git Fix: add a get HOME dir fallback to getpwuid If the $HOME or $LTTNG_HOME is not defined, fallback on getpwuid(3) of the process uid. Fixes #815 Signed-off-by: David Goulet --- diff --git a/src/common/utils.c b/src/common/utils.c index bf93386c4..b640b950e 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -822,11 +822,28 @@ LTTNG_HIDDEN char *utils_get_home_dir(void) { char *val = NULL; + struct passwd *pwd; + val = getenv(DEFAULT_LTTNG_HOME_ENV_VAR); if (val != NULL) { - return val; + goto end; + } + val = getenv(DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR); + if (val != NULL) { + goto end; } - return getenv(DEFAULT_LTTNG_FALLBACK_HOME_ENV_VAR); + + /* Fallback on the password file entry. */ + pwd = getpwuid(getuid()); + if (!pwd) { + goto end; + } + val = pwd->pw_dir; + + DBG3("Home directory is '%s'", val); + +end: + return val; } /**