Fix: add a get HOME dir fallback to getpwuid stable-2.3
authorDavid Goulet <dgoulet@efficios.com>
Thu, 10 Jul 2014 20:02:02 +0000 (16:02 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 10 Jul 2014 20:03:06 +0000 (16:03 -0400)
If the $HOME or $LTTNG_HOME is not defined, fallback on getpwuid(3) of
the process uid.

Fixes #815

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/common/utils.c

index 11b165bc15444fa66005f2ee65c4579e6c9fef32..cf610fb3bbb29c206b95616b78db2341fcf61599 100644 (file)
@@ -633,11 +633,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;
 }
 
 /*
This page took 0.026489 seconds and 4 git commands to generate.