SIGCHLD race *trivial* patch

Nicolas Williams Nicolas.Williams at
Fri Oct 26 11:21:02 EST 2001

1. my patch doesn't really fix the race -- signal blocking is needed for
   that. Sigh.

2. I think the normal expectation is that when there are no more open
   sessions or channels or children that sshd should exit. The opposite
   ought to be an option. IMHO

3. If sshd is to exit when (no more sessions && no more channels && no
   more children) then either you must use a select() timeout, at least
   when (no more sessions && no more channels), or sshd must use the
   signal-handler-writes-to-a-pipe-whose-read-end-is-selected-for trick,
   as described in the "SIGCHLD race condition race?" thread by Paul



On Thu, Oct 25, 2001 at 11:12:28PM +0200, Markus Friedl wrote:
> On Thu, Oct 25, 2001 at 03:25:22PM -0400, Nicolas Williams wrote:
> >       if (!channel_still_open())
> >               max_time_milliseconds = 1000;
> there are no channels when a client authenticates.
> just try ssh -N
> > 
> >    Added this bit of code to server_loop2():
> > 
> >                 if (child_terminated) {
> >                         while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
> >                                 session_close_by_pid(pid, status);
> > -                       child_terminated = 0;
> > +                       if (session_still_used())
> > +                               child_terminated = 0;
> > +                    if (child_terminated && !channel_still_open())
> > +                       break;
> 			^^^^^
> you cannot break. the client decides when the connection gets closed.
> i think it could still request another login shell.
> but yes, the SIGCLD races could be fixed with a select timeout.
> but that's ugly. perhaps using siglongjmp is less ugly
> and even portable.
> -m

Visit our website at

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.

More information about the openssh-unix-dev mailing list