so-called-hang-on-exit

Jani Jaakkola jjaakkol at cs.Helsinki.FI
Thu Aug 8 06:17:33 EST 2002


On Wed, 7 Aug 2002 Nicolas.Williams at ubsw.com wrote:

> 
> A test program *could* be written. The test should try several
> conditions to determine what the kernel/pty driver behaviour is:
> 
>  - does the pty close immediately when the session leader exits?
>  - does the pty close immediately when the session leader is gone *and*
>    the pty's foreground process group is orphaned (or empty?)?
>  - does the pty driver send SIGHUP to all processes associated with the
>    PTY when the session leader exits?

Why? I just want to patch sshd so that it does not matter what the exact 
underlying pty semantics are.

> Having the answers to these questions for each of the major platforms we
> can then think about how to emulate *BSD behaviour on Linux and Solaris
> (assuming that it's even desired). But then, we all pretty much suspect
> what the behaviour is (see previous posts in this thread).

Indeed. I would say that we know the problem. And we have presented 
the fix.

> The notion of "flushing the pty" may not be so simple because the
> boundary between data last written by the session leader and data
> written by background processes may be indistiguishable (would that
> even be a problem?)

In Linux the boundary is indistinguishable and that is not a problem.
How could it be problem?

AFAIK, OpenBSD kernel already decides that it is not a problem. Otherwise 
it could not possibly close the pty from under the background processes.

 - how does one "flush the pty" from the master
> side anyways? (by reading until read() returns EWOULDBLOCK? or is there
> some special ioctl() for emptying buffered data on the slave write side
> to the master read side?)

By read() or select(), as the patches provided demonstrate. I don't see 
any need for any ioctl().

> And one more avenue that must be considered: why not just document the
> platform differences and leave it at that? Some will be inconvenienced,
> but the OpenSSH folks could just say "hey, take it to your OS vendor", say.

Linux kernel behaviour gives the user space the option to choose, whether
(1) to throw away the output from background processes, or to (2) wait 
until all background processes are finished. 

AFAIK, OpenBSD does not provide option (2) at all. 

I could patch Linux kernel instead, but then the kernel would be worse, 
not better.

- Jani




More information about the openssh-unix-dev mailing list