summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2013-04-18 19:59:53 +0200
committerJohn Crispin <blogic@openwrt.org>2013-04-23 18:54:03 +0200
commit9961e88dd853a30503298378679d2cedc497410e (patch)
tree40dba5f53cd6d335462bc5977fb98bacab847fdd
parentb9fcb589a4c086d786891f13dfececcfabc0c91f (diff)
downloadunitd-9961e88dd853a30503298378679d2cedc497410e.tar
unitd-9961e88dd853a30503298378679d2cedc497410e.zip
make reboot work without -f in failsafe
Singed-off-by: John Crispin <blogic@openwrt.org>
-rw-r--r--main.c1
-rw-r--r--procd.h1
-rw-r--r--signal.c31
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);
+}