]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Change to common source files not applicable to open-vm-tools.
authorKruti Pendharkar <kp025370@broadcom.com>
Tue, 24 Jun 2025 16:26:23 +0000 (09:26 -0700)
committerKruti Pendharkar <kp025370@broadcom.com>
Tue, 24 Jun 2025 16:26:23 +0000 (09:26 -0700)
open-vm-tools/lib/include/conf.h
open-vm-tools/libvmtools/vmtoolsLog.c
open-vm-tools/services/vmtoolsd/cmdLine.c
open-vm-tools/services/vmtoolsd/mainLoop.c
open-vm-tools/services/vmtoolsd/toolsRpc.c
open-vm-tools/toolbox/toolbox-cmd.c

index eca86fe423c86b17bd2fc7f0358755350b8e86b3..fc3763dc1a95071efbd5e0815e92daa15875e914 100644 (file)
@@ -50,6 +50,7 @@
 #define CONFNAME_LOGFILE                  "log.file"
 #define CONFNAME_LOGLEVEL                 "log.level"
 #define CONFNAME_DISABLETOOLSVERSION      "disable-tools-version"
+#define CONFNAME_USELEGACYVERSION         "use-legacy-version"
 #define CONFNAME_HIDETOOLSVERSION         "hide-tools-version"
 #define CONFNAME_DISABLEPMTIMERWARNING    "disable-pmtimerwarning"
 #define CONFGROUPNAME_VMTOOLS             "vmtools"
index bb5be820981ee7f1af9d679744d1721a63917544..679467572d0f0eda1faaa785ac1921be19f14b22 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (c) 2008-2024 Broadcom. All Rights Reserved.
+ * Copyright (c) 2008-2025 Broadcom. All Rights Reserved.
  * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -52,6 +52,7 @@
 #  include "w32Messages.h"
 #  include "windowsu.h"
 #endif
+#include "conf.h"
 #include "str.h"
 #include "system.h"
 #include "vmware/tools/log.h"
@@ -508,6 +509,25 @@ VMToolsFreeLogEntry(gpointer data)
 }
 
 
+/**
+ * Function that resets log header of Tools version, build details
+ * and Guest OS details. The format of the version can change.
+ *
+ */
+
+static void
+VMToolsResetLogHeader(void)
+{
+   guint i;
+
+   for (i = 0; i < gLogHeaderCount; i++) {
+      free(gLogHeaderBuf[i]);
+      gLogHeaderBuf[i] = NULL;
+   }
+   gLogHeaderCount = 0;
+}
+
+
 /**
  * Function that logs a cached log header of Tools version, build details
  * and Guest OS details.
@@ -1452,6 +1472,8 @@ VMToolsConfigLoggingInt(const gchar *defaultDomain,
                         gboolean reset)
 {
    gboolean allocDict = (cfg == NULL);
+   static gboolean gUseLegacyVersion = FALSE; // Default is off
+   gboolean useLegacyVersion = FALSE;
    gchar **list;
    gchar **curr;
    GPtrArray *oldDomains = NULL;
@@ -1536,17 +1558,40 @@ VMToolsConfigLoggingInt(const gchar *defaultDomain,
     * Cached log headers will be logged at log rotation and reset.
     * No need to re-init the log headers in case of config reload.
     */
