mirror of
https://github.com/troglobit/finit.git
synced 2026-10-31 13:00:32 +00:00
Trap segfaults caused by service callbacks in separate process context
This patch traps segfaults caused by 3rd party service callbacks in a separate process context. Effectively preventing a single programming mistake from taking down the entire system. Previously it was up to the callback coder to write error free code so that PID 1 did not crash. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
d6efe85a57
commit
b4b63d3722
2 files changed
+46
-3
No files matched your search
@@ -49,7 +49,7 @@
|
||||
|
||||
static int stopped = 0;
|
||||
static uev_t sigint_watcher, sigpwr_watcher;
|
||||
static uev_t sigchld_watcher;
|
||||
static uev_t sigchld_watcher, sigsegv_watcher;
|
||||
static uev_t sigstop_watcher, sigtstp_watcher, sigcont_watcher;
|
||||
|
||||
|
||||
@@ -103,6 +103,15 @@ static void sigchld_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *UNUSED(ar
|
||||
svc_monitor(waitpid(-1, NULL, WNOHANG));
|
||||
}
|
||||
|
||||
/*
|
||||
* SIGSEGV: mostly if service callbacks segfault
|
||||
*/
|
||||
static void sigsegv_cb(uev_ctx_t *UNUSED(ctx), uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
||||
{
|
||||
_e("PID %d caused a segfault!\n", getpid());
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* SIGSTOP/SIGTSTP: Paused by user or netflash
|
||||
*/
|
||||
@@ -204,6 +213,9 @@ void sig_setup(uev_ctx_t *ctx)
|
||||
/* After initial bootstrap of Finit we call the service monitor to reap children */
|
||||
uev_signal_init(ctx, &sigchld_watcher, sigchld_cb, NULL, SIGCHLD);
|
||||
|
||||
/* Trap SIGSEGV in case service callbacks crash */
|
||||
uev_signal_init(ctx, &sigsegv_watcher, sigsegv_cb, NULL, SIGSEGV);
|
||||
|
||||
/* Stopping init is a bit tricky. */
|
||||
uev_signal_init(ctx, &sigstop_watcher, sigstop_cb, NULL, SIGSTOP);
|
||||
uev_signal_init(ctx, &sigtstp_watcher, sigstop_cb, NULL, SIGTSTP);
|
||||
|
||||
Reference in new issue
Block a user