[BusyBox] [PATCH] init.c include initial environment

Erik Gustavsson cyrano at algonet.se
Tue Feb 13 20:31:12 UTC 2001


Hi list!

As my previous post went unanswered I had a look at the source for BB's
init and found the source of my problems, I've made this simple patch to
solve it. 

There is probably some good reason why the environment is discarded before
running init scripts, and there is probably a better way to do this but
I'm posting the patch anyway in case someone needs it. (I can't be the
only person in the world who needs to pass paramters from lilo to my init
scripts?)

/cyr
-------------- next part --------------
--- /tmp/busybox-0.49/init.c	Sat Jan 27 08:23:00 2001
+++ init.c	Tue Feb 13 21:14:08 2001
@@ -134,6 +134,8 @@
 #define INIT_SCRIPT  "/etc/init.d/rcS"   /* Default sysinit script. */
 #endif
 
+#define MAXENV       64              /* Number of env. vars */
+
 static const int LOG = 0x1;
 static const int CONSOLE = 0x2;
 
@@ -396,7 +398,8 @@
 
 static pid_t run(char *command, char *terminal, int get_enter)
 {
-	int i, fd;
+	int i=0, j=0;
+	int fd;
 	pid_t pid;
 	char *tmpCmd;
         char *cmd[255], *cmdpath;
@@ -408,14 +411,18 @@
 #endif
 
 		"\nPlease press Enter to activate this console. ";
-	char *environment[] = {
+	char *environment[MAXENV+1] = {
 		"HOME=/",
 		"PATH=/usr/bin:/bin:/usr/sbin:/sbin",
 		"SHELL=/bin/sh",
-		termType,
-		"USER=root",
-		0
+		"USER=root"
 	};
+
+	while(environment[i+1]) i++;
+	while(environ[++j] && (i++ < MAXENV)) {
+		environment[i]=malloc(strlen(environ[j])+1);
+		strcpy(environment[i],environ[j]);
+	}
 
 	if ((pid = fork()) == 0) {
 		/* Clean up */


More information about the busybox mailing list