From 4f1ae70765700daeceaaacc2f737a7f94ad11203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 30 Dec 2019 10:58:01 +0200 Subject: [PATCH] Allow multiple fatal signals As long as the same thread never handles more than one fatal signal, multiple fatal signals can be processed. This should guarantee that the stacktrace is printed into the log while guaranteeing that recursion never takes place if the handling of a fatal signal causes a fatal signal to be emitted. --- server/core/gateway.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 17809e353..7da83efc3 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -402,11 +402,18 @@ static int signal_set(int sig, void (* handler)(int)); static void sigfatal_handler(int i) { - // The same signal being handled *now* can occur in another thread (and is often likely). - // By setting the default handler here we will always get a core, but not necessarily - // the backtrace into the log file. This should be overhauled to proper signal handling - // (MXS-599). - signal_set(i, SIG_DFL); + thread_local std::thread::id current_id; + std::thread::id no_id; + + if (current_id != no_id) + { + // Fatal error when processing a fatal error. + // TODO: This should be overhauled to proper signal handling (MXS-599). + signal_set(i, SIG_DFL); + raise(i); + } + + current_id = std::this_thread::get_id(); MXS_CONFIG* cnf = config_get_global_options(); fprintf(stderr, @@ -444,6 +451,7 @@ static void sigfatal_handler(int i) /* re-raise signal to enforce core dump */ fprintf(stderr, "\n\nWriting core dump\n"); + signal_set(i, SIG_DFL); raise(i); }