aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-03-16 01:14:04 +0000
committerEric Andersen <andersen@codepoet.org>2001-03-16 01:14:04 +0000
commit7f1978570fb8f27c05d7b0cf2a964ded5db41ee7 (patch)
tree7995a486b9aacb1afd7cc86004c5cd1f94881955
parent4aaefc2a50600f2b2247ec2d607c19896e9cc0df (diff)
downloadbusybox-w32-7f1978570fb8f27c05d7b0cf2a964ded5db41ee7.tar.gz
busybox-w32-7f1978570fb8f27c05d7b0cf2a964ded5db41ee7.tar.bz2
busybox-w32-7f1978570fb8f27c05d7b0cf2a964ded5db41ee7.zip
A patch from Andreas Neuhaus to be especially careful to not dup
any env variables when spawning child processes.
-rw-r--r--init.c27
-rw-r--r--init/init.c27
2 files changed, 34 insertions, 20 deletions
diff --git a/init.c b/init.c
index 64c7768d6..145452ff3 100644
--- a/init.c
+++ b/init.c
@@ -396,11 +396,11 @@ static void console_init()
396 396
397static pid_t run(char *command, char *terminal, int get_enter) 397static pid_t run(char *command, char *terminal, int get_enter)
398{ 398{
399 int i=0, j=0; 399 int i, j;
400 int fd; 400 int fd;
401 pid_t pid; 401 pid_t pid;
402 char *tmpCmd; 402 char *tmpCmd, *s;
403 char *cmd[255], *cmdpath; 403 char *cmd[255], *cmdpath;
404 char buf[255]; 404 char buf[255];
405 static const char press_enter[] = 405 static const char press_enter[] =
406 406
@@ -410,18 +410,25 @@ static pid_t run(char *command, char *terminal, int get_enter)
410 410
411 "\nPlease press Enter to activate this console. "; 411 "\nPlease press Enter to activate this console. ";
412 char *environment[MAXENV+1] = { 412 char *environment[MAXENV+1] = {
413 termType,
413 "HOME=/", 414 "HOME=/",
414 "PATH=/usr/bin:/bin:/usr/sbin:/sbin", 415 "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
415 "SHELL=/bin/sh", 416 "SHELL=/bin/sh",
416 termType, 417 "USER=root",
417 "USER=root" 418 NULL
418 }; 419 };
419 420
420 while (environment[i]) i++; 421 /* inherit environment to the child, merging our values -andy */
421 while ((environ[j]) && (i < MAXENV)) { 422 for (i=0; environ[i]; i++) {
422 if (strncmp(environ[j], "TERM=", 5)) 423 for (j=0; environment[j]; j++) {
423 environment[i++] = environ[j]; 424 s = strchr(environment[j], '=');
424 j++; 425 if (!strncmp(environ[i], environment[j], s - environment[j]))
426 break;
427 }
428 if (!environment[j]) {
429 environment[j++] = environ[i];
430 environment[j] = NULL;
431 }
425 } 432 }
426 433
427 if ((pid = fork()) == 0) { 434 if ((pid = fork()) == 0) {
diff --git a/init/init.c b/init/init.c
index 64c7768d6..145452ff3 100644
--- a/init/init.c
+++ b/init/init.c
@@ -396,11 +396,11 @@ static void console_init()
396 396
397static pid_t run(char *command, char *terminal, int get_enter) 397static pid_t run(char *command, char *terminal, int get_enter)
398{ 398{
399 int i=0, j=0; 399 int i, j;
400 int fd; 400 int fd;
401 pid_t pid; 401 pid_t pid;
402 char *tmpCmd; 402 char *tmpCmd, *s;
403 char *cmd[255], *cmdpath; 403 char *cmd[255], *cmdpath;
404 char buf[255]; 404 char buf[255];
405 static const char press_enter[] = 405 static const char press_enter[] =
406 406
@@ -410,18 +410,25 @@ static pid_t run(char *command, char *terminal, int get_enter)
410 410
411 "\nPlease press Enter to activate this console. "; 411 "\nPlease press Enter to activate this console. ";
412 char *environment[MAXENV+1] = { 412 char *environment[MAXENV+1] = {
413 termType,
413 "HOME=/", 414 "HOME=/",
414 "PATH=/usr/bin:/bin:/usr/sbin:/sbin", 415 "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
415 "SHELL=/bin/sh", 416 "SHELL=/bin/sh",
416 termType, 417 "USER=root",
417 "USER=root" 418 NULL
418 }; 419 };
419 420
420 while (environment[i]) i++; 421 /* inherit environment to the child, merging our values -andy */
421 while ((environ[j]) && (i < MAXENV)) { 422 for (i=0; environ[i]; i++) {
422 if (strncmp(environ[j], "TERM=", 5)) 423 for (j=0; environment[j]; j++) {
423 environment[i++] = environ[j]; 424 s = strchr(environment[j], '=');
424 j++; 425 if (!strncmp(environ[i], environment[j], s - environment[j]))
426 break;
427 }
428 if (!environment[j]) {
429 environment[j++] = environ[i];
430 environment[j] = NULL;
431 }
425 } 432 }
426 433
427 if ((pid = fork()) == 0) { 434 if ((pid = fork()) == 0) {