aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-01-29 08:28:59 +0000
committerRon Yorston <rmy@pobox.com>2023-01-29 08:28:59 +0000
commit6295322661ac6c2ed90af69cba0003c6e37f9700 (patch)
tree44b70fdf880c37e5168ea16f2fa684b5debbadbc /shell
parent82f0d19b101271889b0b2ebe8cdb2f5eb4f64e6c (diff)
downloadbusybox-w32-6295322661ac6c2ed90af69cba0003c6e37f9700.tar.gz
busybox-w32-6295322661ac6c2ed90af69cba0003c6e37f9700.tar.bz2
busybox-w32-6295322661ac6c2ed90af69cba0003c6e37f9700.zip
win32: provide a default value for HOME
The busybox-w32 shell initialises HOME when it starts. However, if applets are run outside the environment provided by the shell they may find HOME is unset. This caused a problem for 'vi' as it was unable to locate its .exrc. If HOME isn't available in the environment make getenv(3) provide a sensible default value. The shell must use the *real* getenv(3) when determining if HOME is already set. Also, unrelated to the above, the shell shouldn't treat failure of getpwuid(3) as a fatal error. Costs 72-80 bytes.
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 6a4b8e273..ebed9b50e 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -15437,6 +15437,8 @@ exitshell(void)
15437} 15437}
15438 15438
15439#if ENABLE_PLATFORM_MINGW32 15439#if ENABLE_PLATFORM_MINGW32
15440/* We need to see if HOME is *really* unset */
15441# undef getenv
15440static void xsetenv_if_unset(const char *key, const char *value) 15442static void xsetenv_if_unset(const char *key, const char *value)
15441{ 15443{
15442 if (!getenv(key)) 15444 if (!getenv(key))
@@ -15531,10 +15533,12 @@ init(void)
15531 15533
15532 /* Initialise some variables normally set at login, but 15534 /* Initialise some variables normally set at login, but
15533 * only if someone hasn't already set them. */ 15535 * only if someone hasn't already set them. */
15534 pw = xgetpwuid(getuid()); 15536 pw = getpwuid(getuid());
15535 xsetenv_if_unset("USER", pw->pw_name); 15537 if (pw) {
15536 xsetenv_if_unset("LOGNAME", pw->pw_name); 15538 xsetenv_if_unset("USER", pw->pw_name);
15537 xsetenv_if_unset("HOME", pw->pw_dir); 15539 xsetenv_if_unset("LOGNAME", pw->pw_name);
15540 xsetenv_if_unset("HOME", pw->pw_dir);
15541 }
15538 xsetenv_if_unset("SHELL", DEFAULT_SHELL); 15542 xsetenv_if_unset("SHELL", DEFAULT_SHELL);
15539 } 15543 }
15540#endif 15544#endif