qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] bug writing pidfile under unix (and fix)


From: Jim Bailey
Subject: [Qemu-devel] bug writing pidfile under unix (and fix)
Date: Fri, 7 Nov 2008 17:02:15 +0000

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.

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;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]