From 575581082befff0e049ef67fa36bbdd2ca737e29 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 14 Dec 2018 15:12:52 +0000 Subject: ash: move code from setup_environment() ash calls setup_environment() but only uses a small amount of its functionality. Moving the code into ash itself means we don't need to customise setup_environment() for WIN32 and can remove it from the build. --- libbb/Kbuild.src | 2 +- libbb/setup_environment.c | 11 ----------- shell/ash.c | 9 ++++++--- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index 9323a8968..43ededbea 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src @@ -66,7 +66,6 @@ lib-y += safe_poll.o lib-y += safe_strncpy.o lib-y += safe_write.o lib-y += securetty.o -lib-y += setup_environment.o lib-y += single_argv.o lib-y += skip_whitespace.o lib-y += str_tolower.o @@ -106,6 +105,7 @@ lib-$(CONFIG_PLATFORM_POSIX) += pidfile.o lib-$(CONFIG_PLATFORM_POSIX) += print_flags.o lib-$(CONFIG_PLATFORM_POSIX) += progress.o lib-$(CONFIG_PLATFORM_POSIX) += read_key.o +lib-$(CONFIG_PLATFORM_POSIX) += setup_environment.o lib-$(CONFIG_PLATFORM_POSIX) += signals.o lib-$(CONFIG_PLATFORM_POSIX) += simplify_path.o lib-$(CONFIG_PLATFORM_POSIX) += speed_table.o diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index c583206f0..f8de44967 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c @@ -29,14 +29,6 @@ */ #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]) @@ -68,9 +60,6 @@ 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) { diff --git a/shell/ash.c b/shell/ash.c index 0b41e7931..3bbfbd694 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -14584,10 +14584,13 @@ init(void) } } - /* some initialisation normally performed at login */ + /* Initialise some variables normally set at login, but + * only if someone hasn't already set them. */ pw = xgetpwuid(getuid()); - setup_environment(pw->pw_shell, - SETUP_ENV_CHANGEENV|SETUP_ENV_NO_CHDIR, pw); + if (!getenv("USER")) xsetenv("USER", pw->pw_name); + if (!getenv("LOGNAME")) xsetenv("LOGNAME", pw->pw_name); + if (!getenv("HOME")) xsetenv("HOME", pw->pw_dir); + if (!getenv("SHELL")) xsetenv("SHELL", DEFAULT_SHELL); } #endif for (envp = environ; envp && *envp; envp++) { -- cgit v1.2.3-55-g6feb