+   /*
+    * Check the config values to see if revert to older format.
+    * Default is false and new format will be used.
+    */
+   useLegacyVersion = g_key_file_get_boolean(cfg,
+                                             CONFGROUPNAME_VMTOOLS,
+                                             CONFNAME_USELEGACYVERSION,
+                                             NULL);
+   if (gUseLegacyVersion != useLegacyVersion) {
+      VMToolsResetLogHeader();
+      gUseLegacyVersion = useLegacyVersion;
+   }
+
    if (gLogHeaderCount == 0) {
+      const char *versionFormat;
+      const char *buildNumberString;
+
       LogHandler *handler = GetLogHandlerByDomain(gLogDomain);
       GlibLogger *logger = handler->logger;
 
       logger->logHeader = TRUE;
 
+      if (useLegacyVersion) {
+         versionFormat = "%s Version: %s (%s)";
+         buildNumberString = BUILD_NUMBER;
+      } else {
+         versionFormat = "%s Version: %s.%s";
+         buildNumberString = BUILD_NUMBER_NUMERIC_STRING;
+      }
       gLogHeaderBuf[gLogHeaderCount++] = Str_Asprintf(NULL,
-                                                      "%s Version: %s (%s)",
+                                                      versionFormat,
                                                       VMWARE_TOOLS_SHORT_NAME,
                                                       TOOLS_VERSION_EXT_CURRENT_STR,
-                                                      BUILD_NUMBER);
+                                                      buildNumberString);
 
       gosDetails = Hostinfo_GetOSDetailedData();
       if (gosDetails != NULL && gLogHeaderCount < LOG_HEADER_MAX_ENTRIES) {
index e2ceae834b7e7f80c62a1a2e78222ac57c2572af..a6a2a802806538a94450829acaa61a6d101500cb 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (c) 2008-2021,2023-2024 Broadcom. All Rights Reserved.
+ * Copyright (c) 2008-2025 Broadcom. All Rights Reserved.
  * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -372,8 +372,30 @@ ToolsCore_ParseCommandLine(ToolsServiceState *state,
    }
 
    if (version) {
-      g_print("%s %s (%s)\n", _("VMware Tools daemon, version"),
-              VMTOOLSD_VERSION_STRING, BUILD_NUMBER);
+      /*
+       * Configure logging system, without resetting the logging
+       * if reporting the version. When reporting the version, the
+       * process will immediately exit.
+       */
+      gboolean useLegacyVersion;
+
+      ToolsCore_ReloadConfig(state, FALSE);
+
+      /*
+       * Check the config values to see if revert to older format.
+       * Default is false and new format will be used.
+       */
+      useLegacyVersion = VMTools_ConfigGetBoolean(state->ctx.config,
+                                                  CONFGROUPNAME_VMTOOLS,
+                                                  CONFNAME_USELEGACYVERSION,
+                                                  FALSE);
+      if (useLegacyVersion) {
+         g_print("%s %s (%s)\n", _("VMware Tools daemon, version"),
+                 VMTOOLSD_VERSION_STRING, BUILD_NUMBER);
+      } else {
+         g_print("%s %s.%s\n", _("VMware Tools daemon, version"),
+                 VMTOOLSD_VERSION_STRING, BUILD_NUMBER_NUMERIC_STRING);
+      }
       exit(0);
    }
 
index 4b3595058b168b2b2d0f181600ccef816b118f2f..b37607f90ee884a4eb0a8893cf11f685aea91b57 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (c) 2008-2024 Broadcom. All Rights Reserved.
+ * Copyright (c) 2008-2025 Broadcom. All Rights Reserved.
  * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -259,37 +259,63 @@ ToolsCoreIOFreezeCb(gpointer src,
  *
  * Report version info as guest variables.
  *
- * @param[in]  state       Service state.
+ * @param[in]  ctx       The application context.
  *
  ******************************************************************************
  */
 
 static void
-ToolsCoreReportVersionData(ToolsServiceState *state)
+ToolsCoreReportVersionData(ToolsAppCtx *ctx)
 {
    char *value;
    const static char cmdPrefix[] = "info-set guestinfo.vmtools.";
+   static gboolean useLegacyVersion = FALSE;
+   static gboolean first = TRUE;
+   const char *cmdDescFmt;
+   const char *cmdToolsVersionStr;
+   gboolean confUseLegacyVersion;
 
    /*
     * These values are documented with specific formats.  Do not change
     * the formats, as client code can depend on them.
     */
+   confUseLegacyVersion =
+      VMTools_ConfigGetBoolean(ctx->config,
+                               CONFGROUPNAME_VMTOOLS,
+                               CONFNAME_USELEGACYVERSION,
+                               FALSE);
+
+   /* Nothing to do if not the first call and state is unchanged. */
+   if (!first && (confUseLegacyVersion == useLegacyVersion)) {
+      return;
+   }
 
+#define CMD_DESCRIPTION          "%sdescription "
+#ifdef OPEN_VM_TOOLS
+#define VMTOOLS_PRODUCT          "open-vm-tools"
+#else
+#define VMTOOLS_PRODUCT          "VMware Tools"
+#endif
+
+   first = FALSE;
+   useLegacyVersion = confUseLegacyVersion;
+   if (useLegacyVersion) {
+      cmdDescFmt = CMD_DESCRIPTION VMTOOLS_PRODUCT " %s build %s";
+      cmdToolsVersionStr = TOOLS_VERSION_CURRENT_STR;
+   } else {
+      cmdDescFmt = CMD_DESCRIPTION VMTOOLS_PRODUCT " %s.%s";
+      cmdToolsVersionStr = TOOLS_VERSION_EXT_CURRENT_STR;
+   }
 
    /*
     * Version description as a human-readable string.  This value should
     * not be parsed, so its format can be modified if necessary.
     */
-   value = g_strdup_printf("%sdescription "
-#ifdef OPEN_VM_TOOLS
-                           "open-vm-tools %s build %s",
-#else
-                           "VMware Tools %s build %s",
-#endif
+   value = g_strdup_printf(cmdDescFmt,
                            cmdPrefix,
-                           TOOLS_VERSION_CURRENT_STR,
+                           cmdToolsVersionStr,
                            BUILD_NUMBER_NUMERIC_STRING);
-   if (!RpcChannel_Send(state->ctx.rpc, value,
+   if (!RpcChannel_Send(ctx->rpc, value,
                         strlen(value) + 1, NULL, NULL)) {
       g_warning("%s: failed to send description", __FUNCTION__);
    }
@@ -300,8 +326,8 @@ ToolsCoreReportVersionData(ToolsServiceState *state)
     * be parsed, so its format should not be modified.
     */
    value = g_strdup_printf("%sversionString "
-                           "%s", cmdPrefix, TOOLS_VERSION_CURRENT_STR);
-   if (!RpcChannel_Send(state->ctx.rpc, value,
+                           "%s", cmdPrefix, cmdToolsVersionStr);
+   if (!RpcChannel_Send(ctx->rpc, value,
                         strlen(value) + 1, NULL, NULL)) {
       g_warning("%s: failed to send versionString", __FUNCTION__);
    }
@@ -313,8 +339,8 @@ ToolsCoreReportVersionData(ToolsServiceState *state)
     */
    value = g_strdup_printf("%sversionNumber "
                            "%d", cmdPrefix, TOOLS_VERSION_CURRENT);
-   if (!RpcChannel_Send(state->ctx.rpc, value,
-                         strlen(value) + 1, NULL, NULL)) {
+   if (!RpcChannel_Send(ctx->rpc, value,
+                        strlen(value) + 1, NULL, NULL)) {
       g_warning("%s: failed to send versionNumber", __FUNCTION__);
    }
    g_free(value);
@@ -325,7 +351,7 @@ ToolsCoreReportVersionData(ToolsServiceState *state)
     */
    value = g_strdup_printf("%sbuildNumber "
                            "%d", cmdPrefix, BUILD_NUMBER_NUMERIC);
-   if (!RpcChannel_Send(state->ctx.rpc, value,
+   if (!RpcChannel_Send(ctx->rpc, value,
                         strlen(value) + 1, NULL, NULL)) {
       g_warning("%s: failed to send buildNumber", __FUNCTION__);
    }
@@ -408,6 +434,33 @@ ToolsCoreResetSignalCb(gpointer src,          // IN
 }
 
 
+/*
+ ******************************************************************************
+ *
+ * ToolsCoreConfReloadSignalCb --
+ *  The tools.conf reload callback. The signal was triggered from
+ *  ToolsCore_ReloadConfig. This function is needed to safely run code
+ *  outside of the RPC Channel reset code.
+ *
+ *  Reinitialize the Vmx Guest variables.
+ *
+ * @param[in]  src      The source object.
+ * @param[in]  ctx      The ToolsAppCtx for passing the config.
+ * @param[in]  data     Unused.
+ *
+ ******************************************************************************
+ */
+
+static void
+ToolsCoreConfReloadSignalCb(gpointer src,          // IN
+                            ToolsAppCtx *ctx,      // IN
+                            gpointer data)         // IN
+{
+   g_debug("Reinitialize the guest vars for version data.\n");
+   ToolsCoreReportVersionData(ctx); /* Update version guest vars */
+}
+
+
 /*
  ******************************************************************************
  * ToolsCoreRunLoop --                                                  */ /**
@@ -448,7 +501,7 @@ ToolsCoreRunLoop(ToolsServiceState *state)
 
    /* Report version info as guest Vars */
    if (state->ctx.rpc) {
-      ToolsCoreReportVersionData(state);
+      ToolsCoreReportVersionData(&state->ctx);
    }
 
 #if defined(_WIN32)
@@ -530,6 +583,14 @@ ToolsCoreRunLoop(ToolsServiceState *state)
                           NULL);
       }
 
+      if (g_signal_lookup(TOOLS_CORE_SIG_CONF_RELOAD,
+                          G_OBJECT_TYPE(state->ctx.serviceObj)) != 0) {
+         g_signal_connect(state->ctx.serviceObj,
+                          TOOLS_CORE_SIG_CONF_RELOAD,
+                          G_CALLBACK(ToolsCoreConfReloadSignalCb),
+                          NULL);
+      }
+
       state->configCheckTask = g_timeout_add(CONF_POLL_TIME * 1000,
                                              ToolsCoreConfFileCb,
                                              state);
index 3d4225519cb49a49d733cbf1fbacd344f3a78ee2..b803df75b85d95c30e140a0cf3ddee52da05264c 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (c) 2008-2024 Broadcom. All Rights Reserved.
+ * Copyright (c) 2008-2025 Broadcom. All Rights Reserved.
  * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -69,6 +69,7 @@ ToolsCoreCheckReset(RpcChannel *chan,
 {
    ToolsServiceState *state = _state;
    static gboolean version_sent = FALSE;
+   static gboolean useLegacyVersion = FALSE;
 
    ASSERT(state != NULL);
    ASSERT(chan == state->ctx.rpc);
@@ -76,6 +77,7 @@ ToolsCoreCheckReset(RpcChannel *chan,
    if (success) {
       const gchar *app;
       gchar *msg;
+      gboolean confUseLegacyVersion;
 
       app = ToolsCore_GetTcloName(state);
       if (app == NULL) {
@@ -89,16 +91,35 @@ ToolsCoreCheckReset(RpcChannel *chan,
       }
       g_free(msg);
 
-      if (!version_sent) {
+      /*
+       * Check the config values to see if revert to older format.
+       * Default is false and new format will be used.
+       */
+      confUseLegacyVersion =
+         VMTools_ConfigGetBoolean(state->ctx.config,
+                                  CONFGROUPNAME_VMTOOLS,
+                                  CONFNAME_USELEGACYVERSION,
+                                  FALSE);
+
+      /* Logging reset */
+      if (!version_sent || confUseLegacyVersion != useLegacyVersion) {
          /*
           * Log the Tools version to the VMX log file. We don't really care
           * if sending the message fails.
           */
-         msg = g_strdup_printf("log %s: Version: %s (%s)",
-                               app, VMTOOLSD_VERSION_STRING, BUILD_NUMBER);
+         g_debug("reset vmtools service: using legacy version=%d\n",
+                 confUseLegacyVersion);
+         if (confUseLegacyVersion) {
+            msg = g_strdup_printf("log %s: Version: %s (%s)",
+                                  app, VMTOOLSD_VERSION_STRING, BUILD_NUMBER);
+         } else {
+            msg = g_strdup_printf("log %s: Version: %s.%s",
+                                  app, VMTOOLSD_VERSION_STRING, BUILD_NUMBER_NUMERIC_STRING);
+         }
          RpcChannel_Send(state->ctx.rpc, msg, strlen(msg) + 1, NULL, NULL);
          g_free(msg);
          /* send message only once to prevent log spewing: */
+         useLegacyVersion = confUseLegacyVersion;
          version_sent = TRUE;
       }
 
index ae9b209a371796659b3703b7be3780e51dab3fba..57ff78dd9f93f967da5576f168f8f224bcc32c3a 100644 (file)
@@ -1,5 +1,6 @@
 /*********************************************************
- * Copyright (c) 2008-2021,2023 VMware, Inc. All rights reserved.
+ * Copyright (c) 2008-2025 Broadcom. All Rights Reserved.
+ * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -28,6 +29,7 @@
 #include <locale.h>
 #include <glib/gstdio.h>
 
+#include "conf.h"
 #include "toolboxCmdInt.h"
 #include "toolboxcmd_version.h"
 #include "system.h"
@@ -523,7 +525,21 @@ main(int argc,    // IN: length of command line arguments
    }
 
    if (show_version) {
-      g_print("%s (%s)\n", TOOLBOXCMD_VERSION_STRING, BUILD_NUMBER);
+      gboolean useLegacyVersion;
+      /*
+       * Check the config values to see if revert to older format.
+       * Default is false and new format will be used.
+       */
+      useLegacyVersion =
+         VMTools_ConfigGetBoolean(conf,
+                                  CONFGROUPNAME_VMTOOLS,
+                                  CONFNAME_USELEGACYVERSION,
+                                  FALSE);
+      if (useLegacyVersion) {
+         g_print("%s (%s)\n", TOOLBOXCMD_VERSION_STRING, BUILD_NUMBER);
+      } else {
+         g_print("%s.%s\n", TOOLBOXCMD_VERSION_STRING, BUILD_NUMBER_NUMERIC_STRING);
+      }
       retval = EXIT_SUCCESS;
    } else if (show_help) {
       ToolboxCmdHelp(argv[0], "help");