From f8077fbe6831018338dae29077a21d4b06ba7e85 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 11 Dec 2014 21:37:43 +0000 Subject: sh: don't overwrite login environment variables if already set Certain environment variables (HOME, LOGNAME, USER, SHELL) are set during early shell startup to emulate what login/su would do on UNIX. If any of these are already set don't overwrite them. --- libbb/setup_environment.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index 4258656fe..944ac5538 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c @@ -30,6 +30,14 @@ #include "libbb.h" +#if ENABLE_PLATFORM_MINGW32 +static void xsetenv_if_unset(const char *key, const char *value) +{ + if (!getenv(key)) + xsetenv(key, value); +} +#endif + void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) { if (!shell || !shell[0]) @@ -61,6 +69,9 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass //xsetenv("HOME", pw->pw_dir); //xsetenv("SHELL", shell); } else if (flags & SETUP_ENV_CHANGEENV) { +#if ENABLE_PLATFORM_MINGW32 +#define xsetenv(k, v) xsetenv_if_unset(k, v) +#endif /* Set HOME, SHELL, and if not becoming a super-user, * USER and LOGNAME. */ if (pw->pw_uid) { -- cgit v1.2.3-55-g6feb