diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index a401ad2ea..1bd425cac 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -12,6 +12,19 @@ static void term_handler(int sig) { __sync_bool_compare_and_swap(&glovars.shutdown,0,1); } +void crash_handler(int sig) { +#ifdef DEBUG + malloc_stats_print(NULL, NULL, ""); +#endif + void *arr[20]; + size_t s; + + s = backtrace(arr, 20); + + fprintf(stderr, "Error: signal %d:\n", sig); + backtrace_symbols_fd(arr, s, STDERR_FILENO); + exit(EXIT_FAILURE); +} ProxySQL_GlobalVariables::~ProxySQL_GlobalVariables() { opt->reset(); @@ -62,7 +75,9 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() { confFile=new ProxySQL_ConfigFile(); signal(SIGTERM, term_handler); - + signal(SIGSEGV, crash_handler); + signal(SIGABRT, crash_handler); + signal(SIGPIPE, SIG_IGN); }; diff --git a/lib/debug.cpp b/lib/debug.cpp index d88c0204e..2d2e04224 100644 --- a/lib/debug.cpp +++ b/lib/debug.cpp @@ -18,20 +18,6 @@ static inline unsigned long long debug_monotonic_time() { return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); } -void crash_handler(int sig) { -#ifdef DEBUG - malloc_stats_print(NULL, NULL, ""); -#endif - void *arr[20]; - size_t s; - - s = backtrace(arr, 20); - - fprintf(stderr, "Error: signal %d:\n", sig); - backtrace_symbols_fd(arr, s, STDERR_FILENO); - exit(EXIT_FAILURE); -} - #define DEBUG_MSG_MAXSIZE 1024