A patch from Matt Kraai that adds a new 'shutdown' action to busybox init. Now
authorEric Andersen <andersen@codepoet.org>
Tue, 3 Apr 2001 18:01:51 +0000 (18:01 -0000)
committerEric Andersen <andersen@codepoet.org>
Tue, 3 Apr 2001 18:01:51 +0000 (18:01 -0000)
you can specify an arbitrary behavior for 'ctrlaltdel' without that behavior
needing to be a reboot.

Changelog
applets/usage.h
docs/busybox.pod
include/usage.h
init.c
init/init.c
init/reboot.c
reboot.c
usage.h

index 19acbbd5cb0d93988646e7a35c2f78e2cef11d97..42dcfecae19cc262f4709dc0b768547407960e39 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,7 +1,12 @@
 0.51pre
        * Erik Andersen -- added env applet
        * Erik Andersen -- Split utility.c into libbb
-       * <fixme>
+       * Andreas Neuhaus <andy@fasta.fh-dortmund.de> -- fix for merging
+           kernel command line environment variables into child environment
+           for init.c
+       * Matt Kraai -- Added a new 'shutdown' action to busybox init.  Now
+           you can specify arbitrary behavior for 'ctrlaltdel' without that
+           behavior needing to be a reboot.
 
 
         -Erik Andersen, not yet released
index 1ee2ab3284f950fa598bca2a3ce56912b1b4c777..aa7f0af22792cac176bb11d285ecbaf9d671aae9 100644 (file)
 "\n" \
 "      ::sysinit:/etc/init.d/rcS\n" \
 "      ::askfirst:/bin/sh\n" \
+"      ::ctrlaltdel:/sbin/reboot\n" \
+"      ::shutdown:/sbin/swapoff -a\n" \
+"      ::shutdown:/bin/umount -a -r\n" \
 "\n" \
 "if it detects that /dev/console is _not_ a serial console, it will also run:\n" \
 "\n" \
 "      tty2::askfirst:/bin/sh\n" \
+"      tty3::askfirst:/bin/sh\n" \
+"      tty4::askfirst:/bin/sh\n" \
 "\n" \
 "If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n" \
 "\n" \
 "      <action>: \n" \
 "\n" \
 "              Valid actions include: sysinit, respawn, askfirst, wait, \n" \
-"              once, and ctrlaltdel.\n" \
+"              once, ctrlaltdel, and shutdown.\n" \
 "\n" \
 "              The available actions can be classified into two groups: actions\n" \
 "              that are run only once, and actions that are re-run when the specified\n" \
 "                      'wait' actions, like  'sysinit' actions, cause init to wait until\n" \
 "                      the specified task completes.  'once' actions are asyncronous,\n" \
 "                      therefore, init does not wait for them to complete.  'ctrlaltdel'\n" \
-"                      actions are run immediately before init causes the system to reboot\n" \
-"                      (unmounting filesystems with a 'ctrlaltdel' action is a very good\n" \
-"                      idea).\n" \
+"                      actions are run when the system detects that someone on the system\n" \
+"                       console has pressed the CTRL-ALT-DEL key combination.  Typically one\n" \
+"                       wants to run 'reboot' at this point to cause the system to reboot.\n" \
+"                      Finally the 'shutdown' action specifies the actions to taken when\n" \
+"                       init is told to reboot.  Unmounting filesystems and disabling swap\n" \
+"                       is a very good here\n" \
 "\n" \
 "              Run repeatedly actions:\n" \
 "\n" \
 "      #::respawn:/sbin/getty 57600 ttyS2\n" \
 "      \n" \
 "      # Stuff to do before rebooting\n" \
-"      ::ctrlaltdel:/bin/umount -a -r\n" \
-"      ::ctrlaltdel:/sbin/swapoff -a\n"
+"      ::ctrlaltdel:/sbin/reboot\n" \
+"      ::shutdown:/bin/umount -a -r\n" \
+"      ::shutdown:/sbin/swapoff -a\n"
 
 #define insmod_trivial_usage \
        "[OPTION]... MODULE [symbol=value]..."
