| Submitter | Michael Roth |
|---|---|
| Date | Jan. 21, 2012, 1:08 a.m. |
| Message ID | <1327108107-16600-1-git-send-email-mdroth@linux.vnet.ibm.com> |
| Download | mbox | patch |
| Permalink | /patch/137132/ |
| State | New |
| Headers | show |
Comments
On 01/21/2012 02:08 AM, Michael Roth wrote: > The __attribute__((constructor)) init_main_loop() automatically get > called if qemu-tool.o is linked in. On win32, this leads to > a qemu_notify_event() call which attempts to SetEvent() on a HANDLE that > won't be initialized until qemu_init_main_loop() is manually called, > breaking qemu-tools.o programs on Windows at runtime. > > This patch checks for an initialized event handle before attempting to > set it, which is analoguous to how we deal with an unitialized > io_thread_fd in the posix implementation. > > Signed-off-by: Michael Roth<mdroth@linux.vnet.ibm.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Paolo
On Fri, Jan 20, 2012 at 07:08:27PM -0600, Michael Roth wrote: > diff --git a/main-loop.c b/main-loop.c > index 692381c..62d95b9 100644 > --- a/main-loop.c > +++ b/main-loop.c > @@ -164,7 +164,7 @@ static int qemu_signal_init(void) > > #else /* _WIN32 */ > > -HANDLE qemu_event_handle; > +HANDLE qemu_event_handle = NULL; Global variables are automatically zeroed, no need to assign NULL.
On 01/20/2012 07:08 PM, Michael Roth wrote: > The __attribute__((constructor)) init_main_loop() automatically get > called if qemu-tool.o is linked in. On win32, this leads to > a qemu_notify_event() call which attempts to SetEvent() on a HANDLE that > won't be initialized until qemu_init_main_loop() is manually called, > breaking qemu-tools.o programs on Windows at runtime. > > This patch checks for an initialized event handle before attempting to > set it, which is analoguous to how we deal with an unitialized > io_thread_fd in the posix implementation. > > Signed-off-by: Michael Roth<mdroth@linux.vnet.ibm.com> Applied. Thanks. Regards, Anthony Liguori > --- > main-loop.c | 5 ++++- > 1 files changed, 4 insertions(+), 1 deletions(-) > > diff --git a/main-loop.c b/main-loop.c > index 692381c..62d95b9 100644 > --- a/main-loop.c > +++ b/main-loop.c > @@ -164,7 +164,7 @@ static int qemu_signal_init(void) > > #else /* _WIN32 */ > > -HANDLE qemu_event_handle; > +HANDLE qemu_event_handle = NULL; > > static void dummy_event_handler(void *opaque) > { > @@ -183,6 +183,9 @@ static int qemu_event_init(void) > > void qemu_notify_event(void) > { > + if (!qemu_event_handle) { > + return; > + } > if (!SetEvent(qemu_event_handle)) { > fprintf(stderr, "qemu_notify_event: SetEvent failed: %ld\n", > GetLastError());
Patch
diff --git a/main-loop.c b/main-loop.c index 692381c..62d95b9 100644 --- a/main-loop.c +++ b/main-loop.c @@ -164,7 +164,7 @@ static int qemu_signal_init(void) #else /* _WIN32 */ -HANDLE qemu_event_handle; +HANDLE qemu_event_handle = NULL; static void dummy_event_handler(void *opaque) { @@ -183,6 +183,9 @@ static int qemu_event_init(void) void qemu_notify_event(void) { + if (!qemu_event_handle) { + return; + } if (!SetEvent(qemu_event_handle)) { fprintf(stderr, "qemu_notify_event: SetEvent failed: %ld\n", GetLastError());
The __attribute__((constructor)) init_main_loop() automatically get called if qemu-tool.o is linked in. On win32, this leads to a qemu_notify_event() call which attempts to SetEvent() on a HANDLE that won't be initialized until qemu_init_main_loop() is manually called, breaking qemu-tools.o programs on Windows at runtime. This patch checks for an initialized event handle before attempting to set it, which is analoguous to how we deal with an unitialized io_thread_fd in the posix implementation. Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> --- main-loop.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)