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-3fa97af7ccc75264fb237f279f253eddf0ba4da1.tar.gz |
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 @@ #include <setjmp.h> #include <fnmatch.h> #include <sys/times.h> +#include <sys/utsname.h> /* for setting $HOSTNAME */ #include "busybox.h" /* for applet_names */ #include "unicode.h" @@ -13018,6 +13019,11 @@ init(void) #if ENABLE_ASH_BASH_COMPAT p = lookupvar("SHLVL"); setvar("SHLVL", utoa((p ? atoi(p) : 0) + 1), VEXPORT); + if (!lookupvar("HOSTNAME")) { + struct utsname uts; + uname(&uts); + setvar2("HOSTNAME", uts.nodename); + } #endif p = lookupvar("PWD"); 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 @@ #if ENABLE_HUSH_CASE # include <fnmatch.h> #endif +#include <sys/utsname.h> /* for setting $HOSTNAME */ #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ #include "unicode.h" @@ -7786,6 +7787,14 @@ int hush_main(int argc, char **argv) /* Export PWD */ set_pwd_var(/*exp:*/ 1); + +#if ENABLE_HUSH_BASH_COMPAT + /* Set (but not export) HOSTNAME unless already set */ + if (!get_local_var_value("HOSTNAME")) { + struct utsname uts; + uname(&uts); + set_local_var_from_halves("HOSTNAME", uts.nodename); + } /* bash also exports SHLVL and _, * and sets (but doesn't export) the following variables: * BASH=/bin/bash @@ -7794,7 +7803,6 @@ int hush_main(int argc, char **argv) * HOSTTYPE=i386 * MACHTYPE=i386-pc-linux-gnu * OSTYPE=linux-gnu - * HOSTNAME=<xxxxxxxxxx> * PPID=<NNNNN> - we also do it elsewhere * EUID=<NNNNN> * UID=<NNNNN> @@ -7822,6 +7830,7 @@ int hush_main(int argc, char **argv) * PS2='> ' * PS4='+ ' */ +#endif #if ENABLE_FEATURE_EDITING G.line_input_state = new_line_input_t(FOR_SHELL); |