mysqld_safe holding open a pty/tty on FreeBSD (7.x and 8.x)

Jilles Tjoelker jilles at stack.nl
Fri Oct 1 12:55:32 UTC 2010


On Thu, Sep 30, 2010 at 09:03:33AM +0200, Ed Schouten wrote:
> * Jeremy Chadwick <freebsd at jdc.parodius.com> wrote:
> > 1) "mysqld_safe > /dev/null 2>&1 &" never released the tty
> > 2) "nohup mysqld_safe > /dev/null 2>&1 &" did release the tty

> What happens if you run the following command?

> 	daemon -cf mysqld_safe

> The point is that FreeBSD's pts(4) driver only deallocates TTYs when
> it's really sure nothing uses it anymore. Even if there is not a single
> file descriptor referring to the slave device, it has to wait until
> there exist no processes which have the TTY as its controlling TTY.

In fact, POSIX allows dissociating the controlling terminal from the
session when all file descriptors for it (in any session) have been
closed. See SUSv4 XBD 11.1.3 The Controlling Terminal. Once the terminal
has been dissociated, it is no longer in use at all and can, in case of
a pty, be cleaned up. Implementing this may be an interesting idea. Of
course, this will cause opening /dev/tty to fail in some cases where it
previously succeeded, but it seems uncommon.

Somewhat unrelated, I think that starting daemons with daemon(8),
</dev/null >/dev/null 2>&1 or similar is inferior to implementing
daemonizing in the program itself. Think of the poor soul who needs to
install and start N daemons full of bugs and configuration errors: it is
better if such errors show up on the console instead of being hidden
away in a log file.

-- 
Jilles Tjoelker


More information about the freebsd-stable mailing list