]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Refactored the componentMgr plugin code following standard practices.
authorJohn Wolfe <jwolfe@vmware.com>
Tue, 21 Dec 2021 20:48:50 +0000 (12:48 -0800)
committerJohn Wolfe <jwolfe@vmware.com>
Tue, 21 Dec 2021 20:48:50 +0000 (12:48 -0800)
open-vm-tools/lib/include/conf.h
open-vm-tools/services/plugins/componentMgr/componentMgr.c
open-vm-tools/services/plugins/componentMgr/componentMgrInstallAction.c
open-vm-tools/services/plugins/componentMgr/componentMgrInstallManager.c
open-vm-tools/services/plugins/componentMgr/componentMgrPlugin.h
open-vm-tools/services/plugins/componentMgr/componentMgrUtil.c
open-vm-tools/tools.conf

index 8f258831be8485f75f2daa44bf346a698aa3f313..4f044202881a43c17583ec76780e9639dc53a611 100644 (file)
  ******************************************************************************
  */
 
+/*
+ ******************************************************************************
+ * BEGIN ComponentMgr goodies.
+ */
+
+/**
+ * Defines the current poll interval (in seconds).
+ * This value is controlled by the componentMgr.poll-interval config file
+ * option.
+ */
+#define COMPONENTMGR_CONF_POLLINTERVAL "poll-interval"
+
+/**
+ * Name of section of configuration to be read from tools.conf.
+ */
+#define COMPONENTMGR_CONF_GROUPNAME "componentmgr"
+
+/**
+ * Defines the components  managed by the componentMgr plugin.
+ * This value is controlled by the componentMgr.included config file option.
+ */
+#define COMPONENTMGR_CONF_INCLUDEDCOMPONENTS "included"
+
+/*
+ * END ComponentMgr goodies.
+ ******************************************************************************
+ */
+
 /*
  ******************************************************************************
  * BEGIN GuestStore upgrader goodies.
index b43d8bcf20c764510c00e1a345c114fed51de5e0..971a12238eca6176a938ff4953fd8cf0bcdd68b7 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "componentMgrPlugin.h"
 #include "str.h"
+#include "conf.h"
 #include "vm_version.h"
 #include "embed_version.h"
 #include "vmtoolsd_version.h"
@@ -62,6 +63,7 @@ static gboolean ComponentMgrCb(gpointer data);
  *
  * @return
  *      Main ToolsAppCtx of the plugin.
+ *
  *****************************************************************************
  */
 
@@ -88,6 +90,7 @@ ComponentMgr_GetToolsAppCtx()
  *
  * Side effects:
  *      Deletes the existing timeout source and recreates a new one.
+ *
  *****************************************************************************
  */
 
