Subject: Re: port-sparc64/29824
To: Matthias Scheler <tron@zhadum.de>
From: Chuck Silvers <chuq@chuq.com>
List: netbsd-bugs
Date: 05/02/2005 08:06:04
On Sun, May 01, 2005 at 10:44:20PM +0100, Matthias Scheler wrote:
> On Sun, May 01, 2005 at 02:37:17PM -0700, Chuck Silvers wrote:
> > > Responsible-Changed-From-To: xsrc-manager->port-sparc64-maintainer
> > > Responsible-Changed-By: tron@netbsd.org
> > > Responsible-Changed-When: Sun, 01 May 2005 18:14:03 +0000
> > > Responsible-Changed-Why:
> > > 1.) XFree86's signal handling code does *not* cause this. It will not
> > >     unblock SIGIO from a the SIGIO signal handler.
> > 
> > I just read the code again, it sure looks like it does to me.
> > the call stack in the initial PR comments looks like it could really happen.
> 
> How?

sorry, I misread your comment.  you're right that it does not unblock
SIGIO in the SIGIO handler, but that's not the problem.  just calling
sigprocmask() in a signal handler is not safe, at least with our pthreads
implementation.   I looked briefly for any mention in our manpages of
what library functions are or are not safe to call in a signal handler,
but I didn't find it.

-Chuck


> 1.) xf86BlockSIGIO() returns whether the signal has been blocked before:
> 
> int
> xf86BlockSIGIO (void)
> {
>     sigset_t    set, old;
> 
>     sigemptyset (&set);
>     sigaddset (&set, SIGIO);
>     sigprocmask (SIG_BLOCK, &set, &old);
>     return sigismember (&old, SIGIO);
> }
> 
> 2.) xf86SigioReadInput() remembers that flag and passed it to
>     xf86UnblockSIGIO():
> 
> static void
> xf86SigioReadInput(int fd,
>                    void *closure)
> {
>     int sigstate = xf86BlockSIGIO();
> [...]
>     xf86UnblockSIGIO(sigstate);
> }
> 
> 3.) void xf86UnblockSIGIO() only unblocks the signal if it has not been
>     blocked before:
> 
> void
> xf86UnblockSIGIO (int wasset)
> {
>     sigset_t    set;
> 
>     if (!wasset)
>     {
>         sigemptyset (&set);
>         sigaddset (&set, SIGIO);
>         sigprocmask (SIG_UNBLOCK, &set, NULL);
>     }
> }
> 
> That looks safe to me.
> 
> 	Kind regards
> 
> -- 
> Matthias Scheler                                  http://scheler.de/~matthias/