Date: Fri, 16 May 2008 17:41:02 +0200 From: Jille Timmermans <jille@quis.cx> To: freebsd-hackers@freebsd.org Subject: Trying (not) to crash with libpthread (6.3-RELEASE) Message-ID: <482DAB0E.70600@quis.cx>
next in thread | raw e-mail | index | archive | help
Hello, I'm trying to catch SIGSEGV, to be able to run 'unchecked' (possibly crashing) code. And not letting the entire program die, but just kill that thread. So I wrote some testing code. But, I ran into a problem; the signal-handler does not work when a thread is created (or something like that). The code below crashes on SIGSEGV, but should die in void sigcatcher(int); If you uncomment the crashingthread(NULL); line, it will die in the signal handler. pthread_create seems to take over signal handling. I quickly checked some pthread source, and it seems that it should call my own handler. (There might be an exception for some signals, but I didn't found that) Can anyone explain me what is happening here ? -- Jille cc -lpthread below.c #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <pthread.h> #include <signal.h> #include <err.h> int success=0; void sigcatcher(int sig) { printf("[%p] signal %d\n", pthread_self(), sig); printf("Test (probably) succeeded\n"); fflush(NULL); success=1; exit(0); } void * crashingthread(void *nada) { /* This will likely crash */ char *x=malloc(1); if(signal(SIGSEGV, sigcatcher)==SIG_ERR) err(1, "signal(SIGSEGV, catchz0r)"); x[666]=0; /* HOPEFULLY NOT REACHED (aargh! die harder!) */ int i; for(i=1; 999999>i; i++) x[i]=0; /* NOT REACHED (either killed, or exit()'ed in sigcatcher) */ abort(); } int main(int argc, char **argv) { pthread_t thr; if(signal(SIGSEGV, sigcatcher)==SIG_ERR) err(1, "signal(SIGSEGV, catchz0r)"); //crashingthread(NULL); pthread_create(&thr, NULL, crashingthread, NULL); sleep(3); return 0; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?482DAB0E.70600>