summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen2001-03-16 01:14:04 +0000
committerEric Andersen2001-03-16 01:14:04 +0000
commit7f1978570fb8f27c05d7b0cf2a964ded5db41ee7 (patch)
tree7995a486b9aacb1afd7cc86004c5cd1f94881955
parent4aaefc2a50600f2b2247ec2d607c19896e9cc0df (diff)
downloadbusybox-7f1978570fb8f27c05d7b0cf2a964ded5db41ee7.zip
busybox-7f1978570fb8f27c05d7b0cf2a964ded5db41ee7.tar.gz
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 64c7768..145452f 100644
--- a/init.c
+++ b/init.c
@@ -396,11 +396,11 @@ static void console_init()
static pid_t run(char *command, char *terminal, int get_enter)
{
- int i=0, j=0;
+ int i, j;
int fd;
pid_t pid;
- char *tmpCmd;
- char *cmd[255], *cmdpath;
+ char *tmpCmd, *s;
+ char *cmd[255], *cmdpath;
char buf[255];
static const char press_enter[] =
@@ -410,18 +410,25 @@ static pid_t run(char *command, char *terminal, int get_enter)
"\nPlease press Enter to activate this console. ";
char *environment[MAXENV+1] = {
+ termType,
"HOME=/",
"PATH=/usr/bin:/bin:/usr/sbin:/sbin",
"SHELL=/bin/sh",
- termType,
- "USER=root"
+ "USER=root",
+ NULL
};
- while (environment[i]) i++;
- while ((environ[j]) && (i < MAXENV)) {
- if (strncmp(environ[j], "TERM=", 5))
- environment[i++] = environ[j];
- j++;
+ /* inherit environment to the child, merging our values -andy */
+ for (i=0; environ[i]; i++) {
+ for (j=0; environment[j]; j++) {
+ s = strchr(environment[j], '=');
+ if (!strncmp(environ[i], environment[j], s - environment[j]))
+ break;
+ }
+ if (!environment[j]) {
+ environment[j++] = environ[i];
+ environment[j] = NULL;
+ }
}
if ((pid = fork()) == 0) {
diff --git a/init/init.c b/init/init.c
index 64c7768..145452f 100644
--- a/init/init.c
+++ b/init/init.c
@@ -396,11 +396,11 @@ static void console_init()
static pid_t run(char *command, char *terminal, int get_enter)
{
- int i=0, j=0;
+ int i, j;
int fd;
pid_t pid;
- char *tmpCmd;
- char *cmd[255], *cmdpath;
+ char *tmpCmd, *s;
+ char *cmd[255], *cmdpath;
char buf[255];
static const char press_enter[] =
@@ -410,18 +410,25 @@ static pid_t run(char *command, char *terminal, int get_enter)
"\nPlease press Enter to activate this console. ";
char *environment[MAXENV+1] = {
+ termType,
"HOME=/",
"PATH=/usr/bin:/bin:/usr/sbin:/sbin",
"SHELL=/bin/sh",
- termType,
- "USER=root"
+ "USER=root",
+ NULL
};
- while (environment[i]) i++;
- while ((environ[j]) && (i < MAXENV)) {
- if (strncmp(environ[j], "TERM=", 5))
- environment[i++] = environ[j];
- j++;
+ /* inherit environment to the child, merging our values -andy */
+ for (i=0; environ[i]; i++) {
+ for (j=0; environment[j]; j++) {
+ s = strchr(environment[j], '=');
+ if (!strncmp(environ[i], environment[j], s - environment[j]))
+ break;
+ }
+ if (!environment[j]) {
+ environment[j++] = environ[i];
+ environment[j] = NULL;
+ }
}
if ((pid = fork()) == 0) {