mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
parent
529ba30b1a
commit
3b92d99277
1 changed files with 25 additions and 19 deletions
44
src/env.cpp
44
src/env.cpp
|
@ -867,28 +867,34 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
||||||
// env HOME=(mktemp -d) su --preserve-environment fish
|
// env HOME=(mktemp -d) su --preserve-environment fish
|
||||||
if (env_get_string(L"HOME").missing_or_empty()) {
|
if (env_get_string(L"HOME").missing_or_empty()) {
|
||||||
const env_var_t unam = env_get_string(L"USER");
|
const env_var_t unam = env_get_string(L"USER");
|
||||||
char *unam_narrow = wcs2str(unam.c_str());
|
if (!unam.missing_or_empty()) {
|
||||||
struct passwd userinfo;
|
char *unam_narrow = wcs2str(unam.c_str());
|
||||||
struct passwd *result;
|
struct passwd userinfo;
|
||||||
char buf[8192];
|
struct passwd *result;
|
||||||
int retval = getpwnam_r(unam_narrow, &userinfo, buf, sizeof(buf), &result);
|
char buf[8192];
|
||||||
if (retval || !result) {
|
int retval = getpwnam_r(unam_narrow, &userinfo, buf, sizeof(buf), &result);
|
||||||
// Maybe USER is set but it's bogus. Reset USER from the db and try again.
|
if (retval || !result) {
|
||||||
setup_user(true);
|
// Maybe USER is set but it's bogus. Reset USER from the db and try again.
|
||||||
const env_var_t unam = env_get_string(L"USER");
|
setup_user(true);
|
||||||
unam_narrow = wcs2str(unam.c_str());
|
const env_var_t unam = env_get_string(L"USER");
|
||||||
retval = getpwnam_r(unam_narrow, &userinfo, buf, sizeof(buf), &result);
|
unam_narrow = wcs2str(unam.c_str());
|
||||||
}
|
retval = getpwnam_r(unam_narrow, &userinfo, buf, sizeof(buf), &result);
|
||||||
if (!retval && result && userinfo.pw_dir) {
|
}
|
||||||
const wcstring dir = str2wcstring(userinfo.pw_dir);
|
if (!retval && result && userinfo.pw_dir) {
|
||||||
env_set(L"HOME", dir.c_str(), ENV_GLOBAL | ENV_EXPORT);
|
const wcstring dir = str2wcstring(userinfo.pw_dir);
|
||||||
|
env_set(L"HOME", dir.c_str(), ENV_GLOBAL | ENV_EXPORT);
|
||||||
|
} else {
|
||||||
|
// We cannot get $HOME, set it to the empty list.
|
||||||
|
// This triggers warnings for history and config.fish already,
|
||||||
|
// so it isn't necessary to warn here as well.
|
||||||
|
env_set(L"HOME", ENV_NULL, ENV_GLOBAL | ENV_EXPORT);
|
||||||
|
}
|
||||||
|
free(unam_narrow);
|
||||||
} else {
|
} else {
|
||||||
// We cannot get $HOME, set it to the empty list.
|
// If $USER is empty as well (which we tried to set above),
|
||||||
// This triggers warnings for history and config.fish already,
|
// we can't get $HOME.
|
||||||
// so it isn't necessary to warn here as well.
|
|
||||||
env_set(L"HOME", ENV_NULL, ENV_GLOBAL | ENV_EXPORT);
|
env_set(L"HOME", ENV_NULL, ENV_GLOBAL | ENV_EXPORT);
|
||||||
}
|
}
|
||||||
free(unam_narrow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
env_set_pwd(); // initialize the PWD variable
|
env_set_pwd(); // initialize the PWD variable
|
||||||
|
|
Loading…
Reference in a new issue