Handle setting $HOME with missing $USER

Fixes #4229 harder.
This commit is contained in:
Fabian Homborg 2017-07-20 19:45:03 +02:00
parent 529ba30b1a
commit 3b92d99277

View file

@ -867,6 +867,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
// env HOME=(mktemp -d) su --preserve-environment fish
if (env_get_string(L"HOME").missing_or_empty()) {
const env_var_t unam = env_get_string(L"USER");
if (!unam.missing_or_empty()) {
char *unam_narrow = wcs2str(unam.c_str());
struct passwd userinfo;
struct passwd *result;
@ -889,6 +890,11 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
env_set(L"HOME", ENV_NULL, ENV_GLOBAL | ENV_EXPORT);
}
free(unam_narrow);
} else {
// If $USER is empty as well (which we tried to set above),
// we can't get $HOME.
env_set(L"HOME", ENV_NULL, ENV_GLOBAL | ENV_EXPORT);
}
}
env_set_pwd(); // initialize the PWD variable