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

Adam Lindberg adam.lindberg at wooga.net
Fri Jun 3 08:18:57 UTC 2016


We are using FreeBSD 10.1 STABLE. We are trying to demonize an Erlang program. Erlang itself has support for detaching but cannot write pidfiles. That’s why we’re trying to use daemon to wrap it.

My experience is also that read works in all cases without a newline, except from inside the rc script. That I cannot explain.

Cheers,
Adam

--
Adam Lindberg | Backend Engineer
Wooga GmbH | Saarbrücker Str. 38 | D-10405 Berlin

Place of business: Berlin
Registered at the local court Berlin-Charlottenburg, HRB 117846 B
Managing Directors: Jens Begemann, Philipp Möser, Jan Miczaika

> On 02 Jun 2016, at 15:56 , Ian Smith <smithi at nimnet.asn.au> wrote:
> 
> 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)
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"



More information about the freebsd-questions mailing list