make reboot work without -f in failsafe
authorJohn Crispin <blogic@openwrt.org>
Thu, 18 Apr 2013 17:59:53 +0000 (19:59 +0200)
committerJohn Crispin <blogic@openwrt.org>
Tue, 23 Apr 2013 16:54:03 +0000 (18:54 +0200)
Singed-off-by: John Crispin <blogic@openwrt.org>
main.c
procd.h
signal.c

diff --git a/main.c b/main.c
index 65ed854bf5f24dae1ec82062a34eb3c7783558f6..9d2ab894629b0b7cf5ff0237ba13bac9a7dbf386 100644 (file)
--- a/main.c
+++ b/main.c
@@ -36,6 +36,7 @@ static int usage(const char *prog)
 
 static int main_procd_init(int argc, char **argv)
 {
+       procd_signal_preinit();
        procd_early();
        debug_init();
        watchdog_init();
diff --git a/procd.h b/procd.h
index f3aff895b18364d8b727d9732e7e7fe7479d2f3f..a500f00d7f0a75b10180f36f642189755ba8314d 100644 (file)
--- a/procd.h
+++ b/procd.h
@@ -58,6 +58,7 @@ void procd_early(void);
 void procd_preinit(void);
 void procd_coldplug(void);
 void procd_signal(void);
+void procd_signal_preinit(void);
 void procd_inittab(void);
 void procd_inittab_run(const char *action);
 
index a4b08c32de5ec8cf9c312c44b228d7cc08812831..f705e5d2a091729240b66877a4934127a3178a48 100644 (file)
--- a/signal.c
+++ b/signal.c
 
 #include "procd.h"
 
+static int preinit;
+
+static void do_reboot(void)
+{
+       LOG("reboot\n");
+       fflush(stderr);
+       sync();
+       sleep(1);
+       reboot(RB_AUTOBOOT);
+       while (1)
+       ;
+}
+
 static void signal_shutdown(int signal, siginfo_t *siginfo, void *data)
 {
        int event = 0;
        char *msg = NULL;
 
+       if (preinit)
+               do_reboot();
+
        switch(signal) {
        case SIGTERM:
                event = RB_AUTOBOOT;
@@ -49,12 +65,7 @@ struct sigaction sa_shutdown = {
 static void signal_crash(int signal, siginfo_t *siginfo, void *data)
 {
        ERROR("Rebooting as procd has crashed\n");
-       fflush(stderr);
-       sync();
-       sleep(1);
-       reboot(RB_AUTOBOOT);
-       while (1)
-               ;
+       do_reboot();
 }
 
 struct sigaction sa_crash = {
@@ -86,3 +97,11 @@ void procd_signal(void)
        sigaction(SIGKILL, &sa_dummy, NULL);
        sigaction(SIGSTOP, &sa_dummy, NULL);
 }
+
+void procd_signal_preinit(void)
+{
+       preinit = 1;
+       sigaction(SIGTERM, &sa_shutdown, NULL);
+       sigaction(SIGUSR1, &sa_shutdown, NULL);
+       sigaction(SIGUSR2, &sa_shutdown, NULL);
+}