index 644abc359257a36af36a3f9b466d18127765db79..42944489af4ed31975bc3b6c0e2a197afab1dac3 100644 (file)
@@ -906,10 +906,15 @@ it has the following default behavior:
 
        ::sysinit:/etc/init.d/rcS
        ::askfirst:/bin/sh
+       ::ctrlaltdel:/sbin/reboot
+       ::shutdown:/sbin/swapoff -a
+       ::shutdown:/bin/umount -a -r
 
 if it detects that /dev/console is _not_ a serial console, it will also run:
 
        tty2::askfirst:/bin/sh
+       tty3::askfirst:/bin/sh
+       tty4::askfirst:/bin/sh
 
 If you choose to use an /etc/inittab file, the inittab entry format is as follows:
 
@@ -935,7 +940,7 @@ If you choose to use an /etc/inittab file, the inittab entry format is as follow
        <action>: 
 
                Valid actions include: sysinit, respawn, askfirst, wait, 
-               once, and ctrlaltdel.
+               once, ctrlaltdel, and shutdown.
 
                The available actions can be classified into two groups: actions
                that are run only once, and actions that are re-run when the specified
@@ -949,9 +954,12 @@ If you choose to use an /etc/inittab file, the inittab entry format is as follow
                        'wait' actions, like  'sysinit' actions, cause init to wait until
                        the specified task completes.  'once' actions are asyncronous,
                        therefore, init does not wait for them to complete.  'ctrlaltdel'
-                       actions are run immediately before init causes the system to reboot
-                       (unmounting filesystems with a 'ctrlaltdel' action is a very good
-                       idea).
+                       actions are run when the system detects that someone on the system
+            console has pressed the CTRL-ALT-DEL key combination.  Typically one
+            wants to run 'reboot' at this point to cause the system to reboot.
+                       Finally the 'shutdown' action specifies the actions to taken when
+            init is told to reboot.  Unmounting filesystems and disabling swap
+            is a very good here.
 
                Run repeatedly actions:
 
@@ -984,10 +992,9 @@ Example /etc/inittab file:
        tty4::respawn:/sbin/getty 38400 tty5
        tty5::respawn:/sbin/getty 38400 tty6
        
-       
-       
-       ::ctrlaltdel:/bin/umount -a -r
-       ::ctrlaltdel:/sbin/swapoff -a
+       ::ctrlaltdel:/sbin/reboot
+       ::shutdown:/bin/umount -a -r
+       ::shutdown:/sbin/swapoff -a
 
 
 -------------------------------
@@ -2476,4 +2483,4 @@ Enrique Zanardi <ezanardi@ull.es>
 
 =cut
 
-# $Id: busybox.pod,v 1.92 2001/03/15 21:20:25 markw Exp $
+# $Id: busybox.pod,v 1.93 2001/04/03 18:01:51 andersen Exp $
index 1ee2ab3284f950fa598bca2a3ce56912b1b4c777..aa7f0af22792cac176bb11d285ecbaf9d671aae9 100644 (file)
 "\n" \
 "      ::sysinit:/etc/init.d/rcS\n" \
 "      ::askfirst:/bin/sh\n" \
+"      ::ctrlaltdel:/sbin/reboot\n" \
+"      ::shutdown:/sbin/swapoff -a\n" \
+"      ::shutdown:/bin/umount -a -r\n" \
 "\n" \
 "if it detects that /dev/console is _not_ a serial console, it will also run:\n" \
 "\n" \
 "      tty2::askfirst:/bin/sh\n" \
+"      tty3::askfirst:/bin/sh\n" \
+"      tty4::askfirst:/bin/sh\n" \
 "\n" \
 "If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n" \
 "\n" \
 "      <action>: \n" \
 "\n" \
 "              Valid actions include: sysinit, respawn, askfirst, wait, \n" \
