Announce 1.2.1
[oweals/busybox.git] / init / init.c
index b3d1f6d365bc4d1c1c24d5758a32c86d3b50d261..cad64f63ae25f185e5d4a1bf51d515d844ea923c 100644 (file)
  */
 
 #include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
 #include <errno.h>
 #include <paths.h>
 #include <signal.h>
-#include <stdarg.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include <limits.h>
-#include <fcntl.h>
 #include <sys/ioctl.h>
-#include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/reboot.h>
 
 #include "init_shared.h"
 
-
 #ifdef CONFIG_SYSLOGD
 # include <sys/syslog.h>
 #endif
 
-
-#ifdef CONFIG_SELINUX
-# include <selinux/selinux.h>
-#endif /* CONFIG_SELINUX */
-
-
 #define INIT_BUFFS_SIZE 256
 
 /* From <linux/vt.h> */
@@ -72,7 +56,6 @@ struct serial_struct {
        int     reserved[1];
 };
 
-
 #ifndef _PATH_STDPATH
 #define _PATH_STDPATH  "/usr/bin:/bin:/usr/sbin:/sbin"
 #endif
@@ -88,8 +71,6 @@ struct serial_struct {
 #include <sys/resource.h>
 #endif
 
-#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
-
 #define INITTAB      "/etc/inittab"    /* inittab file location */
 #ifndef INIT_SCRIPT
 #define INIT_SCRIPT  "/etc/init.d/rcS" /* Default sysinit script. */
@@ -240,7 +221,7 @@ static void message(int device, const char *fmt, ...)
                }
        }
        if ((device & LOG) && (log_fd >= 0)) {
-               bb_full_write(log_fd, msg, l);
+               full_write(log_fd, msg, l);
        }
 #endif
 
@@ -249,7 +230,7 @@ static void message(int device, const char *fmt, ...)
                                        O_WRONLY | O_NOCTTY | O_NONBLOCK);
                /* Always send console messages to /dev/console so people will see them. */
                if (fd >= 0) {
-                       bb_full_write(fd, msg, l);
+                       full_write(fd, msg, l);
                        close(fd);
 #if ENABLE_DEBUG_INIT
                /* all descriptors may be closed */
@@ -312,15 +293,6 @@ static void console_init(void)
 
        if ((s = getenv("CONSOLE")) != NULL || (s = getenv("console")) != NULL) {
                safe_strncpy(console, s, sizeof(console));
-#if 0 /* #cpu(sparc) */
-       /* sparc kernel supports console=tty[ab] parameter which is also
-        * passed to init, so catch it here */
-               /* remap tty[ab] to /dev/ttyS[01] */
-               if (strcmp(s, "ttya") == 0)
-                       safe_strncpy(console, SC_0, sizeof(console));
-               else if (strcmp(s, "ttyb") == 0)
-                       safe_strncpy(console, SC_1, sizeof(console));
-#endif
        } else {
                /* 2.2 kernels: identify the real console backend and try to use it */
                if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
@@ -564,7 +536,7 @@ static pid_t run(const struct init_action *a)
                        messageD(LOG, "Waiting for enter to start '%s'"
                                                "(pid %d, terminal %s)\n",
                                          cmdpath, getpid(), a->terminal);
-                       bb_full_write(1, press_enter, sizeof(press_enter) - 1);
+                       full_write(1, press_enter, sizeof(press_enter) - 1);
                        while(read(0, &c, 1) == 1 && c != '\n')
                                ;
                }
@@ -842,9 +814,6 @@ static void new_init_action(int action, const char *command, const char *cons)
        strcpy(new_action->command, command);
        new_action->action = action;
        strcpy(new_action->terminal, cons);
-#if 0   /* calloc zeroed always */
-       new_action->pid = 0;
-#endif
        messageD(LOG|CONSOLE, "command='%s' action='%d' terminal='%s'\n",
                new_action->command, new_action->action, new_action->terminal);
 }
@@ -1058,6 +1027,9 @@ int init_main(int argc, char **argv)
                for(e = environment; *e; e++)
                        putenv((char *) *e);
        }
+
+       if (argc > 1) setenv("RUNLEVEL", argv[1], 1);
+
        /* Hello world */
        message(MAYBE_CONSOLE | LOG, "init started:  %s", bb_msg_full_version);