qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: become_daemon(): reopen standard f


From: Eric Blake
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
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

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 <address@hidden>
> ---
>  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 <address@hidden>

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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