-"              once, and ctrlaltdel.\n" \
+"              once, ctrlaltdel, and shutdown.\n" \
 "\n" \
 "              The available actions can be classified into two groups: actions\n" \
 "              that are run only once, and actions that are re-run when the specified\n" \
 "                      'wait' actions, like  'sysinit' actions, cause init to wait until\n" \
 "                      the specified task completes.  'once' actions are asyncronous,\n" \
 "                      therefore, init does not wait for them to complete.  'ctrlaltdel'\n" \
-"                      actions are run immediately before init causes the system to reboot\n" \
-"                      (unmounting filesystems with a 'ctrlaltdel' action is a very good\n" \
-"                      idea).\n" \
+"                      actions are run when the system detects that someone on the system\n" \
+"                       console has pressed the CTRL-ALT-DEL key combination.  Typically one\n" \
+"                       wants to run 'reboot' at this point to cause the system to reboot.\n" \
+"                      Finally the 'shutdown' action specifies the actions to taken when\n" \
+"                       init is told to reboot.  Unmounting filesystems and disabling swap\n" \
+"                       is a very good here\n" \
 "\n" \
 "              Run repeatedly actions:\n" \
 "\n" \
 "      #::respawn:/sbin/getty 57600 ttyS2\n" \
 "      \n" \
 "      # Stuff to do before rebooting\n" \
-"      ::ctrlaltdel:/bin/umount -a -r\n" \
-"      ::ctrlaltdel:/sbin/swapoff -a\n"
+"      ::ctrlaltdel:/sbin/reboot\n" \
+"      ::shutdown:/bin/umount -a -r\n" \
+"      ::shutdown:/sbin/swapoff -a\n"
 
 #define insmod_trivial_usage \
        "[OPTION]... MODULE [symbol=value]..."
diff --git a/init.c b/init.c
index 417aadd23be4c88fd31635fcc05d64b88126d7be..570b8a697fe23e8d6640eb42d85eea75fdbd1f85 100644 (file)
--- a/init.c
+++ b/init.c
@@ -146,7 +146,8 @@ typedef enum {
        ASKFIRST,
        WAIT,
        ONCE,
-       CTRLALTDEL
+       CTRLALTDEL,
+       SHUTDOWN
 } initActionEnum;
 
 /* A mapping between "inittab" action name strings and action type codes. */
@@ -162,6 +163,7 @@ static const struct initActionType actions[] = {
        {"wait", WAIT},
        {"once", ONCE},
        {"ctrlaltdel", CTRLALTDEL},
+       {"shutdown", SHUTDOWN},
        {0, 0}
 };
 
@@ -617,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,7 +656,7 @@ static void shutdown_system(void)
        sleep(1);
 
        /* run everything to be run at "ctrlaltdel" */
-       run_lastAction();
+       run_actions(SHUTDOWN);
 
        sync();
        if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
@@ -696,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)
@@ -767,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 */
@@ -883,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 
index 417aadd23be4c88fd31635fcc05d64b88126d7be..570b8a697fe23e8d6640eb42d85eea75fdbd1f85 100644 (file)
@@ -146,7 +146,8 @@ typedef enum {
        ASKFIRST,
        WAIT,
        ONCE,
-       CTRLALTDEL
+       CTRLALTDEL,
+       SHUTDOWN
 } initActionEnum;
 
 /* A mapping between "inittab" action name strings and action type codes. */
@@ -162,6 +163,7 @@ static const struct initActionType actions[] = {
        {"wait", WAIT},
        {"once", ONCE},
        {"ctrlaltdel", CTRLALTDEL},
+       {"shutdown", SHUTDOWN},
        {0, 0}
 };
 
@@ -617,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,7 +656,7 @@ static void shutdown_system(void)
        sleep(1);
 
        /* run everything to be run at "ctrlaltdel" */