@@ -110,7 +113,8 @@ ReconfigureComponentMgrPollLoopEx(ToolsAppCtx *ctx,  // IN
    }
 
    if (pollInterval != 0) {
-      if (pollInterval < COMPONENTMGR_POLL_INTERVAL) {
+      if (pollInterval < COMPONENTMGR_POLL_INTERVAL ||
+         pollInterval > (G_MAXINT / 1000)) {
          g_warning("%s: Invalid poll interval. Using default %us.\n",
                    __FUNCTION__, COMPONENTMGR_POLL_INTERVAL);
          pollInterval = COMPONENTMGR_POLL_INTERVAL;
@@ -120,7 +124,7 @@ ReconfigureComponentMgrPollLoopEx(ToolsAppCtx *ctx,  // IN
              COMPONENTMGR_CONF_POLLINTERVAL,
              pollInterval);
 
-      gComponentMgrTimeoutSource = g_timeout_source_new_seconds(pollInterval);
+      gComponentMgrTimeoutSource = g_timeout_source_new(pollInterval * 1000);
       VMTOOLSAPP_ATTACH_SOURCE(ctx, gComponentMgrTimeoutSource,
                                ComponentMgrCb, ctx, NULL);
       g_source_unref(gComponentMgrTimeoutSource);
@@ -153,11 +157,12 @@ ReconfigureComponentMgrPollLoopEx(ToolsAppCtx *ctx,  // IN
  *
  * Side effects:
  *      None.
+ *
  *****************************************************************************
  */
 
 static gboolean
-ComponentMgrCb(gpointer data) //IN
+ComponentMgrCb(gpointer data) // IN
 {
    ToolsAppCtx *ctx = data;
 
@@ -197,22 +202,23 @@ ComponentMgrCb(gpointer data) //IN
  *
  * Side effects:
  *      None.
+ *
  *****************************************************************************
  */
 
 static void
-ComponentMgrPollLoop(ToolsAppCtx *ctx) //IN
+ComponentMgrPollLoop(ToolsAppCtx *ctx) // IN
 {
    gint pollInterval;
-   gchar *listString = NULL;
+   gchar *listString;
 
    pollInterval = VMTools_ConfigGetInteger(ctx->config,
-                                           COMPONENTMGR_CONFGROUPNAME,
+                                           COMPONENTMGR_CONF_GROUPNAME,
                                            COMPONENTMGR_CONF_POLLINTERVAL,
                                            COMPONENTMGR_POLL_INTERVAL);
 
    listString = VMTools_ConfigGetString(ctx->config,
-                                        COMPONENTMGR_CONFGROUPNAME,
+                                        COMPONENTMGR_CONF_GROUPNAME,
                                         COMPONENTMGR_CONF_INCLUDEDCOMPONENTS,
                                         COMPONENTMGR_ALLCOMPONENTS);
 
@@ -288,13 +294,14 @@ ComponentMgrServerShutdown(gpointer src,     // IN
  *
  * Side effects:
  *      None.
+ *
  ******************************************************************************
  */
 
 static void
-ComponentMgrServerConfReload(gpointer src,        // IN
-                             ToolsAppCtx *ctx,    // IN
-                             gpointer data)       // IN
+ComponentMgrServerConfReload(gpointer src,     // IN
+                             ToolsAppCtx *ctx, // IN
+                             gpointer data)    // IN
 {
    ComponentMgrPollLoop(ctx);
 }
@@ -315,6 +322,7 @@ ComponentMgrServerConfReload(gpointer src,        // IN
  *
  * Side effects:
  *     Reinitializes the plugin timeout source.
+ *
  ******************************************************************************
  */
 
@@ -353,7 +361,7 @@ ComponentMgrServerReset(gpointer src,     // IN
  */
 
 TOOLS_MODULE_EXPORT ToolsPluginData *
-ToolsOnLoad(ToolsAppCtx *ctx)    // IN
+ToolsOnLoad(ToolsAppCtx *ctx) // IN
 {
    static ToolsPluginData regData = {
       "componentMgr",
index a5fcfcc79621c7b9bd2fb909768fca53ef2545e5..3ac3743b5811a1cd2d6f7608380cf485191f4a04 100644 (file)
@@ -36,6 +36,7 @@
 #include "util.h"
 #include "guestApp.h"
 #include "codeset.h"
+#include "conf.h"
 
 
 /*
@@ -94,7 +95,7 @@ ComponentMgrCustomizeSaltAddAction();
  * current action to be run on the component.
  */
 
-static struct componentInfo components[] = {
+static struct ComponentInfo components[] = {
    {SALT_MINION, TRUE, NOTINSTALLED, NULL, NULL, COMPONENTMGR_CHECK_STATUS_COUNT_DOWN, INVALIDACTION}
 };
 
@@ -137,7 +138,7 @@ static ComponentAction executionScripts[] = {
  */
 
 const char*
-ComponentMgr_GetComponentName(int componentIndex) //IN
+ComponentMgr_GetComponentName(int componentIndex) // IN
 {
    return components[componentIndex].name;
 }
@@ -161,19 +162,18 @@ ComponentMgr_GetComponentName(int componentIndex) //IN
  */
 
 gboolean
-ComponentMgr_CheckAnyAsyncProcessRunning()  //IN
+ComponentMgr_CheckAnyAsyncProcessRunning() // IN
 {
    int i;
    for (i = 0; i < ARRAYSIZE(components); i++) {
-      if (components[i].procInfo != NULL) {
-         g_debug("%s: Component %s has an async process still running.\n",
-                 __FUNCTION__, components[i].name);
+      if (ComponentMgr_IsAsyncProcessRunning(i)) {
          return TRUE;
       }
    }
    return FALSE;
 }
 
+
 /*
  *****************************************************************************
  * ComponentMgr_IsAsyncProcessRunning --
@@ -195,7 +195,7 @@ ComponentMgr_CheckAnyAsyncProcessRunning()  //IN
  */
 
 gboolean
-ComponentMgr_IsAsyncProcessRunning(int componentIndex)  //IN
+ComponentMgr_IsAsyncProcessRunning(int componentIndex) // IN
 {
    if (components[componentIndex].procInfo != NULL) {
       g_info("%s: Component %s has an async process still running.\n",
@@ -224,12 +224,13 @@ ComponentMgr_IsAsyncProcessRunning(int componentIndex)  //IN
  *
  * Side effects:
  *      None.
+ *
  *****************************************************************************
  */
 
 void
-ComponentMgr_SetComponentAsyncProcInfo(asyncProcessInfo *asyncProcInfo,
-                                       int componentIndex)
+ComponentMgr_SetComponentAsyncProcInfo(AsyncProcessInfo *asyncProcInfo, // IN
+                                       int componentIndex)              // IN
 {
    ASSERT(components[componentIndex].procInfo == NULL);
    components[componentIndex].procInfo = asyncProcInfo;
@@ -255,7 +256,7 @@ ComponentMgr_SetComponentAsyncProcInfo(asyncProcessInfo *asyncProcInfo,
  */
 
 void
-ComponentMgr_ResetComponentAsyncProcInfo(int componentIndex)
+ComponentMgr_ResetComponentAsyncProcInfo(int componentIndex) // IN
 {
    components[componentIndex].procInfo = NULL;
 }
@@ -283,8 +284,8 @@ ComponentMgr_ResetComponentAsyncProcInfo(int componentIndex)
  */
 
 void
-ComponentMgr_SetComponentGSourceTimer(GSource *componentTimer,
-                                      int componentIndex)
+ComponentMgr_SetComponentGSourceTimer(GSource *componentTimer, // IN
+                                      int componentIndex)      // IN
 {
    ASSERT(components[componentIndex].sourceTimer == NULL);
    components[componentIndex].sourceTimer = componentTimer;
@@ -310,7 +311,7 @@ ComponentMgr_SetComponentGSourceTimer(GSource *componentTimer,
  */
 
 void
-ComponentMgr_ResetComponentGSourceTimer(int componentIndex)
+ComponentMgr_ResetComponentGSourceTimer(int componentIndex) // IN
 {
    components[componentIndex].sourceTimer = NULL;
 }
@@ -337,8 +338,8 @@ ComponentMgr_ResetComponentGSourceTimer(int componentIndex)
  */
 
 static gchar*
-ComponentMgrGetScriptFullPath(const char *scriptName,   //IN
-                              const char *componentDir) //IN
+ComponentMgrGetScriptFullPath(const char *scriptName,   // IN
+                              const char *componentDir) // IN
 {
    gchar *scriptInstallDir;
    gchar *toolsInstallDir;
@@ -350,7 +351,7 @@ ComponentMgrGetScriptFullPath(const char *scriptName,   //IN
 #else
    toolsInstallDir = GuestApp_GetInstallPath();
    scriptInstallDir = g_strdup_printf("%s%s%s%s%s%s%s", toolsInstallDir, DIRSEPS,
-                                      COMPONENTMGR_CONFGROUPNAME, DIRSEPS,
+                                      COMPONENTMGR_DIRECTORY, DIRSEPS,
                                       componentDir, DIRSEPS, scriptName);
 #endif
 
@@ -428,10 +429,10 @@ ComponentMgrCustomizeSaltAddAction()
  */
 
 static char *
-ComponentMgrConstructCommandline(gchar *scriptPath,            //IN
-                                 const char *defaultArguments, //IN
-                                 const char *mandatoryParams,  //IN
-                                 char* (*customizeAction)())   //IN
+ComponentMgrConstructCommandline(gchar *scriptPath,            // IN
+                                 const char *defaultArguments, // IN
+                                 const char *mandatoryParams,  // IN
+                                 char* (*customizeAction)())   // IN
 {
    char *commandline = NULL;
    const char *mandatoryParamsExists = NULL;
@@ -444,7 +445,7 @@ ComponentMgrConstructCommandline(gchar *scriptPath,            //IN
 
    // Customize the arguments for the specific action via the callback function
    if (customizeAction != NULL) {
-      g_info("%s: Customizing argumnets with function.\n", __FUNCTION__);
+      g_info("%s: Customizing arguments with function.\n", __FUNCTION__);
       customArguments = customizeAction();
    }
 
@@ -466,7 +467,7 @@ ComponentMgrConstructCommandline(gchar *scriptPath,            //IN
 
    if (customArguments != NULL) {
       mandatoryParamsExists = strstr(customArguments, mandatoryParams);
-      if(mandatoryParamsExists == NULL) {
+      if (mandatoryParamsExists == NULL) {
          commandline = Str_SafeAsprintf(NULL, "\"%s%s\" %s \"%s\" %s %s %s",
                                         sysDir, powershellExecutable,
                                         componentMgrExecutionPolicy,
@@ -494,7 +495,7 @@ ComponentMgrConstructCommandline(gchar *scriptPath,            //IN
 #else
    if (customArguments != NULL) {
       mandatoryParamsExists = strstr(customArguments, mandatoryParams);
-      if(mandatoryParamsExists == NULL) {
+      if (mandatoryParamsExists == NULL) {
          commandline = Str_SafeAsprintf(NULL, "%s %s %s %s", scriptPath,
                                         defaultArguments, customArguments,
                                         mandatoryParams);
@@ -540,9 +541,9 @@ proceedexit:
  */
 
 char *
-ComponentMgr_CheckStatusCommandLine(int componentIndex)
+ComponentMgr_CheckStatusCommandLine(int componentIndex) // IN
 {
-   char *commandline = NULL;
+   char *commandline;
    gchar *scriptFullPath;
 
    /*
@@ -593,16 +594,24 @@ ComponentMgr_CheckStatusCommandLine(int componentIndex)
  */
 
 static void
-ComponentMgrSetEnabledComponentInfo(const char *componentName, //IN
-                                    gboolean enabled)          //IN
+ComponentMgrSetEnabledComponentInfo(const char *componentName, // IN
+                                    gboolean enabled)          // IN
 {
    int i;
+   gboolean componentFound = FALSE;
+
    for (i = 0; i < ARRAYSIZE(components); i++) {
       if (Str_Strcmp(components[i].name, componentName) == 0) {
-          components[i].isEnabled = enabled;
+         components[i].isEnabled = enabled;
+         componentFound = TRUE;
          break;
       }
    }
+
+   if (!componentFound) {
+      g_info("%s: Invalid component name %s.\n",
+             __FUNCTION__, componentName);
+   }
 }
 
 
@@ -629,9 +638,9 @@ ComponentMgrSetEnabledComponentInfo(const char *componentName, //IN
  */
 
 void
-ComponentMgr_SetStatusComponentInfo(ToolsAppCtx *ctx,   //IN
-                                    int exitCode,       //IN
-                                    int componentIndex) //IN
+ComponentMgr_SetStatusComponentInfo(ToolsAppCtx *ctx,   // IN
+                                    int exitCode,       // IN
+                                    int componentIndex) // IN
 {
    gchar *msg;
    gboolean status;
@@ -643,11 +652,6 @@ ComponentMgr_SetStatusComponentInfo(ToolsAppCtx *ctx,   //IN
 
    status = ComponentMgr_SendRpc(ctx, msg, NULL, NULL);
    g_free(msg);
-   if (!status) {
-      g_info("%s: Error sending RPC message for setting laststatus.\n",
-             __FUNCTION__);
-   }
-
    components[componentIndex].status = exitCode;
 }
 
@@ -670,15 +674,11 @@ ComponentMgr_SetStatusComponentInfo(ToolsAppCtx *ctx,   //IN
  */
 
 static void
-ComponentMgrSetEnabledAllComponents(gboolean enabled)
+ComponentMgrSetEnabledAllComponents(gboolean enabled) // IN
 {
    int i;
    for (i = 0; i < ARRAYSIZE(components); i++) {
-      if (enabled) {
-         components[i].isEnabled = TRUE;
-      } else {
-         components[i].isEnabled = FALSE;
-      }
+      components[i].isEnabled = enabled;
    }
 }
 
@@ -699,11 +699,12 @@ ComponentMgrSetEnabledAllComponents(gboolean enabled)
  *
  * Side effects:
  *      None.
+ *
  *****************************************************************************
  */
 
 void
-ComponentMgr_ExecuteComponentAction(int componentIndex)
+ComponentMgr_ExecuteComponentAction(int componentIndex) // IN
 {
    gchar *scriptFullPath;
    const char *action = NULL;
@@ -768,13 +769,15 @@ ComponentMgr_ExecuteComponentAction(int componentIndex)
     g_free(scriptFullPath);
 
    if (commandline == NULL) {
+      g_info("%s: Construction of command line failed for component %s.\n",
+             __FUNCTION__, components[componentIndex].name);
       return;
    }
 
    g_info("%s: Commandline %s to perform %s action on component %s.\n",
           __FUNCTION__, commandline, action, components[componentIndex].name);
-   ComponentMgr_AsynchrnousComponentActionStart(ComponentMgr_GetToolsAppCtx(),
-                                                commandline, componentIndex);
+   ComponentMgr_AsynchronousComponentActionStart(ComponentMgr_GetToolsAppCtx(),
+                                                 commandline, componentIndex);
    free(commandline);
 }
 
@@ -799,7 +802,7 @@ ComponentMgr_ExecuteComponentAction(int componentIndex)
  */
 
 static void
-ComponentMgrPublishKnownComponents(ToolsAppCtx *ctx)
+ComponentMgrPublishKnownComponents(ToolsAppCtx *ctx) // IN
 {
    int i;
    DynBuf enabledComponents;
@@ -817,7 +820,7 @@ ComponentMgrPublishKnownComponents(ToolsAppCtx *ctx)
                                                         executionScripts[i].componentDirectory);
 
          if (!File_Exists(scriptFullPath)) {
-            g_info("%s: Script file for component %s does not exists "
+            g_info("%s: Script file for component %s does not exist "
                    "under path %s.\n", __FUNCTION__, components[i].name,
                    scriptFullPath);
             g_free(scriptFullPath);
@@ -867,7 +870,7 @@ ComponentMgrPublishKnownComponents(ToolsAppCtx *ctx)
  */
 
 static IncludedComponents
-ComponentMgrIncludedComponents(const char* componentString) //IN
+ComponentMgrIncludedComponents(const char* componentString) // IN
 {
    int i;
    gchar **componentList = NULL;
@@ -921,18 +924,19 @@ ComponentMgrIncludedComponents(const char* componentString) //IN
  */
 
 void
-ComponentMgr_UpdateComponentEnableStatus(ToolsAppCtx *ctx) //IN
+ComponentMgr_UpdateComponentEnableStatus(ToolsAppCtx *ctx) // IN
 {
    gchar *listString;
-   char *context = NULL;
+   IncludedComponents included;
    char *token;
+   char *context = NULL;
 
    listString = VMTools_ConfigGetString(ctx->config,
-                                        COMPONENTMGR_CONFGROUPNAME,
+                                        COMPONENTMGR_CONF_GROUPNAME,
                                         COMPONENTMGR_CONF_INCLUDEDCOMPONENTS,
                                         COMPONENTMGR_ALLCOMPONENTS);
 
-   IncludedComponents included = ComponentMgrIncludedComponents(listString);
+   included = ComponentMgrIncludedComponents(listString);
    switch (included) {
       case ALLCOMPONENTS:
          ComponentMgrSetEnabledAllComponents(TRUE);
@@ -973,7 +977,7 @@ publishComponents:
  * current action for the component and waits for status update counter
  * to reach zero to run a check status operation if the component status
  * and component action are not compliant.
- * If the component action and component status are compliant, it spins of
+ * If the component action and component status are compliant, it spins off
  * an async check status operation.
  *
  * @param[in] ctx Tools application context.
@@ -991,23 +995,21 @@ publishComponents:
  */
 
 static void
-ComponentMgrCheckExecuteComponentAction(ToolsAppCtx *ctx,   //IN
-                                        int componentIndex, //IN
-                                        const char *action) //IN
+ComponentMgrCheckExecuteComponentAction(ToolsAppCtx *ctx,   // IN
+                                        int componentIndex, // IN
+                                        const char *action) // IN
 {
-   Action installaction;
-   char* commandline = NULL;
+   char* commandline;
    void (*callbackFunction)(int) = &ComponentMgr_ExecuteComponentAction;
+   Action installaction = INVALIDACTION;
 
    /*
     * It is possible at this stage, an async process for checkstatus or
-    * present/absent action may be running for the component. In such a sceanrio
+    * present/absent action may be running for the component. In such a scenario
     * the plugin shall not trigger any other async process.
     */
    ASSERT(components[componentIndex].isEnabled);
-   if (ComponentMgr_IsAsyncProcessRunning(componentIndex)) {
-      return;
-   }
+   ASSERT(!ComponentMgr_IsAsyncProcessRunning(componentIndex));
 
    commandline = ComponentMgr_CheckStatusCommandLine(componentIndex);
    if (commandline == NULL) {
@@ -1067,8 +1069,8 @@ ComponentMgrCheckExecuteComponentAction(ToolsAppCtx *ctx,   //IN
     * Before invoking any action for a component, we need to check the current
     * status for that component. We run the pre configured script with pre
     * configured check status arguments to the script.
-    * An async process in spin off to perform check status of a component with
-    * an option of sequenced operation after check status call.
+    * An async process will be spun off to perform check status of a component
+    * with an option of sequenced operation after check status call.
     */
    g_debug("%s: Checking current status of component %s with commandline %s.\n",
            __FUNCTION__, components[componentIndex].name, commandline);
@@ -1081,7 +1083,7 @@ ComponentMgrCheckExecuteComponentAction(ToolsAppCtx *ctx,   //IN
 
 /*
  *****************************************************************************
- * ComponentMgr_DestroyAsyncProcess -
+ * ComponentMgr_DestroyAsyncProcess --
  *
  * Destroy and free any or all async process running for a component.
  *
@@ -1114,7 +1116,7 @@ ComponentMgr_DestroyAsyncProcess()
 
 /*
  *****************************************************************************
- * ComponentMgr_Destroytimers -
+ * ComponentMgr_Destroytimers --
  *
  * This function destroys the GSource timers for all components.
  *
@@ -1167,7 +1169,7 @@ ComponentMgr_Destroytimers(void)
  */
 
 void
-ComponentMgr_UpdateComponentStatus(ToolsAppCtx *ctx)
+ComponentMgr_UpdateComponentStatus(ToolsAppCtx *ctx) // IN
 {
    int i;
 
index fcf398a0b257eb5546d734573da9cb52407a9f28..56c8dc996e48723a205411ff065615563a5a2eb5 100644 (file)
@@ -53,7 +53,7 @@
  */
 
 void
-ComponentMgr_FreeAsyncProc(asyncProcessInfo *procInfo) //IN
+ComponentMgr_FreeAsyncProc(AsyncProcessInfo *procInfo) // IN
 {
    int componentIndex = procInfo->componentIndex;
 #if defined(__linux__)
@@ -96,14 +96,14 @@ ComponentMgr_FreeAsyncProc(asyncProcessInfo *procInfo) //IN
  */
 
 static gboolean
-ComponentMgrCheckStatusMonitor(void *data)
+ComponentMgrCheckStatusMonitor(void *data) // IN
 {
-   int exitCode = -1;
+   ProcMgr_Pid procPid;
    int componentIndex;
-   const char *componentName = NULL;
+   const char *componentName;
    void (*callbackFunction)(int compIndex) = NULL;
 
-   asyncProcessInfo *procInfo = (asyncProcessInfo*)data;
+   AsyncProcessInfo *procInfo = (AsyncProcessInfo*)data;
    ASSERT(procInfo->asyncProc != NULL);
 
    /*
@@ -111,7 +111,7 @@ ComponentMgrCheckStatusMonitor(void *data)
     * the remaining execution time for the component.
     */
    procInfo->backoffTimer -= COMPONENTMGR_ASYNC_CHECK_STATUS_POLL_INTERVAL;
-   ProcMgr_Pid procPid = ProcMgr_GetPid(procInfo->asyncProc);
+   procPid = ProcMgr_GetPid(procInfo->asyncProc);
    componentIndex = procInfo->componentIndex;
    componentName = ComponentMgr_GetComponentName(componentIndex);
 
@@ -120,14 +120,15 @@ ComponentMgrCheckStatusMonitor(void *data)
            componentName, procInfo->backoffTimer);
 
    if (!ProcMgr_IsAsyncProcRunning(procInfo->asyncProc)) {
+      int exitCode = -1;
 #if defined(__linux__)
       if (ProcMgr_GetExitCode(procInfo->asyncProc, &exitCode) || exitCode == -1) {
          exitCode = SCRIPTFAILED;
       }
 #else
-     if (ProcMgr_GetExitCode(procInfo->asyncProc, &exitCode)) {
+      if (ProcMgr_GetExitCode(procInfo->asyncProc, &exitCode)) {
          exitCode = SCRIPTFAILED;
-     }
+      }
 #endif
      g_debug("%s: Checking status of a component has terminated gracefully"
              " with exit code %d.\n", __FUNCTION__, exitCode);
@@ -214,17 +215,18 @@ ComponentMgrCheckStatusMonitor(void *data)
  */
 
 static gboolean
-ComponentMgrProcessMonitor(void *data)
+ComponentMgrProcessMonitor(void *data) // IN
 {
-   char *commandline = NULL;
+   ProcMgr_Pid procPid;
    int componentIndex;
-   const char *componentName = NULL;
+   char *commandline;
+   const char *componentName;
 
-   asyncProcessInfo *procInfo = (asyncProcessInfo*)data;
+   AsyncProcessInfo *procInfo = (AsyncProcessInfo*)data;
    ASSERT(procInfo->asyncProc != NULL);
 
    procInfo->backoffTimer -= COMPONENTMGR_ASYNCPROCESS_POLL_INTERVAL;
-   ProcMgr_Pid procPid = ProcMgr_GetPid(procInfo->asyncProc);
+   procPid = ProcMgr_GetPid(procInfo->asyncProc);
    componentIndex = procInfo->componentIndex;
    componentName = ComponentMgr_GetComponentName(componentIndex);
 
@@ -341,14 +343,14 @@ ComponentMgrProcessMonitor(void *data)
  *****************************************************************************
  */
 
-static asyncProcessInfo*
-ComponentMgrCreateAsyncProcessInfo(ProcMgr_AsyncProc *asyncProc,
-                                   ToolsAppCtx *ctx,
-                                   int backoffTimer,
-                                   int componentIndex,
-                                   void (*callbackFunction)(int componentIndex))
+static AsyncProcessInfo*
+ComponentMgrCreateAsyncProcessInfo(ProcMgr_AsyncProc *asyncProc,                 // IN
+                                   ToolsAppCtx *ctx,                             // IN
+                                   int backoffTimer,                             // IN
+                                   int componentIndex,                           // IN
+                                   void (*callbackFunction)(int componentIndex)) // IN
 {
-   asyncProcessInfo *procInfo;
+   AsyncProcessInfo *procInfo;
    procInfo = g_malloc(sizeof *procInfo);
    procInfo->asyncProc = asyncProc;
    procInfo->ctx = ctx;
@@ -385,14 +387,15 @@ ComponentMgrCreateAsyncProcessInfo(ProcMgr_AsyncProc *asyncProc,
  */
 
 void
-ComponentMgr_AsynchronousComponentCheckStatus(ToolsAppCtx *ctx,
-                                              char *commandline,
-                                              int componentIndex,
-                                              void (*callback)(int compIndex))
+ComponentMgr_AsynchronousComponentCheckStatus(ToolsAppCtx *ctx,                // IN
+                                              const char *commandline,         // IN
+                                              int componentIndex,              // IN
+                                              void (*callback)(int compIndex)) // IN
 {
    ProcMgr_ProcArgs userArgs;
    GSource *sourceTimer;
-   asyncProcessInfo *procInfo;
+   AsyncProcessInfo *procInfo;
+   ProcMgr_AsyncProc *asyncProc;
 
    /*
     * If an async process is already running for the component.
@@ -402,7 +405,7 @@ ComponentMgr_AsynchronousComponentCheckStatus(ToolsAppCtx *ctx,
    ASSERT(!ComponentMgr_IsAsyncProcessRunning(componentIndex));
 
    memset(&userArgs, 0, sizeof userArgs);
-   ProcMgr_AsyncProc *asyncProc = ProcMgr_ExecAsync(commandline, &userArgs);
+   asyncProc = ProcMgr_ExecAsync(commandline, &userArgs);
    if (asyncProc == NULL) {
       g_warning("%s: Failed to create process", __FUNCTION__);
       return;
@@ -431,7 +434,7 @@ ComponentMgr_AsynchronousComponentCheckStatus(ToolsAppCtx *ctx,
 
 /*
  *****************************************************************************
- * ComponentMgr_AsynchrnousComponentActionStart --
+ * ComponentMgr_AsynchronousComponentActionStart --
  *
  * This function invokes the component script as an async process to perform
  * present/absent action and a GSource timer to poll the progress.
@@ -451,13 +454,14 @@ ComponentMgr_AsynchronousComponentCheckStatus(ToolsAppCtx *ctx,
  */
 
 void
-ComponentMgr_AsynchrnousComponentActionStart(ToolsAppCtx *ctx,
-                                             char *commandline,
-                                             int componentIndex)
+ComponentMgr_AsynchronousComponentActionStart(ToolsAppCtx *ctx,        // IN
+                                              const char *commandline, // IN
+                                              int componentIndex)      // IN
 {
    ProcMgr_ProcArgs userArgs;
    GSource *sourceTimer;
-   asyncProcessInfo *procInfo;
+   AsyncProcessInfo *procInfo;
+   ProcMgr_AsyncProc *asyncProc;
 
    /*
     * If an async process is already running for the component.
@@ -467,7 +471,7 @@ ComponentMgr_AsynchrnousComponentActionStart(ToolsAppCtx *ctx,
    ASSERT(!ComponentMgr_IsAsyncProcessRunning(componentIndex));
 
    memset(&userArgs, 0, sizeof userArgs);
-   ProcMgr_AsyncProc *asyncProc = ProcMgr_ExecAsync(commandline, &userArgs);
+   asyncProc = ProcMgr_ExecAsync(commandline, &userArgs);
    if (asyncProc == NULL) {
       g_warning("%s: Failed to create process", __FUNCTION__);
       return;
index 6e6315ada0d763fda0e663ed5240b67687633559..771013799d66c1131fd873d187caff21bf67c751 100644 (file)
@@ -24,7 +24,7 @@
  *
  * This file contains macros used by the componentMgr plugin having references
  * for timer related information, guestVar information, component information
- * and configuration realted information.
+ * and configuration related information.
  * Defines functions shared across the componentMgr plugin.
  * Defines states structures to be used to cache and store information related
  * to a component and async process.
 #endif
 
 
-//********************** Configuration Params Definitions *************
-
-/*
- * Defines the current poll interval (in seconds).
- * This value is controlled by the ComponentMgr.poll-interval config file option.
- */
-#define COMPONENTMGR_CONF_POLLINTERVAL "poll-interval"
-
-/**
- * Name of section of configuration to be read from tools.conf.
- */
-#define COMPONENTMGR_CONFGROUPNAME "componentMgr"
-
-/**
- * Defines the components  managed by the componentMgr plugin.
- * This value is controlled by the componentMgr.included config file option.
- */
-#define COMPONENTMGR_CONF_INCLUDEDCOMPONENTS "included"
-
 //********************** Timer Definitions ****************************
 
 /**
 
 //********************** Component Action Definitions *********************
 
+/**
+ * Defines check status action on the component.
+ */
+#define COMPONENTMGR_COMPONENTCHECKSTATUS "checkstatus"
+
+/**
+ * Defines an invalid action on the component.
+ */
+#define COMPONENTMGR_COMPONENINVALIDACTION "invalidaction"
+
 /**
  * Defines present action for a component to be installed on a system.
  */
 
 //********************** Component Definitions *********************
 
+/**
+ * Defines the directory for the plugin to host the scripts.
+ */
+#define COMPONENTMGR_DIRECTORY "componentMgr"
+
 /**
  * Defines none to indicate no component is managed by the plugin.
  */
@@ -202,7 +198,7 @@ typedef enum Action
 {
    PRESENT,      /* The action adds/installs the components on the guest. */
    ABSENT,       /* The action removes/uninstalls the components on the guest.*/
-   CHECKSTATUS,  /* The actions calls the preconfigured script to check the
+   CHECKSTATUS,  /* The action calls the preconfigured script to check the
                     current status of the component. */
    INVALIDACTION /* Action not recongnised by the plugin. */
 } Action;
@@ -213,7 +209,7 @@ typedef enum Action
  * for a particular component.
  */
 
-typedef struct asyncProcessInfo {
+typedef struct AsyncProcessInfo {
    ProcMgr_AsyncProc *asyncProc; /* ProcMgr_AsyncProc structure consisting of
                                     the process data running an action on the
                                     component. */
@@ -225,7 +221,7 @@ typedef struct asyncProcessInfo {
    void (*callbackFunction)(int componentIndex); /* A callback function to
                                                     sequence a new operation
                                                   */
-} asyncProcessInfo;
+} AsyncProcessInfo;
 
 
 /*
@@ -233,14 +229,14 @@ typedef struct asyncProcessInfo {
  * managed by the plugin. The component states is maintained in this structure.
  */
 
-typedef struct componentInfo
+typedef struct ComponentInfo
 {
    const char *name;     /* The name of the component. */
    gboolean isEnabled;   /* Component enabled/disabled by the plugin. */
    InstallStatus status; /* Contains current status of the component. */
    GSource *sourceTimer; /* A GSource timer for async process monitoring running
                             an operation for a component. */
-   asyncProcessInfo *procInfo; /* A structure to store information about the
+   AsyncProcessInfo *procInfo; /* A structure to store information about the
                                 * current running async process for a component.
                                 */
    int statuscount;      /* A counter value to store max number of times to
@@ -248,7 +244,7 @@ typedef struct componentInfo
                           */
    Action action;        /* Contains information about the action to be
                             performed on a component. */
-} componentInfo;
+} ComponentInfo;
 
 
 void
@@ -279,9 +275,9 @@ ComponentMgr_GetComponentAction(Action action);
 
 
 void
-ComponentMgr_AsynchrnousComponentActionStart(ToolsAppCtx *ctx,
-                                             char *commandline,
-                                             int componetIndex);
+ComponentMgr_AsynchronousComponentActionStart(ToolsAppCtx *ctx,
+                                              const char *commandline,
+                                              int componetIndex);
 
 
 void
@@ -312,7 +308,7 @@ ComponentMgr_ExecuteComponentAction(int componentIndex);
 
 void
 ComponentMgr_AsynchronousComponentCheckStatus(ToolsAppCtx *ctx,
-                                              char *commandline,
+                                              const char *commandline,
                                               int componentIndex,
                                               void (*callback)(int compIndex));
 
@@ -326,7 +322,7 @@ ComponentMgr_GetIncludedComponents(IncludedComponents pos);
 
 
 void
-ComponentMgr_SetComponentAsyncProcInfo(asyncProcessInfo *asyncProcInfo,
+ComponentMgr_SetComponentAsyncProcInfo(AsyncProcessInfo *asyncProcInfo,
                                        int componentIndex);
 
 
@@ -343,7 +339,7 @@ ComponentMgr_GetComponentName(int componentIndex);
 
 
 void
-ComponentMgr_FreeAsyncProc(asyncProcessInfo *procInfo);
+ComponentMgr_FreeAsyncProc(AsyncProcessInfo *procInfo);
 
 
 void
index 549fb8de5e42b82799cc05079a3a971e73fdb6dd..dd2a3c152b2a9a7dfa79c99d1a94d46ffc3c3c97 100644 (file)
  *
  * Side effects:
  *      None.
+ *
  ******************************************************************************
  */
 
 gboolean
-ComponentMgr_SendRpc(ToolsAppCtx *ctx,        //IN
-                     const char *guestInfoCmd,//IN
-                     char **outBuffer,        //OUT
-                     size_t *outBufferLen)    //OUT
+ComponentMgr_SendRpc(ToolsAppCtx *ctx,         // IN
+                     const char *guestInfoCmd, // IN
+                     char **outBuffer,         // OUT
+                     size_t *outBufferLen)     // OUT
 {
    gboolean status;
    size_t replyLen;
@@ -88,7 +89,7 @@ ComponentMgr_SendRpc(ToolsAppCtx *ctx,        //IN
 
 /*
  **************************************************************************
- * ComponentMgr_GetComponentInstallStatus
+ * ComponentMgr_GetComponentInstallStatus --
  *
  * This function returns an enum equivalent of the current status of the
  * component.
@@ -105,7 +106,7 @@ ComponentMgr_SendRpc(ToolsAppCtx *ctx,        //IN
  */
 
 const char*
-ComponentMgr_GetComponentInstallStatus(InstallStatus installStatus) //IN
+ComponentMgr_GetComponentInstallStatus(InstallStatus installStatus) // IN
 {
    switch (installStatus) {
       case NOTINSTALLED:      return "NOTINSTALLED";
@@ -123,7 +124,7 @@ ComponentMgr_GetComponentInstallStatus(InstallStatus installStatus) //IN
 
 /*
  **************************************************************************
- * ComponentMgr_GetComponentAction
+ * ComponentMgr_GetComponentAction --
  *
  * This function returns an enum equivalent of component action to be executed.
  *
@@ -139,15 +140,15 @@ ComponentMgr_GetComponentInstallStatus(InstallStatus installStatus) //IN
  */
 
 const char*
-ComponentMgr_GetComponentAction(Action action) //IN
+ComponentMgr_GetComponentAction(Action action) // IN
 {
    switch (action) {
-      case PRESENT:       return "present";
-      case ABSENT:        return "absent";
-      case CHECKSTATUS:   return "checkstatus";
-      case INVALIDACTION: return "invalidaction";
+      case PRESENT:       return COMPONENTMGR_COMPONENTPRESENT;
+      case ABSENT:        return COMPONENTMGR_COMPONENTABSENT;
+      case CHECKSTATUS:   return COMPONENTMGR_COMPONENTCHECKSTATUS;
+      case INVALIDACTION: return COMPONENTMGR_COMPONENINVALIDACTION;
    }
-   return NULL;
+   return COMPONENTMGR_COMPONENINVALIDACTION;
 }
 
 
@@ -171,13 +172,12 @@ ComponentMgr_GetComponentAction(Action action) //IN
 
 
 const char*
-ComponentMgr_GetIncludedComponents(IncludedComponents specialValue)
+ComponentMgr_GetIncludedComponents(IncludedComponents specialValue) // IN
 {
-   switch(specialValue)
-   {
+   switch (specialValue) {
       case ALLCOMPONENTS:      return "ALLCOMPONENTS";
       case NONECOMPONENTS:     return "NONECOMPONENTS";
-      default:                 return "NOSPECIALVALUES";
+      case NOSPECIALVALUES:    return "NOSPECIALVALUES";
    }
    return "NOSPECIALVALUES";
 }
@@ -198,12 +198,13 @@ ComponentMgr_GetIncludedComponents(IncludedComponents specialValue)
  *
  * Side effects:
  *      None.
+ *
  *****************************************************************************
  */
 
 void
-ComponentMgr_PublishAvailableComponents(ToolsAppCtx *ctx,
-                                        const char *components)
+ComponentMgr_PublishAvailableComponents(ToolsAppCtx *ctx,       // IN
+                                        const char *components) // IN
 {
    gboolean status;
    gchar *msg = g_strdup_printf("%s.%s %s", COMPONENTMGR_PUBLISH_COMPONENTS,
@@ -212,9 +213,4 @@ ComponentMgr_PublishAvailableComponents(ToolsAppCtx *ctx,
 
    status = ComponentMgr_SendRpc(ctx, msg, NULL, NULL);
    g_free(msg);
-
-   if (!status) {
-      g_info("%s: Error sending RPC message for known components.\n",
-             __FUNCTION__);
-   }
 }
index c7a657a6fbb6de5575fcd8fa63b52e54c1557395..a49def4da8bec37175ae67ddfd7ebff8b1bd7f6e 100644 (file)
 # whether to include reserved space in diskInfo space metrics on Linux
 #diskinfo-include-reserved=false
 
-[componentMgr]
+[componentmgr]
 
 # This plugin manages the known and enabled components add/remove status.
 # The plugin polls at regular interval and triggers action add/remove for
 # Default and minimum polling interval in seconds (0 => polling disabled)
 #poll-interval=180
 
-# Comma separated list of components managed by the plugin. If not specified, default value is all, which means all components and enabled by default. A special value of none means no component, which is equivalent to disabling the plugin completely. Value is parsed left to right and parsing stops at first occurrence of all or none or end of line.
+# Comma separated list of components managed by the plugin. If not specified,
+# default value is all, which means all components are enabled by default.
+# A special value of none means no component, which is equivalent to disabling
+# the plugin completely. Value is parsed left to right and parsing stops at
+# first occurrence of all or none or end of line.
 #included=all
 
 [appinfo]