Fix: missing include for getpwuid()
[lttng-tools.git] / src / common / utils.c
index 40c402953f354b8c6cbd98ffaf0fc25adb4b7c64..d4b42ea3491b22165fd9dc13c2c612782c3807db 100644 (file)
@@ -28,6 +28,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include <grp.h>
+#include <pwd.h>
 
 #include <common/common.h>
 #include <common/runas.h>
@@ -820,11 +821,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;
 }
 
 /*
@@ -847,7 +865,7 @@ size_t utils_get_current_time_str(const char *format, char *dst, size_t len)
        timeinfo = localtime(&rawtime);
        ret = strftime(dst, len, format, timeinfo);
        if (ret == 0) {
-               ERR("Unable to strftime with format %s at dst %p of len %lu", format,
+               ERR("Unable to strftime with format %s at dst %p of len %zu", format,
                                dst, len);
        }
 
This page took 0.023381 seconds and 4 git commands to generate.