From owner-freebsd-questions@freebsd.org Thu Jun 2 13:57:01 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 92915B61CD3 for ; Thu, 2 Jun 2016 13:57:01 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D65A614B8 for ; Thu, 2 Jun 2016 13:57:00 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id u52DulAt052949; Thu, 2 Jun 2016 23:56:48 +1000 (EST) (envelope-from smithi@nimnet.asn.au) Date: Thu, 2 Jun 2016 23:56:47 +1000 (EST) From: Ian Smith To: RW cc: freebsd-questions@freebsd.org Subject: Re: Pidfile generated by /usr/sbin/daemon not usable by rc.d script In-Reply-To: Message-ID: <20160602230511.W15883@sola.nimnet.asn.au> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Jun 2016 13:57:01 -0000 In freebsd-questions Digest, Vol 626, Issue 4, Message: 3 On Wed, 1 Jun 2016 15:08:19 +0100 RW 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@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)