Subject: Re: race in select() ?
To: None <tech-kern@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 10/09/2003 18:30:11
>>> [...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?
(Since there is no syscall that combines sigprocmask+select, the only
race-free ways I can see of doing this are (1) the "pipe to itself"
trick and (2) mycroft's suggestion, quoted above.  I think (1) is
better, if only because it doesn't introduce new race conditions on
systems where select() is a userland (and therefore interruptible)
wrapper around something else, like poll().  Unless we don't care about
our inetd working on such systems, of course.)

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B