Subject: Re: race in select() ?
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Charles M. Hannum <abuse@spamalicious.com>
List: tech-kern
Date: 10/09/2003 23:13:53
On Thursday 09 October 2003 10:30 pm, der Mouse wrote:
> >>> [...race conditions in inetd, despite the Subject:...]
> >
> > Pass an actual timeval to select(), with a Really Large Value.  In
> > the SIGCHLD handler, when we restore a socket in the mask, set the
> > timeout to 0.  Handle EWOULDBLOCK by resetting the timeval to the
> > Really Large Value and looping around again.
>
> Wouldn't it be easier and safer to just reap children synchronously, so
> that the SIGCHLD handler does nothing but wake up the main line?

The problem here is entirely in the department of "how to wake up the main 
line," and the various solutions that have been suggested are mainly to 
accomplish that.

I like the "pipe to self" method primarily because it doesn't rely on 
atomicity of *anything* -- it's entirely asynchronous.  Manuel's hack relies 
on the atomicity of a structure copy WRT the signal handler (and therefore 
needs to guarantee that).  My timeval hack relies on the atomicity of the 
system call entry and timeval copy WRT the signal handler.