[Spice-devel] [phodav PATCH 7/7 v3] spice-webdavd-windows: Dismount shared folder on service stop

Lukas Venhoda lvenhoda at redhat.com
Thu Mar 17 13:47:51 UTC 2016


When stopping the service, automatically disconnect shared folder on
windows. Not dismounting could lead to multiple shared folders.
---
Changes since v2:
 - None
Changes since v1:
 - New patch
---
 spice/spice-webdavd.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/spice/spice-webdavd.c b/spice/spice-webdavd.c
index 8f9b06b..c27cbbd 100644
--- a/spice/spice-webdavd.c
+++ b/spice/spice-webdavd.c
@@ -835,6 +835,28 @@ map_drive(void)
 }

 static void
+unmap_drive(void)
+{
+  gchar local_name[3];
+  guint32 retval;
+
+  local_name[0] = drive_letter;
+  local_name[1] = ':';
+  local_name[2] = 0;
+
+  retval = WNetCancelConnection2(local_name, CONNECT_UPDATE_PROFILE, TRUE);
+
+  if (retval == NO_ERROR)
+    g_debug ("unmap_drive ok");
+  else if (retval == ERROR_NOT_CONNECTED)
+    g_debug ("drive not connected");
+  else
+    g_critical ("map_drive error %d", retval);
+
+  return;
+}
+
+static void
 map_drive_cb(GTask *task,
           gpointer source_object,
           gpointer task_data,
@@ -969,6 +991,7 @@ service_ctrl_handler (DWORD ctrl, DWORD type, LPVOID data, LPVOID ctx)
     {
     case SERVICE_CONTROL_STOP:
     case SERVICE_CONTROL_SHUTDOWN:
+        unmap_drive ();
         quit (SIGTERM);
         service_status.dwCurrentState = SERVICE_STOP_PENDING;
         SetServiceStatus (service_status_handle, &service_status);
--
2.5.0



More information about the Spice-devel mailing list