aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-05-21 08:36:09 +0100
committerRon Yorston <rmy@pobox.com>2024-05-21 08:36:09 +0100
commit05b053cd388219d6b194b99ce9e543271dab121f (patch)
treea48d01ac29f51b93a5b4b41e271478fb6ddf8446 /shell/ash.c
parent97c9c40deb0774ffa55e65976c11ae1d51832898 (diff)
downloadbusybox-w32-05b053cd388219d6b194b99ce9e543271dab121f.tar.gz
busybox-w32-05b053cd388219d6b194b99ce9e543271dab121f.tar.bz2
busybox-w32-05b053cd388219d6b194b99ce9e543271dab121f.zip
ash: prevent mintty from setting HOME
The Cygwin terminal program mintty sets the HOME environment variable. Attempt to detect this and unset HOME so the usual busybox-w32 initialisation of HOME is used instead. Adds 80 bytes. (GitHub issue #420)
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c
index b753678c0..4fdc6f1c6 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -15886,9 +15886,16 @@ static void setvar_if_unset(const char *key, const char *value)
15886#endif 15886#endif
15887 15887
15888#if ENABLE_PLATFORM_MINGW32 15888#if ENABLE_PLATFORM_MINGW32
15889/*
15890 * Detect if the environment contains certain mixed-case names:
15891 *
15892 * Home is present in a standard Windows environment
15893 * ComSpec is present in WINE
15894 * ProgramData is present in Cygwin/MSYS2
15895 */
15889static int mixed_case_special_name(const char *envp) 15896static int mixed_case_special_name(const char *envp)
15890{ 15897{
15891 const char *names = "PATH=\0""COMSPEC=\0"; 15898 const char *names = "PATH=\0""COMSPEC=\0""PROGRAMDATA=\0";
15892 const char *n; 15899 const char *n;
15893 15900
15894 for (n = names; *n; ) { 15901 for (n = names; *n; ) {
@@ -15936,6 +15943,11 @@ init(void)
15936 */ 15943 */
15937 for (envp = environ; envp && *envp; envp++) { 15944 for (envp = environ; envp && *envp; envp++) {
15938 if (mixed_case_special_name(*envp)) { 15945 if (mixed_case_special_name(*envp)) {
15946 /* mintty sets HOME: unset it */
15947 const char *tty = getenv("TERM_PROGRAM");
15948 if (tty && strcmp(tty, "mintty") == 0) {
15949 unsetenv("HOME");
15950 }
15939 break; 15951 break;
15940 } 15952 }
15941 } 15953 }