From 7f7b052f0e314a175743674934e484121d9e130b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 2 Oct 2019 10:44:57 +0300 Subject: [PATCH] Print stacktrace in one message By printing the stacktrace in one log message, it prevents it from interleaving with other messages. This happens on busy systems and makes crash analysis harder. --- server/core/gateway.cc | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/server/core/gateway.cc b/server/core/gateway.cc index fa845013e..7bcd083e4 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -411,22 +411,13 @@ static void sigfatal_handler(int i) MXS_CONFIG* cnf = config_get_global_options(); fprintf(stderr, - "Fatal: MaxScale " MAXSCALE_VERSION " received fatal signal %d. " - "Attempting backtrace.\n", - i); - fprintf(stderr, + "Fatal: MaxScale %s received fatal signal %d. " "Commit ID: %s System name: %s Release string: %s\n\n", - maxscale_commit, - cnf->sysname, - cnf->release_string); + MAXSCALE_VERSION, i, maxscale_commit, cnf->sysname, cnf->release_string); - MXS_ALERT("Fatal: MaxScale " MAXSCALE_VERSION " received fatal signal %d. " - "Attempting backtrace.", - i); - MXS_ALERT("Commit ID: %s System name: %s Release string: %s", - maxscale_commit, - cnf->sysname, - cnf->release_string); + MXS_ALERT("Fatal: MaxScale %s received fatal signal %d. " + "Commit ID: %s System name: %s Release string: %s", + MAXSCALE_VERSION, i, maxscale_commit, cnf->sysname, cnf->release_string); if (DCB* dcb = dcb_get_current()) { @@ -437,12 +428,19 @@ static void sigfatal_handler(int i) } } + thread_local char msg[4096] = ""; + msg[0] = '\0'; + auto cb = [](const char* symbol, const char* cmd) { - MXS_ALERT(" %s: %s", symbol, cmd); + char buf[512]; + snprintf(buf, sizeof(buf), " %s: %s\n", symbol, cmd); + strcat(msg, buf); }; mxb::dump_stacktrace(cb); + MXS_ALERT("\n%s", msg); + /* re-raise signal to enforce core dump */ fprintf(stderr, "\n\nWriting core dump\n"); raise(i);