From owner-freebsd-hackers@FreeBSD.ORG Fri May 16 15:41:07 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7C1B31065672 for ; Fri, 16 May 2008 15:41:07 +0000 (UTC) (envelope-from jille@quis.cx) Received: from smtp3.versatel.nl (smtp3.versatel.nl [62.58.50.90]) by mx1.freebsd.org (Postfix) with ESMTP id E41FD8FC1C for ; Fri, 16 May 2008 15:41:06 +0000 (UTC) (envelope-from jille@quis.cx) Received: (qmail 4760 invoked by uid 0); 16 May 2008 15:41:04 -0000 Received: from ip83-113-174-82.adsl2.versatel.nl (HELO istud.quis.cx) ([82.174.113.83]) (envelope-sender ) by smtp3.versatel.nl (qmail-ldap-1.03) with SMTP for < >; 16 May 2008 15:41:04 -0000 Received: by istud.quis.cx (Postfix, from userid 100) id 670173982D; Fri, 16 May 2008 17:41:04 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on istud.quis.cx X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from [192.168.1.10] (unknown [192.168.1.10]) by istud.quis.cx (Postfix) with ESMTP id 9801D3982B for ; Fri, 16 May 2008 17:41:01 +0200 (CEST) Message-ID: <482DAB0E.70600@quis.cx> Date: Fri, 16 May 2008 17:41:02 +0200 From: Jille Timmermans User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Trying (not) to crash with libpthread (6.3-RELEASE) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 May 2008 15:41:07 -0000 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 #include #include #include #include #include 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; }