From 9961e88dd853a30503298378679d2cedc497410e Mon Sep 17 00:00:00 2001 From: John Crispin Date: Thu, 18 Apr 2013 19:59:53 +0200 Subject: [PATCH] make reboot work without -f in failsafe Singed-off-by: John Crispin --- main.c | 1 + procd.h | 1 + signal.c | 31 +++++++++++++++++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 65ed854..9d2ab89 100644 --- 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 f3aff89..a500f00 100644 --- 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); diff --git a/signal.c b/signal.c index a4b08c3..f705e5d 100644 --- a/signal.c +++ b/signal.c @@ -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); +} -- 2.25.1