Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Sep 2010 00:28:19 -0700
From:      Jeremy Chadwick <freebsd@jdc.parodius.com>
To:        Ed Schouten <ed@80386.nl>
Cc:        freebsd-stable@freebsd.org, ale@FreeBSD.org
Subject:   Re: mysqld_safe holding open a pty/tty on FreeBSD (7.x and 8.x)
Message-ID:  <20100930072819.GA10678@icarus.home.lan>
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:
> Hi Jeremy,
> 
> * 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

Let's try it and find out.  This is all being done from pts/2.

icarus# ps -auxwww -U mysql | grep mysqld_safe
mysql    9997  0.0  0.0  8228  1592   1- I    11:38PM   0:00.01 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/storage/mysql/my.cnf --user=mysql --datadir=/storage/mysql --pid-file=/storage/mysql/icarus.home.lan.pid --skip-innodb

icarus# /usr/local/etc/rc.d/mysql-server stop
Stopping mysql.
Waiting for PIDS: 10078.

icarus# daemon -c -f -u mysql /usr/local/bin/mysqld_safe --defaults-extra-file=/storage/mysql/my.cnf --user=mysql --datadir=/storage/mysql --pid-file=/storage/mysql/icarus.home.lan.pid --skip-innodb

icarus# ps -auxwww -U mysql
USER    PID %CPU %MEM   VSZ   RSS  TT  STAT STARTED      TIME COMMAND
mysql 11036  0.0  0.0  8228  1600  ??  Is   12:21AM   0:00.01 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/storage/mysql/my.cnf --user=mysql --datadir=/storage/mysql --pid-file=/storage/mysql/icarus.home.lan.pid --skip-innodb
mysql 11116  0.0  0.3 35100 11032  ??  I    12:21AM   0:00.02 [mysqld]

icarus# exit
$ exit

[another window, different tty]

icarus# pstat -t | grep pts/2
icarus#

Summary: looks good to me.

> 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.

Ah I see.  Well that would explain the difference between Linux and
FreeBSD then -- it sounds like Linux has a one-off with regards to fds
that point to /dev/null.

> The `pstat -t' command is quite useful to figure out whether there is
> still a session associated with the TTY.
> 
> See the following thread:
> 
> 	http://lists.freebsd.org/pipermail/freebsd-ports/2010-July/062417.html

Ahhh, two people pointing me to the same thread, sweet.  :-)  I wasn't
subscribed to -ports back in July, else I'd almost certainly have said
something then.

It's exactly as you stated in that thread -- the tty is in "G" state
(waiting to be freed/process to exist).  Please note the below output
was obtained *before* attempting the "daemon -cf" stuff you recommended.

icarus# pstat -t | grep pts/1
     pts/1     0    0    0    0     0    0    0     0  9372     0 G

Until rc(8) can be updated to support daemon(8) natively, the ~76 ports
which Do The Wrong Thing(tm) should get updated to do it this way.  Ones
like mysqlXX-server should be placed high on the priority list given
their popularity/importance.

-- 
| Jeremy Chadwick                                   jdc@parodius.com |
| Parodius Networking                       http://www.parodius.com/ |
| UNIX Systems Administrator                  Mountain View, CA, USA |
| Making life hard for others since 1977.              PGP: 4BD6C0CB |




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