aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-06-01 08:45:25 +0100
committerRon Yorston <rmy@pobox.com>2020-06-01 08:45:25 +0100
commit8fdbb0564ddaf0361dff8a194a0329f86738343c (patch)
tree3a59046490115195cc25f2c1a1c888eaae775c2d
parent3c5995713d91df7b6f803b34e43df188646b0676 (diff)
downloadbusybox-w32-8fdbb0564ddaf0361dff8a194a0329f86738343c.tar.gz
busybox-w32-8fdbb0564ddaf0361dff8a194a0329f86738343c.tar.bz2
busybox-w32-8fdbb0564ddaf0361dff8a194a0329f86738343c.zip
ash: don't initialise shell variables in forkshell child
The forkshell child process calls init(), which mostly just initialises shell variables. Since these variables are overwritten with values from the parent process there's no point in doing that. In particular, init() initialises HOSTNAME by calling gethostname() which involves network access and is slow. Avoid this cost when we know the shell is a forkshell child.
-rw-r--r--shell/ash.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 4a075d1ea..f57819810 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -14989,11 +14989,11 @@ static void xsetenv_if_unset(const char *key, const char *value)
14989static NOINLINE void 14989static NOINLINE void
14990init(void) 14990init(void)
14991{ 14991{
14992#if !ENABLE_PLATFORM_MINGW32
14992 /* we will never free this */ 14993 /* we will never free this */
14993 basepf.next_to_pgetc = basepf.buf = ckmalloc(IBUFSIZ); 14994 basepf.next_to_pgetc = basepf.buf = ckmalloc(IBUFSIZ);
14994 basepf.linno = 1; 14995 basepf.linno = 1;
14995 14996
14996#if !ENABLE_PLATFORM_MINGW32
14997 sigmode[SIGCHLD - 1] = S_DFL; /* ensure we install handler even if it is SIG_IGNed */ 14997 sigmode[SIGCHLD - 1] = S_DFL; /* ensure we install handler even if it is SIG_IGNed */
14998 setsignal(SIGCHLD); 14998 setsignal(SIGCHLD);
14999#endif 14999#endif
@@ -15254,6 +15254,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
15254 int login_sh; 15254 int login_sh;
15255#if ENABLE_PLATFORM_MINGW32 15255#if ENABLE_PLATFORM_MINGW32
15256 char *sd; 15256 char *sd;
15257 int is_forkshell;
15257#endif 15258#endif
15258 15259
15259 /* Initialize global data */ 15260 /* Initialize global data */
@@ -15302,7 +15303,13 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
15302 rootpid = getpid(); 15303 rootpid = getpid();
15303 15304
15304#if ENABLE_PLATFORM_MINGW32 15305#if ENABLE_PLATFORM_MINGW32
15306 /* we will never free this */
15307 basepf.next_to_pgetc = basepf.buf = ckmalloc(IBUFSIZ);
15308 basepf.linno = 1;
15309
15305 winxp = (argv[1] != NULL && strcmp(argv[1], "-X") == 0); 15310 winxp = (argv[1] != NULL && strcmp(argv[1], "-X") == 0);
15311 is_forkshell = (argc == 3 && !strcmp(argv[1], "--fs"));
15312 if (!is_forkshell)
15306#endif 15313#endif
15307 init(); 15314 init();
15308 setstackmark(&smark); 15315 setstackmark(&smark);
@@ -15311,7 +15318,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
15311 hSIGINT = CreateEvent(NULL, TRUE, FALSE, NULL); 15318 hSIGINT = CreateEvent(NULL, TRUE, FALSE, NULL);
15312 SetConsoleCtrlHandler(ctrl_handler, TRUE); 15319 SetConsoleCtrlHandler(ctrl_handler, TRUE);
15313 15320
15314 if (argc == 3 && !strcmp(argv[1], "--fs")) { 15321 if (is_forkshell) {
15315 forkshell_init(argv[2]); 15322 forkshell_init(argv[2]);
15316 15323
15317 /* only reached in case of error */ 15324 /* only reached in case of error */