From owner-freebsd-current@FreeBSD.ORG Thu Oct 13 11:51:28 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 3FCC110656B4; Thu, 13 Oct 2011 11:51:28 +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 D38828FC08; Thu, 13 Oct 2011 11:51:27 +0000 (UTC) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id DC7291FFC33; Thu, 13 Oct 2011 11:51:26 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id C0195B93C; Thu, 13 Oct 2011 13:51:26 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Pawel Jakub Dawidek References: <86pqi1b1qp.fsf@ds4.des.no> <20111013113024.GE1667@garage.freebsd.pl> Date: Thu, 13 Oct 2011 13:51:26 +0200 In-Reply-To: <20111013113024.GE1667@garage.freebsd.pl> (Pawel Jakub Dawidek's message of "Thu, 13 Oct 2011 13:30:26 +0200") Message-ID: <86botlaz41.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: current@freebsd.org Subject: Re: 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 11:51:28 -0000 Pawel Jakub Dawidek writes: > Dag-Erling Sm=C3=B8rgrav writes: > > 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? > I think we already do that internally in pidfile_open(). Can you take a l= ook at > the source and confirm that this is what you mean? No, it doesn't; pidfile_open(3) returns NULL with errno =3D=3D EAGAIN if the pidfile is locked but empty, as is the case in the window between a successful pidfile_open(3) and the first pidfile_write(3). This is documented in the man page: [EAGAIN] Some process already holds the lock on the given pi= d=E2=80=90 file, but the file is truncated. Most likely, the existing daemon is writing new PID into the file. I have a patch that adds a pidfile to dhclient(8), where I do this: for (;;) { pidfile =3D pidfile_open(path_dhclient_pidfile, 0600, &othe= rpid); if (pidfile !=3D NULL || errno !=3D EAGAIN) break; sleep(1); } if (pidfile =3D=3D NULL) { if (errno =3D=3D EEXIST) error("dhclient already running, pid: %d.", otherpi= d); warning("Cannot open or create pidfile: %m"); } I'm not sure I agree with the common idiom (which I copied here) of ignoring all other errors than EEXIST, but that's a different story. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no