ash: rename redir5.tests (hush has redir5.tests which is different)
[oweals/busybox.git] / init / halt.c
index ad12d914896c7ebe35053f178d2b8ced29d85449..f69b897723a83d08562acc563cd28ccb2f275e5f 100644 (file)
@@ -7,22 +7,28 @@
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
 
-//applet:IF_HALT(APPLET(halt, BB_DIR_SBIN, BB_SUID_DROP))
-//applet:IF_HALT(APPLET_ODDNAME(poweroff, halt, BB_DIR_SBIN, BB_SUID_DROP, poweroff))
-//applet:IF_HALT(APPLET_ODDNAME(reboot, halt, BB_DIR_SBIN, BB_SUID_DROP, reboot))
-
-//kbuild:lib-$(CONFIG_HALT) += halt.o
-
 //config:config HALT
-//config:      bool "poweroff, halt, and reboot"
+//config:      bool "halt"
+//config:      default y
+//config:      help
+//config:        Stop all processes and halt the system.
+//config:
+//config:config POWEROFF
+//config:      bool "poweroff"
 //config:      default y
 //config:      help
-//config:        Stop all processes and either halt, reboot, or power off the system.
+//config:        Stop all processes and power off the system.
+//config:
+//config:config REBOOT
+//config:      bool "reboot"
+//config:      default y
+//config:      help
+//config:        Stop all processes and reboot the system.
 //config:
 //config:config FEATURE_CALL_TELINIT
 //config:      bool "Call telinit on shutdown and reboot"
 //config:      default y
-//config:      depends on HALT && !INIT
+//config:      depends on (HALT || POWEROFF || REBOOT) && !INIT
 //config:      help
 //config:        Call an external program (normally telinit) to facilitate
 //config:        a switch to a proper runlevel.
 //config:        to facilitate proper shutdown, this path is to be used when
 //config:        locating telinit executable.
 
+//applet:IF_HALT(APPLET(halt, BB_DIR_SBIN, BB_SUID_DROP))
+//                   APPLET_ODDNAME:name      main  location     suid_type     help
+//applet:IF_POWEROFF(APPLET_ODDNAME(poweroff, halt, BB_DIR_SBIN, BB_SUID_DROP, poweroff))
+//applet:IF_REBOOT(  APPLET_ODDNAME(reboot,   halt, BB_DIR_SBIN, BB_SUID_DROP, reboot))
+
+//kbuild:lib-$(CONFIG_HALT) += halt.o
+//kbuild:lib-$(CONFIG_POWEROFF) += halt.o
+//kbuild:lib-$(CONFIG_REBOOT) += halt.o
+
 //usage:#define halt_trivial_usage
 //usage:       "[-d DELAY] [-n] [-f]" IF_FEATURE_WTMP(" [-w]")
 //usage:#define halt_full_usage "\n\n"
@@ -109,16 +124,24 @@ int halt_main(int argc UNUSED_PARAM, char **argv)
        int which, flags, rc;
 
        /* Figure out which applet we're running */
+       if (ENABLE_HALT && !ENABLE_POWEROFF && !ENABLE_REBOOT)
+               which = 0;
+       else
+       if (!ENABLE_HALT && ENABLE_POWEROFF && !ENABLE_REBOOT)
+               which = 1;
+       else
+       if (!ENABLE_HALT && !ENABLE_POWEROFF && ENABLE_REBOOT)
+               which = 2;
+       else
        for (which = 0; "hpr"[which] != applet_name[0]; which++)
                continue;
 
        /* Parse and handle arguments */
-       opt_complementary = "d+"; /* -d N */
        /* We support -w even if !ENABLE_FEATURE_WTMP,
         * in order to not break scripts.
         * -i (shut down network interfaces) is ignored.
         */
-       flags = getopt32(argv, "d:nfwi", &delay);
+       flags = getopt32(argv, "d:+nfwi", &delay);
 
        sleep(delay);
 
@@ -135,7 +158,7 @@ int halt_main(int argc UNUSED_PARAM, char **argv)
        if (!(flags & 4)) { /* no -f */
 //TODO: I tend to think that signalling linuxrc is wrong
 // pity original author didn't comment on it...
-               if (ENABLE_FEATURE_INITRD) {
+               if (ENABLE_LINUXRC) {
                        /* talk to linuxrc */
                        /* bbox init/linuxrc assumed */
                        pid_t *pidlist = find_pid_by_name("linuxrc");