-       run_lastAction();
+       run_actions(SHUTDOWN);
 
        sync();
        if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) {
@@ -696,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)
@@ -767,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 */
@@ -883,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 
index 3e5f2382c1cf363e1205e5452f4fa08598c21486..74d2cf6434c62856f721dc34600e2664b7899181 100644 (file)
@@ -28,9 +28,9 @@ extern int reboot_main(int argc, char **argv)
 {
 #ifdef BB_FEATURE_LINUXRC
        /* don't assume init's pid == 1 */
-       return(kill(*(find_pid_by_name("init")), SIGINT));
+       return(kill(*(find_pid_by_name("init")), SIGTERM));
 #else
-       return(kill(1, SIGINT));
+       return(kill(1, SIGTERM));
 #endif
 }
 
index 3e5f2382c1cf363e1205e5452f4fa08598c21486..74d2cf6434c62856f721dc34600e2664b7899181 100644 (file)
--- a/reboot.c
+++ b/reboot.c
@@ -28,9 +28,9 @@ extern int reboot_main(int argc, char **argv)
 {
 #ifdef BB_FEATURE_LINUXRC
        /* don't assume init's pid == 1 */
-       return(kill(*(find_pid_by_name("init")), SIGINT));
+       return(kill(*(find_pid_by_name("init")), SIGTERM));
 #else
-       return(kill(1, SIGINT));
+       return(kill(1, SIGTERM));
 #endif
 }
 
diff --git a/usage.h b/usage.h
index 1ee2ab3284f950fa598bca2a3ce56912b1b4c777..aa7f0af22792cac176bb11d285ecbaf9d671aae9 100644 (file)
--- a/usage.h
+++ b/usage.h
 "\n" \
 "      ::sysinit:/etc/init.d/rcS\n" \
 "      ::askfirst:/bin/sh\n" \
+"      ::ctrlaltdel:/sbin/reboot\n" \
+"      ::shutdown:/sbin/swapoff -a\n" \
+"      ::shutdown:/bin/umount -a -r\n" \
 "\n" \
 "if it detects that /dev/console is _not_ a serial console, it will also run:\n" \
 "\n" \
 "      tty2::askfirst:/bin/sh\n" \
+"      tty3::askfirst:/bin/sh\n" \
+"      tty4::askfirst:/bin/sh\n" \
 "\n" \
 "If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n" \
 "\n" \
 "      <action>: \n" \
 "\n" \
 "              Valid actions include: sysinit, respawn, askfirst, wait, \n" \
-"              once, and ctrlaltdel.\n" \
+"              once, ctrlaltdel, and shutdown.\n" \
 "\n" \
 "              The available actions can be classified into two groups: actions\n" \
 "              that are run only once, and actions that are re-run when the specified\n" \
 "                      'wait' actions, like  'sysinit' actions, cause init to wait until\n" \
 "                      the specified task completes.  'once' actions are asyncronous,\n" \
 "                      therefore, init does not wait for them to complete.  'ctrlaltdel'\n" \
-"                      actions are run immediately before init causes the system to reboot\n" \
-"                      (unmounting filesystems with a 'ctrlaltdel' action is a very good\n" \
-"                      idea).\n" \
+"                      actions are run when the system detects that someone on the system\n" \
+"                       console has pressed the CTRL-ALT-DEL key combination.  Typically one\n" \
+"                       wants to run 'reboot' at this point to cause the system to reboot.\n" \
+"                      Finally the 'shutdown' action specifies the actions to taken when\n" \
+"                       init is told to reboot.  Unmounting filesystems and disabling swap\n" \
+"                       is a very good here\n" \
 "\n" \
 "              Run repeatedly actions:\n" \
 "\n" \
 "      #::respawn:/sbin/getty 57600 ttyS2\n" \
 "      \n" \
 "      # Stuff to do before rebooting\n" \
-"      ::ctrlaltdel:/bin/umount -a -r\n" \
-"      ::ctrlaltdel:/sbin/swapoff -a\n"
+"      ::ctrlaltdel:/sbin/reboot\n" \
+"      ::shutdown:/bin/umount -a -r\n" \
+"      ::shutdown:/sbin/swapoff -a\n"
 
 #define insmod_trivial_usage \
        "[OPTION]... MODULE [symbol=value]..."