diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-04-15 11:43:29 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-04-15 11:43:29 +0200 |
| commit | 3fa97af7ccc75264fb237f279f253eddf0ba4da1 (patch) | |
| tree | d9897c308b55ecaf08b3f6da191b4a1d03e387a8 /shell | |
| parent | ad16741ccd8a8587644d88fb8fdfc41ada1928a6 (diff) | |
| download | busybox-w32-3fa97af7ccc75264fb237f279f253eddf0ba4da1.tar.gz busybox-w32-3fa97af7ccc75264fb237f279f253eddf0ba4da1.tar.bz2 busybox-w32-3fa97af7ccc75264fb237f279f253eddf0ba4da1.zip | |
ash,hush: set $HOSTNAME is bash compat. Closes 7028
function old new delta
hush_main 1056 1128 +72
ash_main 1442 1487 +45
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 6 | ||||
| -rw-r--r-- | shell/hush.c | 11 |
2 files changed, 16 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c index 7a097c814..cabeb40c5 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | #include <setjmp.h> | 41 | #include <setjmp.h> |
| 42 | #include <fnmatch.h> | 42 | #include <fnmatch.h> |
| 43 | #include <sys/times.h> | 43 | #include <sys/times.h> |
| 44 | #include <sys/utsname.h> /* for setting $HOSTNAME */ | ||
| 44 | 45 | ||
| 45 | #include "busybox.h" /* for applet_names */ | 46 | #include "busybox.h" /* for applet_names */ |
| 46 | #include "unicode.h" | 47 | #include "unicode.h" |
| @@ -13018,6 +13019,11 @@ init(void) | |||
| 13018 | #if ENABLE_ASH_BASH_COMPAT | 13019 | #if ENABLE_ASH_BASH_COMPAT |
| 13019 | p = lookupvar("SHLVL"); | 13020 | p = lookupvar("SHLVL"); |
| 13020 | setvar("SHLVL", utoa((p ? atoi(p) : 0) + 1), VEXPORT); | 13021 | setvar("SHLVL", utoa((p ? atoi(p) : 0) + 1), VEXPORT); |
| 13022 | if (!lookupvar("HOSTNAME")) { | ||
| 13023 | struct utsname uts; | ||
| 13024 | uname(&uts); | ||
| 13025 | setvar2("HOSTNAME", uts.nodename); | ||
| 13026 | } | ||
| 13021 | #endif | 13027 | #endif |
| 13022 | p = lookupvar("PWD"); | 13028 | p = lookupvar("PWD"); |
| 13023 | if (p) { | 13029 | if (p) { |
diff --git a/shell/hush.c b/shell/hush.c index 7b0ea8b0c..e1d0ece29 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -91,6 +91,7 @@ | |||
| 91 | #if ENABLE_HUSH_CASE | 91 | #if ENABLE_HUSH_CASE |
| 92 | # include <fnmatch.h> | 92 | # include <fnmatch.h> |
| 93 | #endif | 93 | #endif |
| 94 | #include <sys/utsname.h> /* for setting $HOSTNAME */ | ||
| 94 | 95 | ||
| 95 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ | 96 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ |
| 96 | #include "unicode.h" | 97 | #include "unicode.h" |
| @@ -7786,6 +7787,14 @@ int hush_main(int argc, char **argv) | |||
| 7786 | 7787 | ||
| 7787 | /* Export PWD */ | 7788 | /* Export PWD */ |
| 7788 | set_pwd_var(/*exp:*/ 1); | 7789 | set_pwd_var(/*exp:*/ 1); |
| 7790 | |||
| 7791 | #if ENABLE_HUSH_BASH_COMPAT | ||
| 7792 | /* Set (but not export) HOSTNAME unless already set */ | ||
| 7793 | if (!get_local_var_value("HOSTNAME")) { | ||
| 7794 | struct utsname uts; | ||
| 7795 | uname(&uts); | ||
| 7796 | set_local_var_from_halves("HOSTNAME", uts.nodename); | ||
| 7797 | } | ||
| 7789 | /* bash also exports SHLVL and _, | 7798 | /* bash also exports SHLVL and _, |
| 7790 | * and sets (but doesn't export) the following variables: | 7799 | * and sets (but doesn't export) the following variables: |
| 7791 | * BASH=/bin/bash | 7800 | * BASH=/bin/bash |
| @@ -7794,7 +7803,6 @@ int hush_main(int argc, char **argv) | |||
| 7794 | * HOSTTYPE=i386 | 7803 | * HOSTTYPE=i386 |
| 7795 | * MACHTYPE=i386-pc-linux-gnu | 7804 | * MACHTYPE=i386-pc-linux-gnu |
| 7796 | * OSTYPE=linux-gnu | 7805 | * OSTYPE=linux-gnu |
| 7797 | * HOSTNAME=<xxxxxxxxxx> | ||
| 7798 | * PPID=<NNNNN> - we also do it elsewhere | 7806 | * PPID=<NNNNN> - we also do it elsewhere |
| 7799 | * EUID=<NNNNN> | 7807 | * EUID=<NNNNN> |
| 7800 | * UID=<NNNNN> | 7808 | * UID=<NNNNN> |
| @@ -7822,6 +7830,7 @@ int hush_main(int argc, char **argv) | |||
| 7822 | * PS2='> ' | 7830 | * PS2='> ' |
| 7823 | * PS4='+ ' | 7831 | * PS4='+ ' |
| 7824 | */ | 7832 | */ |
| 7833 | #endif | ||
| 7825 | 7834 | ||
| 7826 | #if ENABLE_FEATURE_EDITING | 7835 | #if ENABLE_FEATURE_EDITING |
| 7827 | G.line_input_state = new_line_input_t(FOR_SHELL); | 7836 | G.line_input_state = new_line_input_t(FOR_SHELL); |
