sshd fails to close open file descriptors when forking

Lutz Jaenicke Lutz.Jaenicke at aet.TU-Cottbus.DE
Mon Oct 22 23:46:22 EST 2001


On Mon, Oct 22, 2001 at 09:36:19AM -0400, Ed Phillips wrote:
> On Sat, 20 Oct 2001, Lutz Jaenicke wrote:
> > The point is: how do you come to your conclusion?
> > daemon() calls dup2() for the file descriptors 0, 1, 2 (stdin, stdout, stderr)
> > and newly assigns them /dev/null. My manual page (HP-UX) says:
> >       dup2() causes fildes2 to refer to the same file as fildes.  If fildes2
> >       refers to an already open file, the open file is closed first.
> > Consequently the open files at 0, 1, 2 are closed.
> > So without further explanation or evidence I consider your bug report
> > to be wrong.
> 
> Actually, my point was, when sshd exits (calls exit() or whatever), no
> matter what file descriptors are open, they'll all get closed as the
> actual process exits.  (But even so, ssh on the other end still hangs...
> potentially depending on which version of ssh you're running...)

I still don't get your point. When sshd exits, all of its file descriptors
are being closed (meaning: they are closed with respect to the exiting
process). If a process has forked and the forked process has the
same file descriptors open, they are still open from the system's point
of view. So what?

Best,
	Lutz
-- 
Lutz Jaenicke                             Lutz.Jaenicke at aet.TU-Cottbus.DE
BTU Cottbus               http://www.aet.TU-Cottbus.DE/personen/jaenicke/
Lehrstuhl Allgemeine Elektrotechnik                  Tel. +49 355 69-4129
Universitaetsplatz 3-4, D-03044 Cottbus              Fax. +49 355 69-4153



More information about the openssh-unix-dev mailing list