Skip to content

Commit 3f198b4

Browse files
authored
Merge pull request #101 from kenyh0926/bugfix/signal
1. 修改signal_handler函数,用于SIGSEG/SIGILL/SIGFPE/SIGBUS的处理
2 parents 6d8a9f6 + 2efb445 commit 3f198b4

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

src/mysql-proxy-cli.c

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,33 @@ int chassis_frontend_set_chassis_options(chassis_frontend_t *frontend, chassis_o
362362
return 0;
363363
}
364364

365-
static void sigsegv_handler(int G_GNUC_UNUSED signum) {
366-
g_on_error_stack_trace(g_get_prgname());
365+
static inline void print_stacktrace(int signum) {
366+
int j, nptrs;
367+
void *buffer[MAX_FRAMES+1];
368+
gchar *signal_str = g_strdup(strsignal(signum));
369+
if (signal_str){
370+
g_log_dbproxy(g_warning, "[backtrace] signal:%s(%d) stack trace:", signal_str, signum);
371+
g_free(signal_str);
372+
}
373+
else{
374+
g_log_dbproxy(g_warning, "[backtrace] signal: (%d) stack trace:", signum);
375+
}
376+
377+
nptrs = backtrace(buffer, MAX_FRAMES);
378+
char **strings = backtrace_symbols(buffer, nptrs);
379+
if (strings == NULL) {
380+
g_log_dbproxy(g_warning, "[backtrace] no backtrace symbols");
381+
return;
382+
}
383+
for (j= 0; j < nptrs; j++){
384+
g_log_dbproxy(g_warning, "[backtrace] %-3d: %s", j, strings[j]);
385+
}
386+
free(strings);
387+
}
388+
389+
static void sigsegv_handler(int signum) {
390+
print_stacktrace(signum);
391+
//g_on_error_stack_trace(g_get_prgname());
367392
abort(); /* trigger a SIGABRT instead of just exiting */
368393
}
369394

@@ -643,9 +668,16 @@ int main_cmdline(int argc, char **argv) {
643668
sigsegv_sa.sa_handler = sigsegv_handler;
644669
sigemptyset(&sigsegv_sa.sa_mask);
645670

646-
if (frontend->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) {
647-
sigaction(SIGSEGV, &sigsegv_sa, NULL);
648-
}
671+
sigaction(SIGSEGV, &sigsegv_sa, NULL);
672+
#ifdef SIGBUS
673+
sigaction(SIGBUS, &sigsegv_sa, NULL);
674+
#endif
675+
sigaction(SIGILL, &sigsegv_sa, NULL);
676+
sigaction(SIGFPE, &sigsegv_sa, NULL);
677+
678+
/*if (frontend->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) {
679+
sigaction(SIGSEGV, &sigsegv_sa, NULL);
680+
}*/
649681
#endif
650682

651683
/*
@@ -1014,9 +1046,15 @@ int main_cmdline(int argc, char **argv) {
10141046
#ifdef HAVE_SIGACTION
10151047
/* reset the handler */
10161048
sigsegv_sa.sa_handler = SIG_DFL;
1017-
if (frontend->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) {
1049+
/*if (frontend->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) {
10181050
sigaction(SIGSEGV, &sigsegv_sa, NULL);
1019-
}
1051+
}*/
1052+
sigaction(SIGSEGV, &sigsegv_sa, NULL);
1053+
#ifdef SIGBUS
1054+
sigaction(SIGBUS, &sigsegv_sa, NULL);
1055+
#endif
1056+
sigaction(SIGILL, &sigsegv_sa, NULL);
1057+
sigaction(SIGFPE, &sigsegv_sa, NULL);
10201058
#endif
10211059
chassis_frontend_free(frontend);
10221060

src/network-mysqld.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646

4747
#include <glib.h>
4848

49+
#include <execinfo.h>
50+
4951
#include "network-exports.h"
5052

5153
#include "network-socket.h"
@@ -60,6 +62,8 @@
6062
#include "network-mysqld-stats.h"
6163
#include "network-conn-errcode.h"
6264

65+
#define MAX_FRAMES 128
66+
6367
#define SEND_ERR_MSG_HANDLE(log_func, errmsg, con) \
6468
do { \
6569
log_func("%s(%s) event_thread(%d) " \

0 commit comments

Comments
 (0)