[Spice-devel] [PATCH vdagent-win 5/6] vdagent: don't terminate if stop event cannot be opened

Arnon Gilboa agilboa at redhat.com
Mon Mar 18 06:42:03 PDT 2013


so vdagent can keep running as standalone without dependency on vdservice.

Regression was due to commit c1807e.

rhbz #903379
---
 vdagent/vdagent.cpp |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index e20c830..f254d55 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -295,11 +295,6 @@ bool VDAgent::run()
         return false;
     }
     _stop_event = OpenEvent(SYNCHRONIZE, FALSE, VD_AGENT_STOP_EVENT);
-    if (!_stop_event) {
-        vd_printf("OpenEvent() failed: %lu", GetLastError());
-        cleanup();
-        return false;
-    }
     memset(&wcls, 0, sizeof(wcls));
     wcls.lpfnWndProc = &VDAgent::wnd_proc;
     wcls.lpszClassName = VD_AGENT_WINCLASS_NAME;
@@ -472,12 +467,19 @@ void VDAgent::input_desktop_message_loop()
 
 void VDAgent::event_dispatcher(DWORD timeout, DWORD wake_mask)
 {
-    HANDLE events[] = {_control_event, _stop_event};    
-    const DWORD event_count = sizeof(events) / sizeof(events[0]);
+    HANDLE events[] = {_control_event, _stop_event};
+    DWORD event_count = _stop_event ? 2 : 1;
     DWORD wait_ret;
     MSG msg;
 
     wait_ret = MsgWaitForMultipleObjectsEx(event_count, events, timeout, wake_mask, MWMO_ALERTABLE);
+    if (wait_ret == WAIT_OBJECT_0 + event_count) {
+        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+            TranslateMessage(&msg);
+            DispatchMessage(&msg);
+        }
+        return;
+    }
     switch (wait_ret) {
     case WAIT_OBJECT_0:
         handle_control_event();
@@ -485,12 +487,6 @@ void VDAgent::event_dispatcher(DWORD timeout, DWORD wake_mask)
     case WAIT_OBJECT_0 + 1:
         _running = false;
         break;
-    case WAIT_OBJECT_0 + event_count:
-        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
-            TranslateMessage(&msg);
-            DispatchMessage(&msg);
-        }
-        break;
     case WAIT_IO_COMPLETION:
     case WAIT_TIMEOUT:
         break;
-- 
1.7.7.6



More information about the Spice-devel mailing list