summary refs log tree commit diff stats
path: root/lib/system/excpt.nim
diff options
context:
space:
mode:
authoralaviss <leorize+oss@disroot.org>2021-02-19 08:29:21 +0000
committerGitHub <noreply@github.com>2021-02-19 00:29:21 -0800
commitccc0667c29256ec1303e1d4280f013b380d85828 (patch)
tree88fda1a9341491f8afdff001a034e1a537ee0ddd /lib/system/excpt.nim
parent95664e15247d678476d64a1c81f7c19b163e823c (diff)
downloadNim-ccc0667c29256ec1303e1d4280f013b380d85828.tar.gz
system/excpt: let the OS handle termination on signal (#16712)
Diffstat (limited to 'lib/system/excpt.nim')
-rw-r--r--lib/system/excpt.nim12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index dbb39f536..19bf8911d 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -643,7 +643,17 @@ when not defined(noSignalHandler) and not defined(useNimRtl):
       # unless there's a good reason to use cstring in signal handler to avoid
       # using gc?
       showErrorMessage(msg, msg.len)
-    quit(1) # always quit when SIGABRT
+
+    when defined(posix):
+      # reset the signal handler to OS default
+      c_signal(sign, SIG_DFL)
+
+      # re-raise the signal, which will arrive once this handler exit.
+      # this lets the OS perform actions like core dumping and will
+      # also return the correct exit code to the shell.
+      discard c_raise(sign)
+    else:
+      quit(1)
 
   proc registerSignalHandler() =
     c_signal(SIGINT, signalHandler)