Update applet define from BB_CP_MV to BB_CP and BB_MV.
[oweals/busybox.git] / init.c
diff --git a/init.c b/init.c
index b775893850f54a39ef5c5a119b3a3b5cc3d65be1..d65220cdd97df72ba4c5649c853b7377a578f705 100644 (file)
--- a/init.c
+++ b/init.c
@@ -85,13 +85,14 @@ static const int RB_ENABLE_CAD = 0x89abcdef;
 static const int RB_DISABLE_CAD = 0;
 #define RB_POWER_OFF    0x4321fedc
 static const int RB_AUTOBOOT = 0x01234567;
-#if defined(__GLIBC__) || defined (__UCLIBC__)
-#include <sys/reboot.h>
+#endif
+
+#if __GNU_LIBRARY__ > 5
+  #include <sys/reboot.h>
   #define init_reboot(magic) reboot(magic)
 #else
   #define init_reboot(magic) reboot(0xfee1dead, 672274793, magic)
 #endif
-#endif
 
 #ifndef _PATH_STDPATH
 #define _PATH_STDPATH  "/usr/bin:/bin:/usr/sbin:/sbin"
@@ -112,13 +113,11 @@ static const int RB_AUTOBOOT = 0x01234567;
 
 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
 
-#if defined(__GLIBC__)
-#include <sys/kdaemon.h>
+#if __GNU_LIBRARY__ > 5
+       #include <sys/kdaemon.h>
 #else
-#include <sys/syscall.h>
-#include <linux/unistd.h>
-static _syscall2(int, bdflush, int, func, int, data);
-#endif                                                 /* __GLIBC__ */
+       extern int bdflush (int func, long int data);
+#endif
 
 
 #define VT_PRIMARY   "/dev/tty1"     /* Primary virtual console */
@@ -146,7 +145,8 @@ typedef enum {
        ASKFIRST,
        WAIT,
        ONCE,
-       CTRLALTDEL
+       CTRLALTDEL,
+       SHUTDOWN
 } initActionEnum;
 
 /* A mapping between "inittab" action name strings and action type codes. */
@@ -162,6 +162,7 @@ static const struct initActionType actions[] = {
        {"wait", WAIT},
        {"once", ONCE},
        {"ctrlaltdel", CTRLALTDEL},
+       {"shutdown", SHUTDOWN},
        {0, 0}
 };
 
@@ -277,7 +278,8 @@ static void set_term(int fd)
 
        /* Make it be sane */
        tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
-       tty.c_cflag |= HUPCL|CLOCAL;
+       tty.c_cflag |= CREAD|HUPCL|CLOCAL;
+
 
        /* input modes */
        tty.c_iflag = ICRNL | IXON | IXOFF;
@@ -512,7 +514,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
                 */
 
                if (*cmdpath == '-') {
-                       char *s;
 
                        /* skip over the dash */
                        ++cmdpath;
@@ -618,12 +619,12 @@ static void check_memory()
 }
 
 /* Run all commands to be run right before halt/reboot */
-static void run_lastAction(void)
+static void run_actions(initActionEnum action)
 {
        initAction *a, *tmp;
        for (a = initActionList; a; a = tmp) {
                tmp = a->nextPtr;
-               if (a->action == CTRLALTDEL) {
+               if (a->action == action) {
                        waitfor(a->process, a->console, FALSE);
                        delete_initAction(a);
                }
@@ -654,8 +655,8 @@ static void shutdown_system(void)
        kill(-1, SIGKILL);
        sleep(1);
 
-       /* run everything to be run at "ctrlaltdel" */
-       run_lastAction();
+       /* run everything to be run at "shutdown" */
+       run_actions(SHUTDOWN);
 
        sync();
        if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
@@ -697,6 +698,11 @@ static void reboot_signal(int sig)
        exit(0);
 }
 
+static void ctrlaltdel_signal(int sig)
+{
+       run_actions(CTRLALTDEL);
+}
+
 #endif                                                 /* ! DEBUG_INIT */
 
 static void new_initAction(initActionEnum action, char *process, char *cons)
@@ -768,10 +774,12 @@ static void parse_inittab(void)
        if (file == NULL) {
                /* No inittab file -- set up some default behavior */
 #endif
+               /* Reboot on Ctrl-Alt-Del */
+               new_initAction(CTRLALTDEL, "/sbin/reboot", console);
                /* Swapoff on halt/reboot */
-               new_initAction(CTRLALTDEL, "/sbin/swapoff -a", console);
+               new_initAction(SHUTDOWN, "/sbin/swapoff -a", console);
                /* Umount all filesystems on halt/reboot */
-               new_initAction(CTRLALTDEL, "/bin/umount -a -r", console);
+               new_initAction(SHUTDOWN, "/bin/umount -a -r", console);
                /* Askfirst shell on tty1 */
                new_initAction(ASKFIRST, SHELL, console);
                /* Askfirst shell on tty2 */
@@ -884,7 +892,7 @@ extern int init_main(int argc, char **argv)
         * clear all of these in run() */
        signal(SIGUSR1, halt_signal);
        signal(SIGUSR2, halt_signal);
-       signal(SIGINT, reboot_signal);
+       signal(SIGINT, ctrlaltdel_signal);
        signal(SIGTERM, reboot_signal);
 
        /* Turn off rebooting via CTL-ALT-DEL -- we get a