All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] bug writing pidfile under unix (and fix)
Date: Tue, 11 Nov 2008 15:05:00 -0600	[thread overview]
Message-ID: <4919F37C.8040203@codemonkey.ws> (raw)
In-Reply-To: <20081107170215.7ca43a08@dgym.ktulu>

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;
>
>
>   

      parent reply	other threads:[~2008-11-11 21:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4919F37C.8040203@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.