}
}
-/**
+/*
* Get the home directory of the current user.
*
- * \return A dynamically allocated string that must be freed by the caller. If
- * the home directory could not be found, this function returns "/tmp".
+ * Returns a dynamically allocated string that must be freed by the caller. If
+ * the HOME environment variable is unset or empty, the function aborts.
*/
__must_check __malloc char *get_homedir(void)
{
- struct passwd *pw = getpwuid(getuid());
- return dss_strdup(pw? pw->pw_dir : "/tmp");
+ const char *home = getenv("HOME");
+ if (home && *home)
+ return dss_strdup(home);
+ DSS_EMERG_LOG(("fatal: HOME is unset or empty\n"));
+ exit(EXIT_FAILURE);
}
/**
return 1;
}
-/**
+/*
* Get the logname of the current user.
*
- * \return A dynamically allocated string that must be freed by the caller. On
- * errors, the string "unknown user" is returned, i.e. this function never
- * returns \p NULL.
- *
- * \sa getpwuid(3).
+ * Returns a dynamically allocated string that must be freed by the caller. On
+ * errors, the string "unknown" is returned. This function never returns NULL.
*/
__must_check __malloc char *dss_logname(void)
{
- struct passwd *pw = getpwuid(getuid());
- return dss_strdup(pw? pw->pw_name : "unknown_user");
+ const char *logname = getenv("LOGNAME");
+ if (!logname && !*logname)
+ logname = "unknown";
+ return dss_strdup(logname);
}
/**