From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L00Q9-0004N6-9K for qemu-devel@nongnu.org; Tue, 11 Nov 2008 16:05:09 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L00Q7-0004LZ-QN for qemu-devel@nongnu.org; Tue, 11 Nov 2008 16:05:08 -0500 Received: from [199.232.76.173] (port=50807 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L00Q7-0004LM-Ap for qemu-devel@nongnu.org; Tue, 11 Nov 2008 16:05:07 -0500 Received: from an-out-0708.google.com ([209.85.132.240]:13545) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L00Q6-0006hV-TQ for qemu-devel@nongnu.org; Tue, 11 Nov 2008 16:05:07 -0500 Received: by an-out-0708.google.com with SMTP id c38so46482ana.37 for ; Tue, 11 Nov 2008 13:05:04 -0800 (PST) Message-ID: <4919F37C.8040203@codemonkey.ws> Date: Tue, 11 Nov 2008 15:05:00 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] bug writing pidfile under unix (and fix) References: <20081107170215.7ca43a08@dgym.ktulu> In-Reply-To: <20081107170215.7ca43a08@dgym.ktulu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed 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 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. > > I noticed this when going from a 5 digit pid to a 3 digit pid, so it > can happen in regular operation, especially if the OS randomizes pids. > > Truncating the file fixes the bug. > Needs a Signed-off-by. Regards, Anthony Liguori > dgym > > > *** osdep.c.orig Fri Nov 7 16:56:12 2008 > --- osdep.c Fri Nov 7 16:58:49 2008 > *************** > *** 236,241 **** > --- 236,243 ---- > len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid()); > if (write(fd, buffer, len) != len) > return -1; > + > + ftruncate(fd, len); > #else > HANDLE file; > DWORD flags; > > >