From c51128f051128567559a331d9f457d82518e036d Mon Sep 17 00:00:00 2001 From: Szekely Gyorgy Date: Mon, 22 Nov 2021 16:39:53 +0100 Subject: [PATCH] Unblock faulting thread signal handler after log flush is complete (#419) --- src/crashhandler_unix.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/crashhandler_unix.cpp b/src/crashhandler_unix.cpp index a14985e..ea2f073 100644 --- a/src/crashhandler_unix.cpp +++ b/src/crashhandler_unix.cpp @@ -39,6 +39,8 @@ namespace { + std::atomic gBlockForFatal {true}; + const std::map kSignals = { {SIGABRT, "SIGABRT"}, {SIGFPE, "SIGFPE"}, @@ -134,10 +136,9 @@ namespace g3 { namespace internal { bool shouldBlockForFatalHandling() { - return true; // For windows we will after fatal processing change it to false + return gBlockForFatal; } - /// Generate stackdump. Or in case a stackdump was pre-generated and non-empty just use that one /// i.e. the latter case is only for Windows and test purposes std::string stackdump(const char* rawdump) { @@ -230,6 +231,12 @@ namespace g3 { kill(getpid(), signal_number); + + // When running as PID1 the above kill doesn't have any effect (execution simply passes through it, contrary + // to a non-PID1 process where execution stops at kill and switches over to signal handling). Also as PID1 + // we must unblock the thread that received the original signal otherwise the process will never terminate. + gBlockForFatal = false; + exit(signal_number); }