qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] bug writing pidfile under unix (and fix)
@ 2008-11-07 17:02 Jim Bailey
  2008-11-07 17:56 ` Paul Brook
  2008-11-11 21:05 ` Anthony Liguori
  0 siblings, 2 replies; 6+ messages in thread
From: Jim Bailey @ 2008-11-07 17:02 UTC (permalink / raw)
  To: qemu-devel

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;

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-11-11 21:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-07 17:02 [Qemu-devel] bug writing pidfile under unix (and fix) Jim Bailey
2008-11-07 17:56 ` Paul Brook
2008-11-07 18:08   ` Jim Bailey
2008-11-07 20:15   ` Anthony Liguori
2008-11-07 20:33     ` Jim Bailey
2008-11-11 21:05 ` Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).