Add in kent robotti's updated dos2unix.c
[oweals/busybox.git] / init.c
diff --git a/init.c b/init.c
index 9046a14a8e53c5ef6f01289d04d50a5efaa6b519..4284600c415b9c08c555f73a5eedcdda16494130 100644 (file)
--- a/init.c
+++ b/init.c
@@ -27,7 +27,6 @@
 #define DEBUG_INIT
 */
 
-#include "busybox.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include "busybox.h"
+#define bb_need_full_version
+#define BB_DECLARE_EXTERN
+#include "messages.c"
 #ifdef BB_SYSLOGD
 # include <sys/syslog.h>
 #endif
 
-#define bb_need_full_version
-#define BB_DECLARE_EXTERN
-#include "messages.c"
 
 /* From <linux/vt.h> */
 struct vt_stat {
@@ -93,9 +93,8 @@ static const int RB_AUTOBOOT = 0x01234567;
 #endif
 #endif
 
-#ifndef _PATH_STDPATH
+#undef _PATH_STDPATH
 #define _PATH_STDPATH  "/usr/bin:/bin:/usr/sbin:/sbin"
-#endif
 
 
 #if defined BB_FEATURE_INIT_COREDUMPS
@@ -134,6 +133,7 @@ static _syscall2(int, bdflush, int, func, int, data);
 #define INIT_SCRIPT  "/etc/init.d/rcS"   /* Default sysinit script. */
 #endif
 
+static const int MAXENV = 16;  /* Number of env. vars */
 static const int LOG = 0x1;
 static const int CONSOLE = 0x2;
 
@@ -394,7 +394,8 @@ static void console_init()
 
 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;
@@ -406,15 +407,21 @@ static pid_t run(char *command, char *terminal, int get_enter)
 #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]) i++;
+       while ((environ[j]) && (i < MAXENV)) {
+               if (strncmp(environ[j], "TERM=", 5))
+                       environment[i++] = environ[j];
+               j++;
+       }
+
        if ((pid = fork()) == 0) {
                /* Clean up */
                ioctl(0, TIOCNOTTY, 0);
@@ -451,9 +458,8 @@ static pid_t run(char *command, char *terminal, int get_enter)
                         * specifies.
                         */
 #ifdef DEBUG_INIT
-                       pid_t shell_pgid = getpid();
                        message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
-                                       command, shell_pgid, terminal);
+                                       command, getpid(), terminal);
 #endif
                        write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
                        getc(stdin);
@@ -462,7 +468,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
 #ifdef DEBUG_INIT
                /* Log the process name and args */
                message(LOG, "Starting pid %d, console %s: '%s'\r\n",
-                               shell_pgid, terminal, command);
+                               getpid(), terminal, command);
 #endif
 
                /* See if any special /bin/sh requiring characters are present */