Fix stack trace generation

The stack traces weren't logged as the LOG_ALERT priority wasn't enabled
by default. As an alert is intended to be something that must leave a
trace somewhere, and as such, it must not be possible to disable it. For
this reason, it is acceptable to always log the message if the priority is
LOG_ALERT.

Added the -rdynamic linker flag so that all symbols are exported when
linking MaxScale.

As the stack trace is printed in a signal handler, the first attempt
should be to print the stack trace to the standard output. This way the
output is printed before an attempt to use malloc is made when it is
logged to the logfile.
This commit is contained in:
Markus Mäkelä 2017-09-30 12:37:40 +03:00
parent 94a55f6602
commit 69557c650e
3 changed files with 18 additions and 21 deletions

View File

@ -144,7 +144,7 @@ configure_file(${CMAKE_SOURCE_DIR}/etc/postrm.in ${CMAKE_BINARY_DIR}/postrm @ONL
configure_file(${CMAKE_SOURCE_DIR}/etc/upstart/maxscale.conf.in ${CMAKE_BINARY_DIR}/upstart/maxscale.conf @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.cnf ${CMAKE_BINARY_DIR}/maxscale.cnf @ONLY)
set(FLAGS "-Wall -Wno-unused-variable -Wno-unused-function -Werror -fPIC" CACHE STRING "Compilation flags")
set(FLAGS "-rdynamic -Wall -Wno-unused-variable -Wno-unused-function -Werror -fPIC" CACHE STRING "Compilation flags")
set(DEBUG_FLAGS "-ggdb -pthread -pipe -Wformat -fstack-protector --param=ssp-buffer-size=4" CACHE STRING "Debug compilation flags")
if(CMAKE_VERSION VERSION_GREATER 2.6)

View File

@ -109,7 +109,7 @@ void mxs_log_get_throttling(MXS_LOG_THROTTLING* throttling);
static inline bool mxs_log_priority_is_enabled(int priority)
{
assert((priority & ~LOG_PRIMASK) == 0);
return MXS_LOG_PRIORITY_IS_ENABLED(priority);
return MXS_LOG_PRIORITY_IS_ENABLED(priority) || priority == LOG_ALERT;
}
int mxs_log_message(int priority,

View File

@ -398,32 +398,31 @@ sigfatal_handler(int i)
}
fatal_handling = 1;
MXS_CONFIG* cnf = config_get_global_options();
fprintf(stderr, "\n\nMaxScale " MAXSCALE_VERSION " received fatal signal %d\n", i);
fprintf(stderr, "Fatal: MaxScale " MAXSCALE_VERSION " received fatal signal %d. "
"Attempting backtrace.\n", i);
fprintf(stderr, "Commit ID: %s System name: %s Release string: %s\n\n",
maxscale_commit, cnf->sysname, cnf->release_string);
void *addrs[128];
int count = backtrace(addrs, 128);
MXS_ALERT("Fatal: MaxScale " MAXSCALE_VERSION " received fatal signal %d. Attempting backtrace.", i);
// First print the stack trace to stderr as malloc is likely broken
backtrace_symbols_fd(addrs, count, STDERR_FILENO);
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);
// Then see if we can log them
char** symbols = backtrace_symbols(addrs, count);
if (symbols)
{
void *addrs[128];
int count = backtrace(addrs, 128);
char** symbols = backtrace_symbols(addrs, count);
if (symbols)
for (int n = 0; n < count; n++)
{
for (int n = 0; n < count; n++)
{
MXS_ALERT(" %s\n", symbols[n]);
}
MXS_FREE(symbols);
}
else
{
fprintf(stderr, "\nresolving symbols to error log failed, writing call trace to stderr:\n");
backtrace_symbols_fd(addrs, count, fileno(stderr));
MXS_ALERT(" %s\n", symbols[n]);
}
MXS_FREE(symbols);
}
mxs_log_flush_sync();
@ -434,8 +433,6 @@ sigfatal_handler(int i)
raise(i);
}
/**
* @node Wraps sigaction calls
*