From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:46618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rqhaw-0000uC-Po for qemu-devel@nongnu.org; Fri, 27 Jan 2012 03:55:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rqhav-0002KE-Fh for qemu-devel@nongnu.org; Fri, 27 Jan 2012 03:55:42 -0500 Message-ID: <4F2266D8.2020502@redhat.com> Date: Fri, 27 Jan 2012 09:56:56 +0100 From: Laszlo Ersek MIME-Version: 1.0 References: <1327613801-5828-1-git-send-email-lersek@redhat.com> <20120127063639.GA22748@stefanha-thinkpad.localdomain> In-Reply-To: <20120127063639.GA22748@stefanha-thinkpad.localdomain> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH] keep the PID file locked for the lifetime of the process List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org On 01/27/12 07:36, Stefan Hajnoczi wrote: > On Thu, Jan 26, 2012 at 10:36:41PM +0100, Laszlo Ersek wrote: >> The lockf() call in qemu_create_pidfile() aims at ensuring mutual >> exclusion. We shouldn't close the pidfile on success, because that drops >> the lock as well [1]: >> >> "File locks shall be released on first close by the locking process >> of any file descriptor for the file." >> >> Coverity may complain again about the leaked file descriptor; let's >> worry about that later. >> >> [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html >> >> Signed-off-by: Laszlo Ersek >> --- > > Isn't the normal way to do pidfiles O_CREAT | O_EXCL? Yes, it is. > It may not work > on all NFS versions but putting the pidfile on NFS doesn't really make > sense. > > Then we can drop the lockf(3) completely. When you rely on O_EXCL to ensure mutual exclusion, and an abruptly terminated process leaves the lockfile lying around, then the user has to clean it up manually before starting the next instance (and double check if the pid file is in fact stale or not). I'm personally OK with that, but I reckoned the qemu code tried to avoid that intentionally. Record locks can't remain stale when the process dies. Laszlo