From: Eric Blake <eblake@redhat.com>
To: Florian Larysch <fl@n621.de>, qemu-devel@nongnu.org
Cc: sw@weilnetz.de
Subject: Re: [Qemu-devel] [PATCH v2] os: truncate pidfile on creation
Date: Tue, 20 Mar 2018 12:27:12 -0500 [thread overview]
Message-ID: <ca91c5dc-6ef8-773f-9ee5-6cf8d0bedcce@redhat.com> (raw)
In-Reply-To: <20180320165855.23258-1-fl@n621.de>
On 03/20/2018 11:58 AM, Florian Larysch wrote:
> qemu_create_pidfile does not truncate the pidfile when it creates it,
> but rather overwrites its contents with the new pid. This works fine as
> long as the length of the pid doesn't decrease, but this might happen in
> case of wraparounds, causing pidfiles to contain trailing garbage which
> breaks operations such as 'kill $(cat pidfile)'.
>
> Instead, always truncate the file before writing it.
>
> Note that the order is important here: We cannot simply use O_TRUNC in
> the open() call because another qemu process might truncate the pidfile
> of a process that is still running before reaching the lockf() barrier.
>
> The Windows version suffers from a similar problem, but as it does not
> provide effective mutual exclusion anyway (because the file handle is
> closed immediately after writing to it), adopting this behavior still
> seems to be an improvement, as it at least prevents garbeled pidfiles.
s/garbeled/garbled/
>
> Signed-off-by: Florian Larysch <fl@n621.de>
> ---
> os-posix.c | 6 ++++++
> os-win32.c | 2 +-
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
prev parent reply other threads:[~2018-03-20 17:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-20 16:58 [Qemu-devel] [PATCH v2] os: truncate pidfile on creation Florian Larysch
2018-03-20 17:27 ` Eric Blake [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=ca91c5dc-6ef8-773f-9ee5-6cf8d0bedcce@redhat.com \
--to=eblake@redhat.com \
--cc=fl@n621.de \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/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 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).