From 9fad49e027fe8616c2f9913433c744ceb1a3589b Mon Sep 17 00:00:00 2001 From: Ben Gamari <ben@smart-cactus.org> Date: Tue, 23 May 2023 13:44:20 -0400 Subject: [PATCH] rts: Do not call exit() from SIGINT handler Previously `shutdown_handler` would call `stg_exit` if the scheduler was Oalready found to be in `SCHED_INTERRUPTING` state (or higher). However, `stg_exit` is not signal-safe as it calls `exit` (which calls `atexit` handlers). The only safe thing to do in this situation is to call `_exit`, which terminates with minimal cleanup. Fixes #23417. --- rts/posix/Signals.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rts/posix/Signals.c b/rts/posix/Signals.c index 1d96fcfdf526..a16bc24b7cac 100644 --- a/rts/posix/Signals.c +++ b/rts/posix/Signals.c @@ -522,7 +522,9 @@ shutdown_handler(int sig STG_UNUSED) // extreme prejudice. So the first ^C tries to exit the program // cleanly, and the second one just kills it. if (getSchedState() >= SCHED_INTERRUPTING) { - stg_exit(EXIT_INTERRUPTED); + // N.B. we cannot use stg_exit() here as it calls exit() which is not + // signal-safe. See #23417. + _exit(EXIT_INTERRUPTED); } else { interruptStgRts(); } -- GitLab