[Bug 233820] databases/postgresql96-server: holds a pty unnecessarily

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Thu Dec 6 03:58:50 UTC 2018


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=233820

            Bug ID: 233820
           Summary: databases/postgresql96-server: holds a pty
                    unnecessarily
           Product: Ports & Packages
           Version: Latest
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: Individual Port(s)
          Assignee: pgsql at FreeBSD.org
          Reporter: jdc at koitsu.org
             Flags: maintainer-feedback?(pgsql at FreeBSD.org)
          Assignee: pgsql at FreeBSD.org

It appears that databases/postgresql96-server's rc.d script starts pgsql
directly (via su(1)), rather than using daemon(8).  The result can be a wasted
pty due to the lack of redirecting stdout and stderr prior to process start, if
the daemon is started from an interactive shell directly.  That pty also
continues to hold the username/uid of whomever started postgres itself.

Issue likely affects other versions of databases/postgresql*-server.

Solution:

daemon(8) should be used instead of su(1), particularly with the -f flag, when
starting the daemon. There are other example ports which use daemon(8) if the
maintainer is unfamiliar with it; I believe databases/mysql*-server is a good
example:

https://svnweb.freebsd.org/ports/head/databases/mysql80-server/files/mysql-server.in?revision=466508&view=markup

You may also find additional flags (such as -u to setuid() in advance) useful.

Evidence:

Confirmed on stable/11 (r339174).  Note that fd 1 (stdout) and fd 2 (stderr)
are still being held open and are not /dev/null; pts/0 is being "held" by
postgresql.

$ w
 7:43PM  up 51 days, 19:17, 1 user, load averages: 2.08, 2.10, 2.08
USER       TTY      FROM                                      LOGIN@  IDLE WHAT
jdc        pts/0    koitsu                                    7:43PM     - w
$ sudo service postgresql stop
$ sudo service postgresql start
LOG:  ending log output to stderr
HINT:  Future log output will go to log destination "syslog".
$ ls -l /dev/pts
total 0
crw--w----    1 jdc       tty       0x61 Dec  5 19:44 0
$ logout
{closes session}
{open new session}
$ w
 7:44PM  up 51 days, 19:18, 1 user, load averages: 2.02, 2.08, 2.07
USER       TTY      FROM                                      LOGIN@  IDLE WHAT
jdc        pts/1    XXXXXX                                    7:44PM     - w
$ ls -l /dev/pts
total 0
crw--w----    1 jdc       tty       0x61 Dec  5 19:44 0
crw--w----    1 jdc       tty       0x63 Dec  5 19:44 1
$ sudo pgrep -a -S -t 0
66606
$ ps -auxw | grep 66606
postgres 66606   0.0  0.3 167640  28648  0- S    19:43        0:00.03
/usr/local/bin/postgres -D /postgresql
jdc      66709   0.0  0.0   6640   2476  1  R+   19:45        0:00.00 grep
66606
$ sudo fstat -p 66606
USER     CMD          PID   FD MOUNT      INUM MODE         SZ|DV R/W
postgres postgres   66606 text /        12771700 -rwxr-xr-x  6285760  r
postgres postgres   66606   wd /postgresql      4 drwx------      29  r
postgres postgres   66606 root /             2 drwxr-xr-x     512  r
postgres postgres   66606    0 /dev         28 crw-rw-rw-    null  r
postgres postgres   66606    1 -         -         bad    -
postgres postgres   66606    2 -         -         bad    -
postgres postgres   66606    3* internet stream tcp fffff800214fe000
postgres postgres   66606    4* local stream fffff800402bc4b0
postgres postgres   66606    5* pipe fffff800089125f0 <-> fffff80008912758     
0 rw
postgres postgres   66606    6* pipe fffff80008912758 <-> fffff800089125f0     
0 rw
postgres postgres   66606    7* local dgram fffff80011d4a2d0 <->
fffff80011cd1780
postgres postgres   66606    8* internet dgram udp fffff800119b6910

Other irrelevant details:

$ grep postgresql /etc/rc.conf
postgresql_enable="yes"
postgresql_data="/postgresql"

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-ports-bugs mailing list