Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Feb 2002 22:40:23 -0500 (EST)
From:      Daniel Eischen <eischen@pcnet1.pcnet.com>
To:        callum.gibson@db.com
Cc:        hackers@FreeBSD.ORG
Subject:   Re: pthread_sigmask problem
Message-ID:  <Pine.GSO.4.10.10202042229360.23662-100000@pcnet1.pcnet.com>
In-Reply-To: <20020205020623.75168.qmail@merton.aus.deuba.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 5 Feb 2002 callum.gibson@db.com wrote:
> Hi all,
> I have an application which attempts to block all signals using
> pthread_sigmask(). I'm aware that this only works on the current thread,
> however this call occurs before any other threads are created and so
> should be inherited. I call it as follows:
> 
>     sigset_t signalSet;
> 
>     (void)sigfillset(&signalSet);
>     (void)pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
> 
> However, it seems that signals such as SIGPIPE, SIGINT, etc will still
> kill the process. I also tried replacing the pthread_sigmask call with
> sigprocmask to see if it made any difference, which it didn't.

Yes, at least with FreeBSD pthreads you have to either install a signal
handler to catch these signals or to set the handler to SIG_IGN.  When
you set a threads signal mask, even if it is for all threads, you don't
affect how signals are delivered to the process.  The default action
for SIGPIPE and SIGINT is to kill the process, so setting masks for
threads doesn't affect this.

> The only other relevant info I can think of, is that I start up another
> thread specifically for catching SIGTERM, thusly:
> 
>     (void)sigemptyset(&signalSet);
>     (void)sigaddset(&signalSet, SIGTERM);
>     if (sigwait(&signalSet, &signo) < 0 || signo != SIGTERM)
>     	/* some error handling */;
> 
>     /* shutdown cleanly */
>     etc.
> 
> This part still works as expected.

POSIX explicitly states that if you use sigwait() and there are no
handlers installed, that the effect is as if a handler is installed
for the signal.  So using sigwait() will automagically install a
handler for the signal and then remove it once the sigwait() is
completed (that is, unless the application already installed a handler
for the signal, in which case sigwait doesn't install a handler).

-- 
Dan Eischen


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.10.10202042229360.23662-100000>