diff options
author | Ron Yorston <rmy@pobox.com> | 2018-12-14 15:12:52 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-12-14 17:41:23 +0000 |
commit | 575581082befff0e049ef67fa36bbdd2ca737e29 (patch) | |
tree | 047f75d89b1c88838bd95e1335b51a62ee5ed615 | |
parent | 858091c25687727c335880dca459fe5b24259009 (diff) | |
download | busybox-w32-575581082befff0e049ef67fa36bbdd2ca737e29.tar.gz busybox-w32-575581082befff0e049ef67fa36bbdd2ca737e29.tar.bz2 busybox-w32-575581082befff0e049ef67fa36bbdd2ca737e29.zip |
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.
-rw-r--r-- | libbb/Kbuild.src | 2 | ||||
-rw-r--r-- | libbb/setup_environment.c | 11 | ||||
-rw-r--r-- | 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 | |||
66 | lib-y += safe_strncpy.o | 66 | lib-y += safe_strncpy.o |
67 | lib-y += safe_write.o | 67 | lib-y += safe_write.o |
68 | lib-y += securetty.o | 68 | lib-y += securetty.o |
69 | lib-y += setup_environment.o | ||
70 | lib-y += single_argv.o | 69 | lib-y += single_argv.o |
71 | lib-y += skip_whitespace.o | 70 | lib-y += skip_whitespace.o |
72 | lib-y += str_tolower.o | 71 | lib-y += str_tolower.o |
@@ -106,6 +105,7 @@ lib-$(CONFIG_PLATFORM_POSIX) += pidfile.o | |||
106 | lib-$(CONFIG_PLATFORM_POSIX) += print_flags.o | 105 | lib-$(CONFIG_PLATFORM_POSIX) += print_flags.o |
107 | lib-$(CONFIG_PLATFORM_POSIX) += progress.o | 106 | lib-$(CONFIG_PLATFORM_POSIX) += progress.o |
108 | lib-$(CONFIG_PLATFORM_POSIX) += read_key.o | 107 | lib-$(CONFIG_PLATFORM_POSIX) += read_key.o |
108 | lib-$(CONFIG_PLATFORM_POSIX) += setup_environment.o | ||
109 | lib-$(CONFIG_PLATFORM_POSIX) += signals.o | 109 | lib-$(CONFIG_PLATFORM_POSIX) += signals.o |
110 | lib-$(CONFIG_PLATFORM_POSIX) += simplify_path.o | 110 | lib-$(CONFIG_PLATFORM_POSIX) += simplify_path.o |
111 | lib-$(CONFIG_PLATFORM_POSIX) += speed_table.o | 111 | 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 @@ | |||
29 | */ | 29 | */ |
30 | #include "libbb.h" | 30 | #include "libbb.h" |
31 | 31 | ||
32 | #if ENABLE_PLATFORM_MINGW32 | ||
33 | static void xsetenv_if_unset(const char *key, const char *value) | ||
34 | { | ||
35 | if (!getenv(key)) | ||
36 | xsetenv(key, value); | ||
37 | } | ||
38 | #endif | ||
39 | |||
40 | void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) | 32 | void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) |
41 | { | 33 | { |
42 | if (!shell || !shell[0]) | 34 | if (!shell || !shell[0]) |
@@ -68,9 +60,6 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass | |||
68 | //xsetenv("HOME", pw->pw_dir); | 60 | //xsetenv("HOME", pw->pw_dir); |
69 | //xsetenv("SHELL", shell); | 61 | //xsetenv("SHELL", shell); |
70 | } else if (flags & SETUP_ENV_CHANGEENV) { | 62 | } else if (flags & SETUP_ENV_CHANGEENV) { |
71 | #if ENABLE_PLATFORM_MINGW32 | ||
72 | #define xsetenv(k, v) xsetenv_if_unset(k, v) | ||
73 | #endif | ||
74 | /* Set HOME, SHELL, and if not becoming a super-user, | 63 | /* Set HOME, SHELL, and if not becoming a super-user, |
75 | * USER and LOGNAME. */ | 64 | * USER and LOGNAME. */ |
76 | if (pw->pw_uid) { | 65 | 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) | |||
14584 | } | 14584 | } |
14585 | } | 14585 | } |
14586 | 14586 | ||
14587 | /* some initialisation normally performed at login */ | 14587 | /* Initialise some variables normally set at login, but |
14588 | * only if someone hasn't already set them. */ | ||
14588 | pw = xgetpwuid(getuid()); | 14589 | pw = xgetpwuid(getuid()); |
14589 | setup_environment(pw->pw_shell, | 14590 | if (!getenv("USER")) xsetenv("USER", pw->pw_name); |
14590 | SETUP_ENV_CHANGEENV|SETUP_ENV_NO_CHDIR, pw); | 14591 | if (!getenv("LOGNAME")) xsetenv("LOGNAME", pw->pw_name); |
14592 | if (!getenv("HOME")) xsetenv("HOME", pw->pw_dir); | ||
14593 | if (!getenv("SHELL")) xsetenv("SHELL", DEFAULT_SHELL); | ||
14591 | } | 14594 | } |
14592 | #endif | 14595 | #endif |
14593 | for (envp = environ; envp && *envp; envp++) { | 14596 | for (envp = environ; envp && *envp; envp++) { |