Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Oct 2010 14:55:30 +0200
From:      Jilles Tjoelker <jilles@stack.nl>
To:        Ed Schouten <ed@80386.nl>
Cc:        freebsd-stable@freebsd.org, ale@FreeBSD.org, Jeremy Chadwick <freebsd@jdc.parodius.com>
Subject:   Re: mysqld_safe holding open a pty/tty on FreeBSD (7.x and 8.x)
Message-ID:  <20101001125530.GA52375@stack.nl>
In-Reply-To: <20100930070333.GU87427@hoeg.nl>
References:  <20100930065151.GA9634@icarus.home.lan> <20100930070333.GU87427@hoeg.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Sep 30, 2010 at 09:03:33AM +0200, Ed Schouten wrote:
> * Jeremy Chadwick <freebsd@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101001125530.GA52375>