]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
[GlobalConf] Support for vmusr service to load Global Configuration.
authorJohn Wolfe <jwolfe@vmware.com>
Tue, 27 Oct 2020 00:29:53 +0000 (17:29 -0700)
committerJohn Wolfe <jwolfe@vmware.com>
Tue, 27 Oct 2020 00:29:53 +0000 (17:29 -0700)
Currently, the vmsvc service periodically downloads the Global Configuration
from the GuestStore and applies the downloaded configuration.  'vmusr'
service doesn't have the support.  In this changeset, made the changes
for both vmusr and vmsvc services to periodically check and apply
the changes.

To keep thing simple and easy, the new approach is check the
modification time every time the regular tools conf is read and if
changes are detected, the configuration is applied.  With this new approach,
signalling mechanism is not needed and that code is removed.

vmsvc:
* Starts a background thread which periodically fetches the global
configuration from the GuestStore.

vmusr:
* No background thread is created. But checks and loads the configuration
everytime the regular tools.conf is checked.

open-vm-tools/lib/include/vmware/tools/plugin.h
open-vm-tools/services/vmtoolsd/mainLoop.c
open-vm-tools/services/vmtoolsd/toolsCoreInt.h

index e8e3d146c22c726364349705f40ec2695c6aeed9..62d8d967e843bd80e25f93f88e24b994ee73dc31 100644 (file)
@@ -217,15 +217,6 @@ ToolsCore_LogState(guint level,
  */
 #define TOOLS_CORE_SIG_SERVICE_CONTROL  "tcs_service_control"
 
-/**
- * Signal sent when a new version of global configuration is downloaded.
- *
- * @param[in]  src      The source object.
- * @param[in]  ctx      ToolsAppCtx *: The application context.
- * @param[in]  data     Client data.
- */
-#define TOOLS_CORE_SIG_GLOBALCONF_UPDATE "tcs_globalconf_update"
-
 #endif
 
 /**
index bad1d81fc5af6c8c2f49727cd26004dba2b6c80e..e05f82ffea568796c3673aa8338648295677b295 100644 (file)
@@ -198,28 +198,6 @@ ToolsCoreConfFileCb(gpointer clientData)
 }
 
 
-#if defined(_WIN32)
-/**
- * Callback TOOLS_CORE_SIG_GLOBALCONF_UPDATE signal. The signal is
- * triggered whenever a new global configuration is downloaded.
- *
- * @param[in]  src   The source object.
- * @param[in]  ctx   The ToolsAppCtx for passing config.
- * @param[in]  state Service state.
- */
-
-static void
-ToolsCoreGlobalConfUpdateSignalCb(gpointer src,
-                                  ToolsAppCtx *ctx,
-                                  ToolsServiceState *state)
-{
-   g_debug("%s: global config is updated. Reloading the config.", __FUNCTION__);
-
-   ToolsCore_ReloadConfigEx(state, FALSE, TRUE);
-}
-#endif
-
-
 /**
  * IO freeze signal handler. Disables the conf file check task if I/O is
  * frozen, re-enable it otherwise. See bug 529653.
@@ -516,26 +494,15 @@ ToolsCoreRunLoop(ToolsServiceState *state)
             g_info("%s: Successfully started tools hang detector",
                    __FUNCTION__);
          }
+      }
+
 #if defined(_WIN32)
-         if (GlobalConfig_Start(&state->ctx)) {
-            g_info("%s: Successfully started global config module.",
-                   __FUNCTION__);
-            if (g_signal_lookup(TOOLS_CORE_SIG_GLOBALCONF_UPDATE,
-                                G_OBJECT_TYPE(state->ctx.serviceObj)) != 0) {
-               g_signal_connect(state->ctx.serviceObj,
-                                TOOLS_CORE_SIG_GLOBALCONF_UPDATE,
-                                G_CALLBACK(ToolsCoreGlobalConfUpdateSignalCb),
-                                state);
-               g_debug("%s: Registered the handler for the "
-                       "global config update signal.", __FUNCTION__);
-               gGlobalConfEnabled = TRUE;
-            } else {
-               g_debug("%s: Failed to register the handler for the "
-                       "global config update signal", __FUNCTION__);
-            }
-         }
-#endif
+      if (GlobalConfig_Start(&state->ctx)) {
+         g_info("%s: Successfully started global config module.",
+                  __FUNCTION__);
+         gGlobalConfEnabled = TRUE;
       }
+#endif
 
       g_main_loop_run(state->ctx.mainLoop);
 #endif
@@ -669,35 +636,42 @@ ToolsCore_GetTcloName(ToolsServiceState *state)
  *
  * @param[in]  state       Service state.
  * @param[in]  reset       Whether to reset the logging subsystem.
- * @param[in]  force       If TRUE, the config file will be loaded even if it
- *                         has not been modified since the last check.
  */
 
 void
-ToolsCore_ReloadConfigEx(ToolsServiceState *state,
-                         gboolean reset,
-                         gboolean force)
+ToolsCore_ReloadConfig(ToolsServiceState *state,
+                       gboolean reset)
 {
    gboolean first = state->ctx.config == NULL;
    gboolean loaded;
 
-   if (force) {
-      /*
-       * Set the configMtime to 0 so that the config file from the file system
-       * is reloaded. Else, the config is loaded only if it's been modified
-       * since the last check.
-       */
-      state->configMtime = 0;
+#if defined(_WIN32)
+   gboolean globalConfLoaded = FALSE;
+
+   if (gGlobalConfEnabled) {
+      globalConfLoaded =  GlobalConfig_LoadConfig(&state->globalConfig,
+                                                  &state->globalConfigMtime);
+      if (globalConfLoaded) {
+         /*
+         * Set the configMtime to 0 so that the config file from the file system
+         * is reloaded. Else, the config is loaded only if it's been modified
+         * since the last check.
+         */
+         state->configMtime = 0;
+      }
    }
+#endif
 
    loaded = VMTools_LoadConfig(state->configFile,
                                G_KEY_FILE_NONE,
                                &state->ctx.config,
                                &state->configMtime);
+
 #if defined(_WIN32)
-   if (gGlobalConfEnabled && (loaded || force)) {
-      gboolean globalConfigUpdated =  GlobalConfig_Update(state->ctx.config);
-      loaded = loaded || globalConfigUpdated;
+   if (loaded || globalConfLoaded) {
+      gboolean configUpdated = VMTools_AddConfig(state->globalConfig,
+                                                 state->ctx.config);
+      loaded = loaded || configUpdated;
    }
 #endif
 
@@ -735,24 +709,6 @@ ToolsCore_ReloadConfigEx(ToolsServiceState *state,
 }
 
 
-/**
- * Reloads the config file and re-configure the logging subsystem if the
- * log file was updated. If the config file is being loaded for the first
- * time, try to upgrade it to the new version if an old version is
- * detected.
- *
- * @param[in]  state       Service state.
- * @param[in]  reset       Whether to reset the logging subsystem.
- */
-
-void
-ToolsCore_ReloadConfig(ToolsServiceState *state,
-                       gboolean reset)
-{
-   ToolsCore_ReloadConfigEx(state, reset, FALSE);
-}
-
-
 #if defined(_WIN32)
 
 /**
index 6b9f38a292a1a19d233093e9bc82cd975b8042ee..fe5125a976417b6df00137a31761bd1b250cd724 100644 (file)
@@ -72,6 +72,10 @@ typedef struct ToolsServiceState {
    gchar         *name;
    gchar         *configFile;
    time_t         configMtime;
+#if defined(_WIN32)
+   GKeyFile      *globalConfig;
+   time_t         globalConfigMtime;
+#endif
    guint          configCheckTask;
    gboolean       mainService;
    gboolean       capsRegistered;
@@ -143,11 +147,6 @@ void
 ToolsCore_ReloadConfig(ToolsServiceState *state,
                        gboolean reset);
 
-void
-ToolsCore_ReloadConfigEx(ToolsServiceState *state,
-                         gboolean reset,
-                         gboolean force);
-
 void
 ToolsCore_RegisterPlugins(ToolsServiceState *state);