From owner-freebsd-current@FreeBSD.ORG Thu Mar 14 14:57:28 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 90239766; Thu, 14 Mar 2013 14:57:28 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 619A6265; Thu, 14 Mar 2013 14:57:28 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id A9A52B992; Thu, 14 Mar 2013 10:57:27 -0400 (EDT) From: John Baldwin To: Pawel Jakub Dawidek Subject: Re: pidfile_open incorrectly returns EAGAIN when pidfile is locked Date: Thu, 14 Mar 2013 09:42:40 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p25; KDE/4.5.5; amd64; ; ) References: <513F8D20.2050707@erdgeist.org> <51417C19.9060002@erdgeist.org> <20130314084420.GH1372@garage.freebsd.pl> In-Reply-To: <20130314084420.GH1372@garage.freebsd.pl> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201303140942.40945.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Thu, 14 Mar 2013 10:57:27 -0400 (EDT) Cc: Dirk Engling , freebsd-current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 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, 14 Mar 2013 14:57:28 -0000 On Thursday, March 14, 2013 4:44:20 am Pawel Jakub Dawidek wrote: > On Thu, Mar 14, 2013 at 08:28:25AM +0100, Dirk Engling wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > On 13.03.13 23:08, Pawel Jakub Dawidek wrote: > > > > > I think I considered something similar at first, but the change I > > > proposed was optimal, IMHO at the cost of producing pretty large > > > diff, because of indentation change. But to be sure, can you send a > > > patch of your proposed change? > > > > http://erdgeist.org/arts/software/Code/pidfile.c.diff > > Right. Your patch assumes EWOULDBLOCK is equal to EAGAIN, which is true > on FreeBSD, but is not portable. Also in case pidptr is NULL you compare > errno three times instead of just one (not a big deal of course, just > something that could be done a bit more optimal:)). Geeze, why not just add an else. That's the really short diff: Index: pidfile.c =================================================================== --- pidfile.c (revision 248162) +++ pidfile.c (working copy) @@ -140,7 +140,8 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr = -1; if (errno == 0 || errno == EAGAIN) errno = EEXIST; - } + } else if (errno == EWOULDBLOCK) + errno = EEXIST; free(pfh); return (NULL); } -- John Baldwin