diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-12-21 12:36:16 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2018-01-03 09:41:41 +0100 |
commit | d559a044b7d6daa62437a38ff81161505b2e58b8 (patch) | |
tree | ab84531236bed4ff4cb2e7f4cd9745a39065932a | |
parent | b659dabd9d8a72b810d212a1b938409185a81432 (diff) |
sig-monitor: Handle signals in exit
Change signal treatment when exit is called
internally by sig-monitor.
Change-Id: Ieb6261b2143811d7abcbc49b134e919c8c5626dc
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | src/sig-monitor.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/sig-monitor.c b/src/sig-monitor.c index f5762bcc..1b57a5f6 100644 --- a/src/sig-monitor.c +++ b/src/sig-monitor.c @@ -43,6 +43,8 @@ static _Thread_local timer_t thread_timerid; /* internal signal lists */ static int sigerr[] = { SIG_FOR_TIMER, SIGSEGV, SIGFPE, SIGILL, SIGBUS, 0 }; static int sigterm[] = { SIGINT, SIGABRT, SIGTERM, 0 }; +static int exiting = 0; + /* * Dumps the current stack */ @@ -183,6 +185,25 @@ static int install(void (*handler)(int), int *signals) return result; } +/* + * rescue exit + */ +static void on_rescue_exit(int signum) +{ + ERROR("Rescue exit for signal %d: %s", signum, strsignal(signum)); + _exit(exiting); +} + +/* + * Do a safe exit + */ +static void safe_exit(int code) +{ + install(on_rescue_exit, sigerr); + install(on_rescue_exit, sigterm); + exiting = code; + exit(code); +} /* Handles signals that terminate the process */ static void on_signal_terminate (int signum) @@ -192,7 +213,7 @@ static void on_signal_terminate (int signum) if (signum == SIGABRT) safe_dumpstack(3, signum); } - exit(1); + safe_exit(1); } /* Handles monitored signals that can be continued */ @@ -212,7 +233,7 @@ static void on_signal_error(int signum) longjmp(*error_handler, signum); ERROR("Unmonitored signal %d received: %s", signum, strsignal(signum)); - exit(2); + safe_exit(2); } int sig_monitor_init() |