From dc250e0c294970d4b424e8760792fdd372793e64 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 18 Sep 2018 21:03:04 -0500 Subject: [PATCH] Fix fish startup behavior in presence of unset $USER As reported in fish-shell/fish-shell#5180, when the USER environment variable is not set and fish is started, `get_runtime_path()` returns a blank string. At some point in the past, this was called after `setup_user()` in env.cpp, but this is no longer the case. This commit removes the reliance on the $USER environment variable entirely, and instead uses `getpwuid(geteuid()).pw_name` to retrieve the current username. Closes #5180. --- src/env_universal_common.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index 1cbf5b675..b23c2664c 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -140,12 +140,9 @@ static wcstring get_runtime_path() { if (dir != NULL && access(dir, mode) == 0 && check_runtime_path(dir) == 0) { result = str2wcstring(dir); } else { - const char *uname = getenv("USER"); - // $USER should already have been set (in setup_path()). - // If it still isn't, there's something wrong. - if (!uname) { - return result; - } + // Don't rely on $USER being set, as setup_user() has not yet been called. + // See https://github.com/fish-shell/fish-shell/issues/5180 + const char *uname = getpwuid(geteuid()).pw_name; // /tmp/fish.user std::string tmpdir = "/tmp/fish."; tmpdir.append(uname);