init.c bug merging environment
Andreas Neuhaus
andy at fasta.fh-dortmund.de
Fri Mar 16 00:06:55 UTC 2001
Package: busybox
Version: cvs
Severity: normal
init.c tries to merge the existing environment (usually only TERM=linux when
booting a plain kernel) with the new settings (HOME,PATH,SHELL,USER). in
case you use linuxrc, there are already other environment settings added
(like PATH) which init.c isn't aware of. this results in a duplicate entry
for PATH in my case.
here's a patch for init.c that merges the two enviroments correctly. this
will create the child environment and only add settings that init don't
sets itself.
Index: init.c
===================================================================
RCS file: /var/cvs/busybox/init.c,v
retrieving revision 1.126
diff -u -r1.126 init.c
--- init.c 2001/03/15 21:04:18 1.126
+++ init.c 2001/03/16 00:05:53
@@ -396,10 +396,10 @@
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 *tmpCmd, *s;
char *cmd[255], *cmdpath;
char buf[255];
static const char press_enter[] =
@@ -410,18 +410,25 @@
"\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) {
regards,
andreas neuhaus
--
Life could be so much easier if we could just look at the source code...
.~.
/V\ Andreas Neuhaus, FaStA Informatik FH-Dortmund
// \\ Sonnenstr. 96, D-44139 Dortmund, Tel 0231/9112-734
/( )\ System-Administration FaStA FH-Dortmund
^^-^^
LINUX - Don't fear the penguin
---------------------------------------
Received: (at 1135-done) by bugs.lineo.com; 3 Apr 2001 17:11:20 +0000
More information about the busybox
mailing list