[Spice-commits] 3 commits - vdagent/vdagent.cpp

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jul 18 10:09:43 UTC 2018


 vdagent/vdagent.cpp |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

New commits:
commit 2ae3bd5b9c9548c096e13f5de42855680a63b692
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun Jul 1 06:40:48 2018 +0100

    Use destructor instead of cleanup function
    
    More C++ style.
    Also avoids missing cleanup calls.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index 69d61da..306bfbd 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -116,7 +116,6 @@ private:
     void load_display_setting();
     bool send_announce_capabilities(bool request);
     void cleanup_in_msg();
-    void cleanup();
     bool has_capability(unsigned int capability) const {
         return VD_AGENT_HAS_CAPABILITY(_client_caps.begin(), _client_caps.size(),
                                        capability);
@@ -223,6 +222,8 @@ VDAgent::VDAgent()
 
 VDAgent::~VDAgent()
 {
+    FreeLibrary(_user_lib);
+    close_vio_serial();
     CloseHandle(_stop_event);
     CloseHandle(_control_event);
     delete _log;
@@ -257,6 +258,8 @@ bool VDAgent::run()
     HANDLE event_thread;
     WNDCLASS wcls;
 
+    close_vio_serial();
+
     if (!ProcessIdToSessionId(GetCurrentProcessId(), &session_id)) {
         vd_printf("ProcessIdToSessionId failed %lu", GetLastError());
         return false;
@@ -289,7 +292,6 @@ bool VDAgent::run()
         _control_event = CreateEvent(NULL, FALSE, FALSE, NULL);
     if (!_control_event) {
         vd_printf("CreateEvent() failed: %lu", GetLastError());
-        cleanup();
         return false;
     }
     ResetEvent(_control_event);
@@ -302,7 +304,6 @@ bool VDAgent::run()
     wcls.lpszClassName = VD_AGENT_WINCLASS_NAME;
     if (!RegisterClass(&wcls)) {
         vd_printf("RegisterClass() failed: %lu", GetLastError());
-        cleanup();
         return false;
     }
     _desktop_layout.reset(new DesktopLayout());
@@ -310,20 +311,17 @@ bool VDAgent::run()
         vd_printf("No QXL devices!");
     }
     if (!init_vio_serial()) {
-        cleanup();
         return false;
     }
     if (!ReadFileEx(_vio_serial, _read_buf, sizeof(VDIChunk), &_read_overlapped, read_completion) &&
             GetLastError() != ERROR_IO_PENDING) {
         vd_printf("vio_serial read error %lu", GetLastError());
-        cleanup();
         return false;
     }
     _running = true;
     event_thread = CreateThread(NULL, 0, event_thread_proc, this, 0, NULL);
     if (!event_thread) {
         vd_printf("CreateThread() failed: %lu", GetLastError());
-        cleanup();
         return false;
     }
     send_announce_capabilities(true);
@@ -337,16 +335,9 @@ bool VDAgent::run()
     }
     vd_printf("Agent stopped");
     CloseHandle(event_thread);
-    cleanup();
     return true;
 }
 
-void VDAgent::cleanup()
-{
-    FreeLibrary(_user_lib);
-    close_vio_serial();
-}
-
 void VDAgent::set_control_event(control_command_t control_command)
 {
     MutexLocker lock(_control_mutex);
commit 0ac9d687e92165f6274786e5f5485cc65ae5c34a
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sat Jun 30 05:48:02 2018 +0100

    Introduce an helper to close VirtIo device
    
    Do not assume we allocated the handle doing the cleanup.
    This utility will be reused in next patch.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe de Dinechin <dinechin at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index eed3103..69d61da 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -110,6 +110,7 @@ private:
     bool write_message(uint32_t type, uint32_t size, void* data);
     bool write_clipboard(VDAgentMessage* msg, uint32_t size);
     bool init_vio_serial();
+    void close_vio_serial();
     bool send_input();
     void set_display_depth(uint32_t depth);
     void load_display_setting();
@@ -343,7 +344,7 @@ bool VDAgent::run()
 void VDAgent::cleanup()
 {
     FreeLibrary(_user_lib);
-    CloseHandle(_vio_serial);
+    close_vio_serial();
 }
 
 void VDAgent::set_control_event(control_command_t control_command)
@@ -1227,6 +1228,14 @@ bool VDAgent::init_vio_serial()
     return true;
 }
 
+void VDAgent::close_vio_serial()
+{
+    if (_vio_serial != INVALID_HANDLE_VALUE) {
+        CloseHandle(_vio_serial);
+        _vio_serial = INVALID_HANDLE_VALUE;
+    }
+}
+
 void VDAgent::dispatch_message(VDAgentMessage* msg, uint32_t port)
 {
     bool res = true;
commit 6d1d4241ac9abc59970c4839845a2d174db58854
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sat Jun 30 05:46:19 2018 +0100

    Use proper invalid value for _vio_serial
    
    For some reason kernel handles in Windows have 2 invalid values
    depending on the type. Files/devices use INVALID_HANDLE_VALUE (-1),
    while others use NULL (0). As _vio_serial is a file, created
    with CreateFile, use INVALID_HANDLE_VALUE for consistency.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index 423c3ee..eed3103 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -198,7 +198,7 @@ VDAgent::VDAgent()
     , _session_is_locked (false)
     , _desktop_switch (false)
     , _display_setting (VD_AGENT_REGISTRY_KEY)
-    , _vio_serial (NULL)
+    , _vio_serial (INVALID_HANDLE_VALUE)
     , _read_pos (0)
     , _write_pos (0)
     , _logon_desktop (false)


More information about the Spice-commits mailing list