Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
markus456 committed Dec 31, 2019
1 parent 7fb0987 commit 03d45c2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions server/core/gateway.cc
Expand Up @@ -403,11 +403,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,
Expand Down Expand Up @@ -443,6 +450,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);
}

Expand Down

0 comments on commit 03d45c2

Please sign in to comment.