Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Jun 2016 10:18:53 +0200
From:      Adam Lindberg <adam.lindberg@wooga.net>
To:        Ian Smith <smithi@nimnet.asn.au>
Cc:        RW <rwmaillists@googlemail.com>, freebsd-questions@freebsd.org
Subject:   Re: Pidfile generated by /usr/sbin/daemon not usable by rc.d script
Message-ID:  <5C74A843-C2EB-424B-9254-0CD68A07E480@wooga.net>
In-Reply-To: <20160602230511.W15883@sola.nimnet.asn.au>
References:  <mailman.75.1464870067.82158.freebsd-questions@freebsd.org> <20160602230511.W15883@sola.nimnet.asn.au>

next in thread | previous in thread | raw e-mail | index | archive | help
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=E2=80=99s why we=E2=80=99re 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=C3=BCcker 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=C3=B6ser, Jan Miczaika

> On 02 Jun 2016, at 15:56 , Ian Smith <smithi@nimnet.asn.au> wrote:
>=20
> In freebsd-questions Digest, Vol 626, Issue 4, Message: 3
> On Wed, 1 Jun 2016 15:08:19 +0100 RW <rwmaillists@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'?
>>=20
>> 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.=20
>=20
> Ah right, fair enough and thanks.
>=20
>>> For one thing, it seems that daemon keeps the -p pidfile locked
>>> during execution of the process; might that affect service status,
>>> stop, etc?
>>=20
>> I think the problem is pretty straightforward. If you run this
>>=20
>>  read _pid _junk < $_pidfile
>>=20
>> 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.
>=20
> But it doesn't wait on 9.3 stable of last October at least with this=20=

> small set of pidfiles, some with & some without trailing newline, =
thus:
>=20
> % 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
>=20
> root@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
>=20
> No ptoblem interactively either; one of each (that non-root can read):
>=20
> $ read _pid _junk < /var/run/ntpd.pid
> $ echo $_pid
> 692
> $ echo $_junk
>=20
> $ read _pid _junk < /var/run/sshd.pid
> $ echo $_pid
> 801
> $ echo $_junk
>=20
> So maybe this issue is something new(er) in FreeBSD somewhere?
>=20
> cheers, Ian  (please cc me, digests can take a day)
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to =
"freebsd-questions-unsubscribe@freebsd.org"




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5C74A843-C2EB-424B-9254-0CD68A07E480>