]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Hgfs Win Client: fix upgrade of driver by changing the Hgfs install settings
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:22:58 +0000 (11:22 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:22:58 +0000 (11:22 -0700)
Some upgrades of the vmhgfs driver are requiring an additional
reboot even after the initial reboot. The Difx APIs replace the
driver with the new one on reboot, but after the old one is loaded.
This means that after the reboot everything looks good on the surface
but the old driver is running and not even on the disk at that point.
To mitigate this we can change the driver start type and fix missed
install settings both of which makes the HGFS driver compatible with
the rest of the Windows redirectors.

Perform to system registry changes to the vmhgfs driver service:
- set the HGFS driver dependent on the MUP component which it is anyway.
- set the driver start type to be demand start and not a standard system driver.

This makes that the vmtools system service responsible for starting the
Shared Folders client driver. This is again more compatible with the
Windows redirector model.

open-vm-tools/services/plugins/hgfsServer/hgfsPlugin.c

index 4e8d749fbb9528a9459eaebc634403082121c2ac..34dfefa73a804049d2c69e385a86ab7089768992 100644 (file)
@@ -22,6 +22,9 @@
  * Functionality to utilize the hgfs server in bora/lib as a tools plugin.
  */
 
+#if defined(_WIN32)
+#include <windows.h>
+#endif // defined(_WIN32)
 #include <string.h>
 
 #define G_LOG_DOMAIN "hgfsd"
@@ -144,6 +147,89 @@ HgfsServerCapReg(gpointer src,
 }
 
 
+#if defined(_WIN32)
+/**
+ * Starts the client driver service.
+ *
+ * @param[in]  serviceControlManager   Service Control Manager handle.
+ * @param[in]  driverName              Name of the driver service to start.
+ *
+ * @return ERROR_SUCCESS on success, an appropriate error otherwise.
+ */
+
+static DWORD
+HgfsServerStartClientService(SC_HANDLE    serviceControlManager, // IN: control manager
+                             PCWSTR       driverName)            // IN: driver name
+{
+   SC_HANDLE   service;
+   DWORD       result = ERROR_SUCCESS;
+
+   g_info("%s: starting service %S\n", __FUNCTION__, driverName);
+
+   /*
+    * Open the handle to the existing service.
+    */
+   service = OpenServiceW(serviceControlManager, driverName, SERVICE_ALL_ACCESS);
+   if (NULL == service) {
+      result = GetLastError();
+      g_warning("%s: Error: open service %S = %d \n", __FUNCTION__, driverName, result);
+      goto exit;
+   }
+
+   /*
+    * Start the execution of the service (i.e. start the driver).
+    */
+   if (!StartServiceW(service, 0, NULL)) {
+      result = GetLastError();
+
+      if (ERROR_SERVICE_ALREADY_RUNNING == result) {
+         result = ERROR_SUCCESS;
+      } else {
+         g_warning("%s: Error: start service %S = %d \n", __FUNCTION__, driverName, result);
+      }
+      goto exit;
+   }
+
+exit:
+   if (NULL != service) {
+      CloseServiceHandle(service);
+   }
+
+   return result;
+}
+#endif // defined(_WIN32)
+
+
+/**
+ * Start the HGFS client redirector.
+ *
+ * @return None.
+ */
+
+static void
+HgfsServerStartClientRedirector(void)
+{
+#if defined(_WIN32)
+   SC_HANDLE   serviceControlManager = NULL;
+   PCWSTR      driverName = L"vmhgfs";
+   DWORD       result = ERROR_SUCCESS;
+
+   serviceControlManager = OpenSCManagerW(NULL, NULL, SERVICE_START);
+   if (NULL == serviceControlManager) {
+      result = GetLastError();
+      g_warning("%s: Error: Open SC Manager = %d \n", __FUNCTION__, result);
+      goto exit;
+   }
+   result = HgfsServerStartClientService(serviceControlManager, driverName);
+
+exit:
+   if (NULL != serviceControlManager) {
+      CloseServiceHandle(serviceControlManager);
+   }
+#endif // defined(_WIN32)
+}
+
+
 /**
  * Returns the registration data for the HGFS server.
  *
@@ -167,6 +253,11 @@ ToolsOnLoad(ToolsAppCtx *ctx)
       return NULL;
    }
 
+   if (TOOLS_IS_MAIN_SERVICE(ctx)) {
+      /* Start the Shared Folders redirector client. */
+      HgfsServerStartClientRedirector();
+   }
+
    mgrData = g_malloc0(sizeof *mgrData);
    HgfsServerManager_DataInit(mgrData,
                               ctx->name,