diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-12-21 12:36:16 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-12-21 12:36:16 +0100 |
commit | 267f82b78cfb41a7b96553b775f753760e8ac5da (patch) | |
tree | f6010a8956f7aacf1cee4a0ba82d8dc1c980140a | |
parent | b7254323f35a172543ead20235bf77dd5408ccd8 (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() |