From 3005c2c2fa2875a3413af97e9db368856d3330fd Mon Sep 17 00:00:00 2001 From: Yuriy Pudgorodskiy Date: Wed, 6 Apr 2016 08:43:30 +0300 Subject: [PATCH 1/2] qga: fix fd leak with guest-exec i/o channels Signed-off-by: Yuriy Pudgorodskiy Signed-off-by: Denis V. Lunev CC: Michael Roth * squashed in g_io_channel_shutdown() to match cleanup paths for input/output Signed-off-by: Michael Roth --- qga/commands.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qga/commands.c b/qga/commands.c index 95d8b04a16..b653a460b9 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -373,6 +373,7 @@ static gboolean guest_exec_output_watch(GIOChannel *ch, return true; close: + g_io_channel_shutdown(ch, true, NULL); g_io_channel_unref(ch); g_atomic_int_set(&p->closed, 1); return false; @@ -447,6 +448,7 @@ GuestExec *qmp_guest_exec(const char *path, g_io_channel_set_encoding(in_ch, NULL, NULL); g_io_channel_set_buffered(in_ch, false); g_io_channel_set_flags(in_ch, G_IO_FLAG_NONBLOCK, NULL); + g_io_channel_set_close_on_unref(in_ch, true); g_io_add_watch(in_ch, G_IO_OUT, guest_exec_input_watch, &gei->in); } @@ -462,6 +464,8 @@ GuestExec *qmp_guest_exec(const char *path, g_io_channel_set_encoding(err_ch, NULL, NULL); g_io_channel_set_buffered(out_ch, false); g_io_channel_set_buffered(err_ch, false); + g_io_channel_set_close_on_unref(out_ch, true); + g_io_channel_set_close_on_unref(err_ch, true); g_io_add_watch(out_ch, G_IO_IN | G_IO_HUP, guest_exec_output_watch, &gei->out); g_io_add_watch(err_ch, G_IO_IN | G_IO_HUP, From 27559c214d9a16d0ef6164d0c3f6fb45833ba2f9 Mon Sep 17 00:00:00 2001 From: Yuri Pudgorodskiy Date: Wed, 6 Apr 2016 08:43:31 +0300 Subject: [PATCH 2/2] qga: Workaround for console redirection from non-interactive qemu-ga service mingw-glib uses helper process to assist gspawn() api. There are two versions of helpers, one with main() and another with WinMain() startup routines. Whenever gspawn() detects consoleless environment (and qemu-ga is running in such environment as Win32 service), it chooses helper with main() instead of WinMain. It is done by name, e.g. gspawn-win32-helper-console.exe vs gspawn-win32-helper.exe Running console-aware application like any win32 console apps from main() crt initalized process results in redirection of stdout to console created in crt startup instead of parent-provided handle connected to subprocess pipe. Thus, stdout/stderr redirection do not work correctly. The patch makes WinMain()'s version of helper be used as the only helper shipped with qemu-ga package. Using only win32 helper ensures console is created before any redirection and fixes stdout/stderr redirection issue. Signed-off-by: Yuri Pudgorodskiy Signed-off-by: Denis V. Lunev CC: Michael Roth Signed-off-by: Michael Roth --- qga/installer/qemu-ga.wxs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index 7f9289122f..fa2260cafa 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -96,7 +96,7 @@ - + @@ -104,7 +104,7 @@ - +