From nobody@FreeBSD.org  Fri Feb 16 01:00:34 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 81D5A37B401
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 16 Feb 2001 01:00:34 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.1/8.11.1) id f1G90Yx72349;
	Fri, 16 Feb 2001 01:00:34 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200102160900.f1G90Yx72349@freefall.freebsd.org>
Date: Fri, 16 Feb 2001 01:00:34 -0800 (PST)
From: jagarl@creator.club.ne.jp
To: freebsd-gnats-submit@FreeBSD.org
Subject: sigprocmask problem with pthread
X-Send-Pr-Version: www-1.0

>Number:         25132
>Category:       bin
>Synopsis:       sigprocmask problem with pthread
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 16 01:10:00 PST 2001
>Closed-Date:    Thu Jul 26 05:52:06 PDT 2001
>Last-Modified:  Thu Jul 26 05:58:10 PDT 2001
>Originator:     Kazunori Ueno
>Release:        4.2-RELEASE
>Organization:
Univ. of Tokyo, Japan
>Environment:
FreeBSD KitzBSD.chem.t.u-tokyo.ac.jp 4.2-RELEASE FreeBSD 4.2-RELEASE #1: Mon Jan 15 20:14:10 JST 2001     root@KitzBSD.chem.t.u-tokyo.ac.jp:/usr/src/sys/compile/KitzBSD  i386

>Description:
I want to block a signal by sigprocmask, but the signal is not blocked.

Following description is for SIGTERM signal.

In pthread library, signal is trapped by thread_sig_handler(). If
the signal mask is set, the signal blocks in the handler. But
thread_init() sets thread_sig_hander() as signal handler only for
_SCHED_SIGNAL, SIGINFO and SIGCHLD. When the SIGTERM signal is caught,
the signal is processed in kernel and default handler (kill process)
is called.

If I set some signal hander for SIGTERM, then thread_sig_handler() is
used as the signal handler for SIGTERM. Then the signal mask is correctly
used.



>How-To-Repeat:
Compile this program with -pthread option. For example,
  cc test.c -pthread
This program should block 'SIGTERM' signal, but 'kill -TERM pid' kills
this program.

#include <signal.h>

int main()
{
        sigset_t tset;
        sigemptyset(&tset);
        sigaddset(&tset, SIGTERM);
        sigprocmask(SIG_BLOCK,&tset,NULL);
        while(1) ;
}

But this program correctly blocks the signal.

#include <signal.h>

void handler(int sig) {
        _exit(0);
}

int main()
{
        sigset_t tset;
        sigemptyset(&tset);
        sigaddset(&tset, SIGTERM);
        sigprocmask(SIG_BLOCK,&tset,NULL);
        signal(SIGTERM,handler);
        while(1) ;
}


>Fix:


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: deischen 
State-Changed-When: Thu Jul 26 05:52:06 PDT 2001 
State-Changed-Why:  
In a multithreaded process (our threads library), sigprocmask only changes 
the signal mask for the calling thread.  It doesn't affect the signal mask 
of the _process_.  The only way to block a signal in a multithreaded process 
is to use sigaction() with sa_handler set to SIG_IGN. 

Posix Std 1003.1, 1996 specifies that the behaviour of sigprocmask in a 
multi-threaded process is undefined.  FreeBSD behaviour of sigprocmask 
in a multithreaded process should be similar to that of Solaris, which 
also makes sigprocmask behave the same as pthread_setmask. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=25132 
>Unformatted:
