From owner-freebsd-threads@FreeBSD.ORG Thu Oct 21 07:00:48 2004 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E08A216A4CF for ; Thu, 21 Oct 2004 07:00:48 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0709143D2D for ; Thu, 21 Oct 2004 07:00:45 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i9L70iDq004727 for ; Thu, 21 Oct 2004 07:00:44 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i9L70i4x004725; Thu, 21 Oct 2004 07:00:44 GMT (envelope-from gnats) Resent-Date: Thu, 21 Oct 2004 07:00:44 GMT Resent-Message-Id: <200410210700.i9L70i4x004725@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Mark Andrews Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BE85416A4CE for ; Thu, 21 Oct 2004 06:54:13 +0000 (GMT) Received: from daemon.lab.isc.org (daemon.lab.isc.org [204.152.187.133]) by mx1.FreeBSD.org (Postfix) with ESMTP id 78CA543D58 for ; Thu, 21 Oct 2004 06:54:13 +0000 (GMT) (envelope-from marka@daemon.lab.isc.org) Received: from daemon.lab.isc.org (localhost [127.0.0.1]) by daemon.lab.isc.org (8.12.10/8.12.10) with ESMTP id i9L6sDT9029638 for ; Thu, 21 Oct 2004 06:54:13 GMT (envelope-from marka@daemon.lab.isc.org) Received: (from marka@localhost) by daemon.lab.isc.org (8.12.10/8.12.10/Submit) id i9L6sCjk029637; Thu, 21 Oct 2004 06:54:12 GMT (envelope-from marka) Message-Id: <200410210654.i9L6sCjk029637@daemon.lab.isc.org> Date: Thu, 21 Oct 2004 06:54:12 GMT From: Mark Andrews To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: threads/72953: fork() unblocks blocked signals w/o PTHREAD_SCOPE_SYSTEM X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Mark Andrews List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Oct 2004 07:00:49 -0000 >Number: 72953 >Category: threads >Synopsis: fork() unblocks blocked signals w/o PTHREAD_SCOPE_SYSTEM >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-threads >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Oct 21 07:00:44 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Mark Andrews >Release: FreeBSD 5.3-BETA6 i386 >Organization: ISC >Environment: System: FreeBSD daemon.lab.isc.org 5.3-BETA6 FreeBSD 5.3-BETA6 #16: Tue Oct 5 23:37:23 UTC 2004 jinmei@daemon.lab.isc.org:/hog0/users/jinmei/src/sys/i386/compile/DAEMON i386 >Description: fork() clears blocked signals unless PTHREAD_SCOPE_SYSTEM is set. >How-To-Repeat: Run the following program with and without the arguement system. In the first case the program will incorrectly be killed by the SIGTERM. In the second case the signal will be blocked and sigwait returns. #include #include #include #include #include #include #include sigset_t signal_mask; void dofork() { switch (fork()) { case 0: break; case -1: _exit(1); default: _exit(0); } fprintf(stderr, "fork\n"); fflush(stderr); } static void * waiter(void *arg) { int result; int sig; result = sigwait(&signal_mask, &sig); if (result != 0) fprintf(stderr, "sigwait: %\n", strerror(result)); else fprintf(stderr, "signal %d\n", sig); fflush(stderr); return (NULL); } int main(int argc, char **argv) { pthread_t id; pthread_attr_t attr; int result; int scope = 0; if (argc > 1) { if (strcmp(argv[1], "system") == 0) scope = 1; } sigemptyset (&signal_mask); sigaddset (&signal_mask, SIGTERM); result = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); if (result != 0) fprintf(stderr, "pthread_sigmask: %\n", strerror(result)); else fprintf(stderr, "pthread_sigmask: OK\n"); fflush(stderr); dofork(); result = pthread_attr_init(&attr); if (result != 0) fprintf(stderr, "pthread_attr_init: %\n", strerror(result)); else fprintf(stderr, "pthread_attr_init: OK\n"); fflush(stderr); if (scope) { result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); if (result != 0) fprintf(stderr, "pthread_attr_setscope: %\n", strerror(result)); else fprintf(stderr, "pthread_attr_setscope: OK\n"); } else fprintf(stderr, "default scope\n"); fflush(stderr); result = pthread_create (&id, &attr, waiter, NULL); if (result != 0) fprintf(stderr, "pthread_create: %\n", strerror(result)); else fprintf(stderr, "pthread_create: OK\n"); fflush(stderr); if (kill(getpid(), SIGTERM) == -1) perror("kill"); else fprintf(stderr, "kill: OK\n"); fflush(stderr); result = pthread_join(id, NULL); if (result != 0) fprintf(stderr, "pthread_join: %\n", strerror(result)); else fprintf(stderr, "pthread_join: OK\n"); fflush(stderr); return(0); } >Fix: >Release-Note: >Audit-Trail: >Unformatted: