From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSZi3-0006Bo-1a for qemu-devel@nongnu.org; Thu, 10 May 2012 16:11:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSZi1-0004UZ-0K for qemu-devel@nongnu.org; Thu, 10 May 2012 16:11:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40471) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSZi0-0004US-O3 for qemu-devel@nongnu.org; Thu, 10 May 2012 16:11:32 -0400 Message-ID: <4FAC20E8.3020006@redhat.com> Date: Thu, 10 May 2012 14:11:20 -0600 From: Eric Blake MIME-Version: 1.0 References: <1336679442-19198-1-git-send-email-lcapitulino@redhat.com> <1336679442-19198-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1336679442-19198-3-git-send-email-lcapitulino@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig485B5544BE818C85F2B4C511" Subject: Re: [Qemu-devel] [PATCH 2/2] qemu-ga: become_daemon(): reopen standard fds to /dev/null List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig485B5544BE818C85F2B4C511 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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. >=20 > 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'): >=20 > 0 -> /dev/vport0p1 > 3 -> /run/qemu-ga.pid >=20 > Then a guest-suspend-* function is issued. They call bios_supports_mode= (), > which will call pipe(), and qemu-ga's fd will be: >=20 > 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. >=20 > Signed-off-by: Luiz Capitulino > --- > qemu-ga.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) >=20 > 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; > } > =20 > - 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 --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enig485B5544BE818C85F2B4C511 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJPrCDoAAoJEKeha0olJ0Nq2E4IAJLuIUi0WMtBnr+vjrHHbllu BeMdM1uBieuqViHAUSo7bSFDj/7mX6Y7a5Ox4fHVcaui7zwyY3nT8yPz0xI9f6Su uCZ35LM/NL1nhMW3rowDpWl1+D/l/b8GYQdL0RpTF4Tp4nK4eqMSGOdiVAgDJCBw DldVUK4amGcQ5NN/Wf2tYePR9Jdl9VAvvtaKTsR/LReZ1F/c4ZpOqJENoHy89X6I NrO7qMY9UoOQ9GLw2AIAu45xls5TXacakkfRfMY9BlHJujAhN7ADqfWQhDonfku1 f8SlocW5xAWak4J+kivh/6aWBr51ECTl4s0EAe3+WeYABFKlZ/sNYN1OOTTGpC0= =X+bP -----END PGP SIGNATURE----- --------------enig485B5544BE818C85F2B4C511--