Latest and greatest
[oweals/busybox.git] / init / init.c
index e70d5a15d01583d4337c6dcfd1af17c9e16aa609..f6e9eff971d1d6f4e0713401c88962dc4402b95b 100644 (file)
@@ -41,7 +41,7 @@
 #include <sys/vt.h>            /* for vt_stat */
 #include <sys/ioctl.h>
 
-#define VT_CONSOLE      "/dev/console" /* Logical system console */
+#define DEV_CONSOLE      "/dev/console"        /* Logical system console */
 #define VT_PRIMARY      "/dev/tty1"    /* Primary virtual console */
 #define VT_SECONDARY    "/dev/tty2"    /* Virtual console */
 #define VT_LOG          "/dev/tty3"    /* Virtual console */
@@ -53,7 +53,7 @@
 
 #define LOG             0x1
 #define CONSOLE         0x2
-static char *console = VT_CONSOLE;
+static char *console = DEV_CONSOLE;
 static char *second_console = VT_SECONDARY;
 static char *log = VT_LOG;
 static int kernel_version = 0;
@@ -109,7 +109,8 @@ void message(int device, char *fmt, ...)
        va_end(arguments);
     }
     if (device & CONSOLE) {
-       if ((fd = device_open(console, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
+       /* Always send console messages to /dev/console so people will see them. */
+       if ((fd = device_open(DEV_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
            va_start(arguments, fmt);
            vdprintf(fd, fmt, arguments);
            va_end(arguments);
@@ -217,7 +218,7 @@ static void console_init()
            /* this is linux virtual tty */
            snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
        } else {
-           console = VT_CONSOLE;
+           console = DEV_CONSOLE;
            tried_devcons++;
        }
     }
@@ -226,7 +227,7 @@ static void console_init()
        /* Can't open selected console -- try /dev/console */
        if (!tried_devcons) {
            tried_devcons++;
-           console = VT_CONSOLE;
+           console = DEV_CONSOLE;
            continue;
        }
        /* Can't open selected console -- try vt1 */
@@ -417,10 +418,14 @@ extern int init_main(int argc, char **argv)
     pid_t pid1 = 0;
     pid_t pid2 = 0;
     struct stat statbuf;
-    const char* const init_commands[] = { INITSCRIPT, INITSCRIPT, 0};
-    const char* const shell_commands[] = { SHELL, "-" SHELL, 0};
-    const char* const* tty0_commands = shell_commands;
-    const char* const* tty1_commands = shell_commands;
+    const char* const rc_script_command[] = { INITSCRIPT, INITSCRIPT, 0};
+    const char* const shell_command[] = { SHELL, "-" SHELL, 0};
+    const char* const* tty0_command = shell_command;
+    const char* const* tty1_command = shell_command;
+#ifdef BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS
+    const char* const rc_exit_command[] = BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS;
+#endif
+
 #ifdef DEBUG_INIT
     char *hello_msg_format =
        "init(%d) started:  BusyBox v%s (%s) multi-call binary\r\n";
@@ -493,7 +498,7 @@ extern int init_main(int argc, char **argv)
     /* Make sure an init script exists before trying to run it */
     if (run_rc == TRUE && stat(INITSCRIPT, &statbuf)==0) {
        wait_for_enter = FALSE;
-       tty0_commands = init_commands;
+       tty0_command = rc_script_command;
     }
 
 
@@ -504,11 +509,11 @@ extern int init_main(int argc, char **argv)
        pid_t wpid;
        int status;
 
-       if (pid1 == 0 && tty0_commands) {
-           pid1 = run(tty0_commands, console, wait_for_enter);
+       if (pid1 == 0 && tty0_command) {
+           pid1 = run(tty0_command, console, wait_for_enter);
        }
-       if (pid2 == 0 && tty1_commands && second_console) {
-           pid2 = run(tty1_commands, second_console, TRUE);
+       if (pid2 == 0 && tty1_command && second_console) {
+           pid2 = run(tty1_command, second_console, TRUE);
        }
        wpid = wait(&status);
        if (wpid > 0 ) {
@@ -518,13 +523,13 @@ extern int init_main(int argc, char **argv)
        if (wpid == pid1) {
            if (run_rc == FALSE) {
                pid1 = 0;
-           } 
-#if 0
-/* Turn this on to start a shell on the console if the init script exits.... */
+           }
+#ifdef BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS
            else {
+               pid1 = 0;
                run_rc=FALSE;
                wait_for_enter=TRUE;
-               tty0_commands=shell_commands;
+               tty0_command=rc_exit_command;
            }
 #endif
        }