Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KyVlJ-0004Yl-Lh for qemu-devel@nongnu.org; Fri, 07 Nov 2008 13:08:49 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KyVlI-0004XZ-Rd for qemu-devel@nongnu.org; Fri, 07 Nov 2008 13:08:49 -0500 Received: from [199.232.76.173] (port=48721 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KyVlI-0004XR-N0 for qemu-devel@nongnu.org; Fri, 07 Nov 2008 13:08:48 -0500 Received: from ey-out-1920.google.com ([74.125.78.144]:48217) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KyVlH-0006aA-Vf for qemu-devel@nongnu.org; Fri, 07 Nov 2008 13:08:48 -0500 Received: by ey-out-1920.google.com with SMTP id 4so591472eyk.4 for ; Fri, 07 Nov 2008 10:08:46 -0800 (PST) Date: Fri, 7 Nov 2008 18:08:42 +0000 From: Jim Bailey Subject: Re: [Qemu-devel] bug writing pidfile under unix (and fix) Message-ID: <20081107180842.6bb1f05b@dgym.ktulu> In-Reply-To: <200811071756.12371.paul@codesourcery.com> References: <20081107170215.7ca43a08@dgym.ktulu> <200811071756.12371.paul@codesourcery.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paul Brook Hi Paul, Opening with O_TRUNC causes a problem. If you try and start qemu again (by accident presumably) it opens the pidfile and then fails to acquire a lock on it. It then exits with a useful message "Could not acquire pidfile" and you know that is has just saved you from trashing your images. If we open the file with O_TRUNC the contents get discarded before the lock is checked, so although a second instance wouldn't run, it would still leave you with an empty pidfile for your still-running first instance. I hope that makes sense. Removing the file on exit would also be a great feature. dgym On Fri, 7 Nov 2008 18:56:11 +0100 Paul Brook wrote: > On Friday 07 November 2008, Jim Bailey wrote: > > Hello, > > > > In qemu_create_pidfile (osdep.c:229) the current pid and a newline is > > written to the pidfile. However, the pidfile isn't truncated, so if it > > is longer than the length of the pid and the newline character you get > > trailing junk that can really mess up scripts. > > Shouldn't we just open with O_TRUNC ? > > I also notice that we're not removing the file when we exit. > > Paul