From owner-freebsd-current@FreeBSD.ORG Tue Mar 12 20:16:35 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 7EECDCA2 for ; Tue, 12 Mar 2013 20:16:35 +0000 (UTC) (envelope-from erdgeist@erdgeist.org) Received: from elektropost.org (elektropost.org [217.13.206.130]) by mx1.freebsd.org (Postfix) with ESMTP id BD0E23DA for ; Tue, 12 Mar 2013 20:16:34 +0000 (UTC) Received: (qmail 58471 invoked from network); 12 Mar 2013 20:16:33 -0000 Received: from elektropost.org (HELO elektropost.org) (erdgeist@erdgeist.org) by elektropost.org with CAMELLIA256-SHA encrypted SMTP; 12 Mar 2013 20:16:33 -0000 Message-ID: <513F8D20.2050707@erdgeist.org> Date: Tue, 12 Mar 2013 21:16:32 +0100 From: Dirk Engling User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130216 Thunderbird/17.0.3 MIME-Version: 1.0 To: freebsd-current@freebsd.org Subject: pidfile_open incorrectly returns EAGAIN when pidfile is locked X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: Tue, 12 Mar 2013 20:16:35 -0000 While debugging my own daemon I noticed that pidfile_open does not perform the appropriate checks for a running daemon if the caller does not provide a pidptr to pidfile_open fd = flopen(pfh->pf_path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NONBLOCK, mode); fails when another daemon holds the lock and flopen sets errno to EAGAIN, the check 4 lines below in if (errno == EWOULDBLOCK && pidptr != NULL) { means that the pidfile_read is never executed. This results in my second daemon receiving an EAGAIN which clearly was meant to report a race condition between two daemons starting at the same time and the first one not yet finishing pidfile_write. The expected behavior would be to set errno to EEXIST, even if no pidptr was passed. Regards, erdgeist