From owner-freebsd-current@FreeBSD.ORG Thu Oct 13 10:54:40 2011 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B61DE1065692; Thu, 13 Oct 2011 10:54:40 +0000 (UTC) (envelope-from des@des.no) Received: from smtp.des.no (smtp.des.no [194.63.250.102]) by mx1.freebsd.org (Postfix) with ESMTP id 7DA078FC0A; Thu, 13 Oct 2011 10:54:40 +0000 (UTC) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id D0BC51FFC33; Thu, 13 Oct 2011 10:54:38 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id B873DB93C; Thu, 13 Oct 2011 12:54:38 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: current@freebsd.org Date: Thu, 13 Oct 2011 12:54:38 +0200 Message-ID: <86pqi1b1qp.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: pjd@freebsd.org Subject: incorrect use of pidfile(3) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Oct 2011 10:54:40 -0000 I looked at some of the programs that use pidfile(3) in base, and they pretty much all get it wrong. Consider these two scenarios: 1) common case process A process B main() pidfile_open() -> success perform_initialization() daemon() pidfile_write() -> success perform_work() main() pidfile_open() -> EEXIST exit() 2) very unlikely but still possible case process A process B main() pidfile_open() -> success main() perform_initialization() pidfile_open() -> EAGAIN daemon() perform_initialization() pidfile_write() -> success daemon() perform_work() perform_work() The problem is that most of them (at least the ones I checked) ignore a pidfile_open() failure unless errno =3D=3D EEXIST. How do we fix this? My suggestion is to loop until pidfile_open() succeeds or errno !=3D EAGAIN. Does anyone have any objections to that approach? DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no