Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 06 Dec 2018 03:58:43 +0000
From:      bugzilla-noreply@freebsd.org
To:        ports-bugs@FreeBSD.org
Subject:   [Bug 233820] databases/postgresql96-server: holds a pty unnecessarily
Message-ID:  <bug-233820-7788@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D233820

            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@FreeBSD.org
          Reporter: jdc@koitsu.org
             Flags: maintainer-feedback?(pgsql@FreeBSD.org)
          Assignee: pgsql@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 was=
ted
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, w=
hen
starting the daemon. There are other example ports which use daemon(8) if t=
he
maintainer is unfamiliar with it; I believe databases/mysql*-server is a go=
od
example:

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

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

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=
=20=20=20=20=20
0 rw
postgres postgres   66606    6* pipe fffff80008912758 <-> fffff800089125f0=
=20=20=20=20=20
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=3D"yes"
postgresql_data=3D"/postgresql"

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



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