From: Kruti Pendharkar Date: Tue, 24 Jun 2025 16:26:23 +0000 (-0700) Subject: Change to common source files not applicable to open-vm-tools. X-Git-Tag: stable-13.1.0~150 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c6a2991f60917e6bec78f08b45a028773f64e7c8;p=thirdparty%2Fopen-vm-tools.git Change to common source files not applicable to open-vm-tools. --- diff --git a/open-vm-tools/lib/include/conf.h b/open-vm-tools/lib/include/conf.h index eca86fe42..fc3763dc1 100644 --- a/open-vm-tools/lib/include/conf.h +++ b/open-vm-tools/lib/include/conf.h @@ -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" diff --git a/open-vm-tools/libvmtools/vmtoolsLog.c b/open-vm-tools/libvmtools/vmtoolsLog.c index bb5be8209..679467572 100644 --- a/open-vm-tools/libvmtools/vmtoolsLog.c +++ b/open-vm-tools/libvmtools/vmtoolsLog.c @@ -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) { diff --git a/open-vm-tools/services/vmtoolsd/cmdLine.c b/open-vm-tools/services/vmtoolsd/cmdLine.c index e2ceae834..a6a2a8028 100644 --- a/open-vm-tools/services/vmtoolsd/cmdLine.c +++ b/open-vm-tools/services/vmtoolsd/cmdLine.c @@ -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); } diff --git a/open-vm-tools/services/vmtoolsd/mainLoop.c b/open-vm-tools/services/vmtoolsd/mainLoop.c index 4b3595058..b37607f90 100644 --- a/open-vm-tools/services/vmtoolsd/mainLoop.c +++ b/open-vm-tools/services/vmtoolsd/mainLoop.c @@ -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); diff --git a/open-vm-tools/services/vmtoolsd/toolsRpc.c b/open-vm-tools/services/vmtoolsd/toolsRpc.c index 3d4225519..b803df75b 100644 --- a/open-vm-tools/services/vmtoolsd/toolsRpc.c +++ b/open-vm-tools/services/vmtoolsd/toolsRpc.c @@ -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; } diff --git a/open-vm-tools/toolbox/toolbox-cmd.c b/open-vm-tools/toolbox/toolbox-cmd.c index ae9b209a3..57ff78dd9 100644 --- a/open-vm-tools/toolbox/toolbox-cmd.c +++ b/open-vm-tools/toolbox/toolbox-cmd.c @@ -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 #include +#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");