]> git.proxmox.com Git - qemu.git/commitdiff
main-loop: Fix SetEvent() on uninitialized handle on win32
authorMichael Roth <mdroth@linux.vnet.ibm.com>
Sat, 21 Jan 2012 01:08:27 +0000 (19:08 -0600)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 1 Feb 2012 20:45:02 +0000 (14:45 -0600)
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.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
main-loop.c

index 692381cb19d63aa6691c61a49e9ddc0641c5f178..62d95b96379e9c3cf265bf89308a1cb4229b732d 100644 (file)
@@ -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());