[Toxine-cvs] CVS: toxine/src main.c,1.42,1.43
Brought to you by:
f1rmb
From: Daniel Caujolle-B. <f1...@us...> - 2004-07-19 09:59:45
|
Update of /cvsroot/toxine/toxine/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30704 Modified Files: main.c Log Message: really handle SEGV signal... Index: main.c =================================================================== RCS file: /cvsroot/toxine/toxine/src/main.c,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- main.c 19 Jul 2004 09:00:47 -0000 1.42 +++ main.c 19 Jul 2004 09:59:33 -0000 1.43 @@ -82,38 +82,40 @@ * Handle signals event. */ void toxine_signals_handler (int sig) { - pid_t pid = getppid(); + pid_t pid; - if(pid == tox->pid) { - - switch(sig) { - /* Segfault */ - case SIGSEGV: - perr("SIGSEGV received.\n"); + /* Segfault */ + if(sig == SIGSEGV) { + perr("SIGSEGV received.\n"); #ifdef __linux__ - { - void *backtrace_array[255]; - char **backtrace_strings; - int entries, i; - - if((entries = backtrace(backtrace_array, 255))) { - if((backtrace_strings = backtrace_symbols(backtrace_array, entries))) { - perr("Backtrace:\n"); - - for(i = 0; i < entries; i++) { - poutalign(); - pout("[%d] %s\n", i, backtrace_strings[i]); - } - - free(backtrace_strings); - perr("--\n"); + { + void *backtrace_array[255]; + char **backtrace_strings; + int entries, i; + + if((entries = backtrace(backtrace_array, 255))) { + if((backtrace_strings = backtrace_symbols(backtrace_array, entries))) { + perr("Backtrace:\n"); + + for(i = 0; i < entries; i++) { + poutalign(); + pout("[%d] %s\n", i, backtrace_strings[i]); } + + free(backtrace_strings); + perr("--\n"); } } + } #endif - exit(TOX_ERR_SIGSEGV); - break; + exit(TOX_ERR_SIGSEGV); + } + + pid = getppid(); + if(pid == tox->pid) { + + switch(sig) { /* Kill the line on C-c */ case SIGINT: if(tox->interactive != 1) { @@ -491,6 +493,7 @@ * ... */ int main(int argc, char **argv) { + struct sigaction action; int pid, status, ret; if(getuid() == 0) { @@ -506,6 +509,12 @@ signal(SIGQUIT, SIG_IGN); signal(SIGALRM, SIG_IGN); + action.sa_handler = toxine_signals_handler; + sigemptyset(&(action.sa_mask)); + action.sa_flags = 0; + if(sigaction(SIGSEGV, &action, NULL) != 0) + fprintf(stderr, "sigaction(SIGSEGV) failed: %s\n", strerror(errno)); + pid = fork(); switch(pid) { case -1: |