diff --git a/daemon/gamemode.c b/daemon/gamemode.c index 4e20aae..22e3d2e 100644 --- a/daemon/gamemode.c +++ b/daemon/gamemode.c @@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include #include @@ -48,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include /* SCHED_ISO may not be defined as it is a reserved value not yet @@ -671,6 +673,25 @@ GameModeContext *game_mode_context_instance() return &instance; } +/** + * Lookup the home directory of the user in a safe way. + */ +static char *game_mode_lookup_user_home(void) +{ + /* Try loading env HOME first */ + const char *home = secure_getenv("HOME"); + if (!home) { + /* If HOME is not defined (or out of context), fall back to passwd */ + struct passwd *pw = getpwuid(getuid()); + if (!pw) + return NULL; + home = pw->pw_dir; + } + + /* Try to allocate into our heap */ + return home ? strdup(home) : NULL; +} + /** * Attempt to locate the exe for the process. * We might run into issues if the process is running under an odd umask.