From 05b053cd388219d6b194b99ce9e543271dab121f Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 21 May 2024 08:36:09 +0100 Subject: 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) --- shell/ash.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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) #endif #if ENABLE_PLATFORM_MINGW32 +/* + * Detect if the environment contains certain mixed-case names: + * + * Home is present in a standard Windows environment + * ComSpec is present in WINE + * ProgramData is present in Cygwin/MSYS2 + */ static int mixed_case_special_name(const char *envp) { - const char *names = "PATH=\0""COMSPEC=\0"; + const char *names = "PATH=\0""COMSPEC=\0""PROGRAMDATA=\0"; const char *n; for (n = names; *n; ) { @@ -15936,6 +15943,11 @@ init(void) */ for (envp = environ; envp && *envp; envp++) { if (mixed_case_special_name(*envp)) { + /* mintty sets HOME: unset it */ + const char *tty = getenv("TERM_PROGRAM"); + if (tty && strcmp(tty, "mintty") == 0) { + unsetenv("HOME"); + } break; } } -- cgit v1.2.3-55-g6feb