From owner-freebsd-questions@freebsd.org Thu May 26 10:10:26 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 A6794B4A314 for ; Thu, 26 May 2016 10:10:26 +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 E4E6019A2 for ; Thu, 26 May 2016 10:10:24 +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 u4QAADAm098263; Thu, 26 May 2016 20:10:14 +1000 (EST) (envelope-from smithi@nimnet.asn.au) Date: Thu, 26 May 2016 20:10:13 +1000 (EST) From: Ian Smith To: RW cc: Adam Lindberg , freebsd-questions@freebsd.org Subject: Re: Pidfile generated by /usr/sbin/daemon not usable by rc.d script In-Reply-To: Message-ID: <20160526193917.C15883@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, 26 May 2016 10:10:26 -0000 In freebsd-questions Digest, Vol 625, Issue 4, Message: 19 On Wed, 25 May 2016 20:26:56 +0100 RW wrote: > On Wed, 25 May 2016 17:12:36 +0200 > Adam Lindberg wrote: > > > Hi, > > > > I don?t know what powerd is and how it factors into this. :-) > > It's an example of a daemon that generates a pid file without a > newline, and yet "stop" and "status" work. > > It turns out that /etc/rc.d/powerd doesn't define pidfile, in which > case rc.subr finds the pid from the output of ps. So it's not a > counter-example and it does appear to be a bug that rc.subr can't cope > with a pid file without a newline. > > You could use the same method, but using sed seems safer. Just as another data point, from a 9.3 system (if relevant), where the majority of pidfiles have no trailing newline; no obvious consistency: root@x200:~ # sh -c 'for i in /var/run/*.pid ; do echo $i; hd $i; done' /var/run/consolekit.pid 00000000 39 31 31 0a |911.| 00000004 /var/run/cron.pid 00000000 38 35 31 |851| 00000003 /var/run/devd.pid 00000000 34 32 37 |427| 00000003 /var/run/dhclient.em0.pid 00000000 33 34 38 |348| 00000003 /var/run/moused.pid 00000000 37 31 39 |719| 00000003 /var/run/ntpd.pid 00000000 36 39 32 |692| 00000003 /var/run/powerd.pid 00000000 36 39 35 |695| 00000003 /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| 00000010 6e 64 6d 61 69 6c 20 2d 4c 20 73 6d 2d 6d 74 61 |ndmail -L sm-mta| 00000020 20 2d 62 64 20 2d 71 33 30 6d 20 2d 4f 44 61 65 | -bd -q30m -ODae| 00000030 6d 6f 6e 50 6f 72 74 4f 70 74 69 6f 6e 73 3d 41 |monPortOptions=A| 00000040 64 64 72 3d 6c 6f 63 61 6c 68 6f 73 74 0a |ddr=localhost.| 0000004e /var/run/sshd.pid 00000000 38 30 31 0a |801.| 00000004 /var/run/syslog.pid 00000000 35 39 30 |590| 00000003 check_pidfile in /etc/rc.subr (at 9.3 and in head I see) uses: read _pid _junk < $_pidfile which extracts pids ok with or without the newline. Don't suppose the behaviour of read in sh(1) might have changed in terms of separating words or in whitespace reckoning? Otherwise this is rather mysterious. cheers, Ian