Pidfile generated by /usr/sbin/daemon not usable by rc.d script

Ian Smith smithi at nimnet.asn.au
Thu Jun 2 13:57:01 UTC 2016


In freebsd-questions Digest, Vol 626, Issue 4, Message: 3
On Wed, 1 Jun 2016 15:08:19 +0100 RW <rwmaillists at googlemail.com> wrote:
 > On Wed, 1 Jun 2016 22:58:28 +1000 (EST)
 > Ian Smith wrote:
[..]
 > > Also, none of the others (here) need daemon(8) to run, in background
 > > or otherwise .. are you sure that you require its functionality for
 > > 'foo'?
 > 
 > Most daemons were written as such.  daemon(8) is there for those that
 > weren't or were written in a scripting language that doesn't support
 > the double fork. 

Ah right, fair enough and thanks.

 > > For one thing, it seems that daemon keeps the -p pidfile locked
 > > during execution of the process; might that affect service status,
 > > stop, etc?
 > 
 > I think the problem is pretty straightforward. If you run this
 > 
 >   read _pid _junk < $_pidfile
 > 
 > and $_pidfile doesn't end in a newline, read will wait for one, just as
 > it would if you typed in a line and didn't hit return.

But it doesn't wait on 9.3 stable of last October at least with this 
small set of pidfiles, some with & some without trailing newline, thus:

% cat ~/bin/pidtest.sh
#!/bin/sh
# 2/6/16 re RW's msg in questions@
for _pidfile in /var/run/*.pid; do
        echo $_pidfile
        hd $_pidfile | head -1
        read _pid _junk < $_pidfile
        echo "_pid: '$_pid' _junk: '$_junk'"
done
echo done

root at x200:~ # pidtest.sh
/var/run/consolekit.pid
00000000  39 31 31 0a                                       |911.|
_pid: '911' _junk: ''
/var/run/cron.pid
00000000  38 35 31                                          |851|
_pid: '851' _junk: ''
/var/run/devd.pid
00000000  34 32 37                                          |427|
_pid: '427' _junk: ''
/var/run/dhclient.em0.pid
00000000  33 34 38                                          |348|
_pid: '348' _junk: ''
/var/run/moused.pid
00000000  37 31 39                                          |719|
_pid: '719' _junk: ''
/var/run/ntpd.pid
00000000  36 39 32                                          |692|
_pid: '692' _junk: ''
/var/run/powerd.pid
00000000  36 39 35                                          |695|
_pid: '695' _junk: ''
/var/run/sendmail.pid
00000000  38 32 34 0a 2f 75 73 72  2f 73 62 69 6e 2f 73 65  |824./usr/sbin/se|
_pid: '824' _junk: ''
/var/run/sshd.pid
00000000  38 30 31 0a                                       |801.|
_pid: '801' _junk: ''
/var/run/syslog.pid
00000000  35 39 30                                          |590|
_pid: '590' _junk: ''
done

No ptoblem interactively either; one of each (that non-root can read):

$ read _pid _junk < /var/run/ntpd.pid
$ echo $_pid
692
$ echo $_junk

$ read _pid _junk < /var/run/sshd.pid
$ echo $_pid
801
$ echo $_junk

So maybe this issue is something new(er) in FreeBSD somewhere?

cheers, Ian  (please cc me, digests can take a day)


More information about the freebsd-questions mailing list