qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] qemu-ga: become_daemon(): reopen standard fds to /dev/null
Date: Thu, 10 May 2012 14:11:20 -0600	[thread overview]
Message-ID: <4FAC20E8.3020006@redhat.com> (raw)
In-Reply-To: <1336679442-19198-3-git-send-email-lcapitulino@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1827 bytes --]

On 05/10/2012 01:50 PM, Luiz Capitulino wrote:
> This fixes a bug where qemu-ga doesn't suspend the guest because it
> fails to detect suspend support even when the guest does support
> suspend. This happens because of the way qemu-ga fds are managed in
> daemon mode.
> 
> When starting qemu-ga with --daemon, become_daemon() will close all
> standard fds. This will cause qemu-ga to end up with the following
> fds (if started with 'qemu-ga --daemon'):
> 
>     0 -> /dev/vport0p1
>     3 -> /run/qemu-ga.pid
> 
> Then a guest-suspend-* function is issued. They call bios_supports_mode(),
> which will call pipe(), and qemu-ga's fd will be:
> 
>     0 -> /dev/vport0p1
>     1 -> pipe:[16247]
>     2 -> pipe:[16247]
>     3 -> /run/qemu-ga.pid

Very nasty.


> To solve this problem we have to reopen standard fds to /dev/null
> in become_daemon(), instead of closing them.

Yes, POSIX warns that applications should never call exec() with fd 0,
1, or 2 closed, at least not if the application wants the child to
behave in a conforming environment.

> 
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  qemu-ga.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/qemu-ga.c b/qemu-ga.c
> index 7896565..c64bc71 100644
> --- a/qemu-ga.c
> +++ b/qemu-ga.c
> @@ -445,9 +445,9 @@ static void become_daemon(const char *pidfile)
>          goto fail;
>      }
>  
> -    close(STDIN_FILENO);
> -    close(STDOUT_FILENO);
> -    close(STDERR_FILENO);
> +    reopen_fd_to_null(STDIN_FILENO);
> +    reopen_fd_to_null(STDOUT_FILENO);
> +    reopen_fd_to_null(STDERR_FILENO);

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

  reply	other threads:[~2012-05-10 20:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-10 19:50 [Qemu-devel] [PATCH 0/2]: qemu-ga: Fix fd handling in daemon mode Luiz Capitulino
2012-05-10 19:50 ` [Qemu-devel] [PATCH 1/2] qemu-ga: make reopen_fd_to_null() public Luiz Capitulino
2012-05-10 20:14   ` Eric Blake
2012-05-10 19:50 ` [Qemu-devel] [PATCH 2/2] qemu-ga: become_daemon(): reopen standard fds to /dev/null Luiz Capitulino
2012-05-10 20:11   ` Eric Blake [this message]
2012-05-11 22:02 ` [Qemu-devel] [PATCH 0/2]: qemu-ga: Fix fd handling in daemon mode Michael Roth

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=4FAC20E8.3020006@redhat.com \
    --to=eblake@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --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 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).