[Git][ghc/ghc][master] rts: Do not call exit() from SIGINT handler

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Jun 20 07:20:36 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
9fad49e0 by Ben Gamari at 2023-06-20T03:20:19-04:00
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.

- - - - -


1 changed file:

- rts/posix/Signals.c


Changes:

=====================================
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();
     }



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9fad49e027fe8616c2f9913433c744ceb1a3589b

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9fad49e027fe8616c2f9913433c744ceb1a3589b
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230620/3801b11c/attachment.html>


More information about the ghc-commits mailing list