diff options
author | Ron Yorston <rmy@pobox.com> | 2018-04-03 09:40:47 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-04-03 12:28:21 +0100 |
commit | ed8eb229df581c702e44a352aaf4ed47b64bf623 (patch) | |
tree | 953df3a55d3c75b80f6e1553d5b8cfa38fffa614 | |
parent | b7115d6ab736c0e9968bec3460ffa5cb12c94965 (diff) | |
download | busybox-w32-ed8eb229df581c702e44a352aaf4ed47b64bf623.tar.gz busybox-w32-ed8eb229df581c702e44a352aaf4ed47b64bf623.tar.bz2 busybox-w32-ed8eb229df581c702e44a352aaf4ed47b64bf623.zip |
ash: reinstate applet name variable after forkshell
When 'sh --forkshell' is invoked the BB_APPLET_<pid> environment
variable is set, but then it's cleared when the environment of the
child process is restored. Reinstate it in reinitvar.
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | libbb/appletlib.c | 14 | ||||
-rw-r--r-- | shell/ash.c | 7 |
3 files changed, 16 insertions, 6 deletions
diff --git a/include/libbb.h b/include/libbb.h index af234e7b0..da3459224 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -2075,6 +2075,7 @@ extern const char bb_path_wtmp_file[] ALIGN1; | |||
2075 | #define bb_dev_null "/dev/null" | 2075 | #define bb_dev_null "/dev/null" |
2076 | #if ENABLE_PLATFORM_MINGW32 | 2076 | #if ENABLE_PLATFORM_MINGW32 |
2077 | #define bb_busybox_exec_path get_busybox_exec_path() | 2077 | #define bb_busybox_exec_path get_busybox_exec_path() |
2078 | extern char *bb_applet_pid(void); | ||
2078 | #else | 2079 | #else |
2079 | extern const char bb_busybox_exec_path[] ALIGN1; | 2080 | extern const char bb_busybox_exec_path[] ALIGN1; |
2080 | #endif | 2081 | #endif |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 210f9ff4d..1488d4bd6 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -796,6 +796,13 @@ static void install_links(const char *busybox UNUSED_PARAM, | |||
796 | 796 | ||
797 | static void run_applet_and_exit(const char *name, char **argv) NORETURN; | 797 | static void run_applet_and_exit(const char *name, char **argv) NORETURN; |
798 | 798 | ||
799 | #if ENABLE_PLATFORM_MINGW32 | ||
800 | char *bb_applet_pid(void) | ||
801 | { | ||
802 | return auto_string(xasprintf("BB_APPLET_%d=%s", getpid(), applet_name)); | ||
803 | } | ||
804 | #endif | ||
805 | |||
799 | # if ENABLE_BUSYBOX | 806 | # if ENABLE_BUSYBOX |
800 | # if ENABLE_FEATURE_SH_STANDALONE && ENABLE_FEATURE_TAB_COMPLETION | 807 | # if ENABLE_FEATURE_SH_STANDALONE && ENABLE_FEATURE_TAB_COMPLETION |
801 | /* | 808 | /* |
@@ -1008,12 +1015,7 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar | |||
1008 | check_suid(applet_no); | 1015 | check_suid(applet_no); |
1009 | 1016 | ||
1010 | #if ENABLE_PLATFORM_MINGW32 | 1017 | #if ENABLE_PLATFORM_MINGW32 |
1011 | { | 1018 | putenv(bb_applet_pid()); |
1012 | char var[64]; | ||
1013 | |||
1014 | sprintf(var, "BB_APPLET_%d=%s", getpid(), applet_name); | ||
1015 | putenv(var); | ||
1016 | } | ||
1017 | #endif | 1019 | #endif |
1018 | 1020 | ||
1019 | xfunc_error_retval = applet_main[applet_no](argc, argv); | 1021 | xfunc_error_retval = applet_main[applet_no](argc, argv); |
diff --git a/shell/ash.c b/shell/ash.c index 6d24fb55a..2a1ddac39 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -14975,6 +14975,13 @@ reinitvar(void) | |||
14975 | varinit[i].var_func = varinit_data[i].var_func; | 14975 | varinit[i].var_func = varinit_data[i].var_func; |
14976 | } | 14976 | } |
14977 | vlineno.var_text = linenovar; | 14977 | vlineno.var_text = linenovar; |
14978 | |||
14979 | /* | ||
14980 | * BB_APPLET_<pid> was correct when 'sh --forkshell' was started | ||
14981 | * but has now been overwritten by the environment from the forkshell | ||
14982 | * data block. Reinstate it. | ||
14983 | */ | ||
14984 | setvareq(bb_applet_pid(), VEXPORT); | ||
14978 | } | 14985 | } |
14979 | 14986 | ||
14980 | /* FIXME: should consider running forkparent() and forkchild() */ | 14987 | /* FIXME: should consider running forkparent() and forkchild() */ |