diff options
author | John Crispin <blogic@openwrt.org> | 2013-04-18 19:59:53 +0200 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2013-04-23 18:54:03 +0200 |
commit | 9961e88dd853a30503298378679d2cedc497410e (patch) | |
tree | 40dba5f53cd6d335462bc5977fb98bacab847fdd | |
parent | b9fcb589a4c086d786891f13dfececcfabc0c91f (diff) | |
download | unitd-9961e88dd853a30503298378679d2cedc497410e.tar unitd-9961e88dd853a30503298378679d2cedc497410e.zip |
make reboot work without -f in failsafe
Singed-off-by: John Crispin <blogic@openwrt.org>
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | procd.h | 1 | ||||
-rw-r--r-- | signal.c | 31 |
3 files changed, 27 insertions, 6 deletions
@@ -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(); @@ -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); @@ -19,11 +19,27 @@ #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); +} |