From: Kruti Pendharkar Date: Wed, 8 Jan 2025 06:05:51 +0000 (-0800) Subject: With this modification to VMware Tools Support script, the files listed under X-Git-Tag: stable-13.0.0~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=477886b720ad44ae632e0a1ffa9a3fe8f84730b7;p=thirdparty%2Fopen-vm-tools.git With this modification to VMware Tools Support script, the files listed under "logging" section in tools.conf file are additionally bundled into tar archive. --- diff --git a/open-vm-tools/scripts/common/vm-support b/open-vm-tools/scripts/common/vm-support index f949d6bd4..9813ac614 100644 --- a/open-vm-tools/scripts/common/vm-support +++ b/open-vm-tools/scripts/common/vm-support @@ -1,6 +1,7 @@ #!/bin/sh ########################################################## -# Copyright (c) 2006-2022 VMware, Inc. All rights reserved. +# Copyright (c) 2006-2024 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 @@ -133,6 +134,54 @@ addfiles() } +# Get the log files mentioned in the logging section of tools.conf. Get the log +# archive file names +# The archive logic for these logs files seems to be this. Below is one example: +# if vmtoolsd.data = vmtoolsd.log +# then the file is backed up as vmtoolsd.1.log vmtoolsd.2.log etc +# if vmtoolsd.data = vmtoolsdlog +# then the file is backed up as vmtoolsdlog.1 vmtoolsdlog.2 etc +# if vmtoolsd.data = vmtoolsdlog.a +# then the file is backed up as vmtoolsdlog.1.a vmtoolsdlog.2.a etc +addLogFiles() +{ + IFS="" + vmware-toolbox-cmd config get logging | grep "\.data =" | cut -d"=" -f2 | while read -r logFile; do + logFile=`eval echo "$logFile"` + if [ -z "$logFile" ]; then + continue + fi + + # trim the leading spaces + logFile=`echo $logFile | sed 's/^ *//'` + dirName=`dirname $logFile` + fileName=`basename $logFile` + + #find and add the current logs + find "$dirName" -maxdepth 1 -name "$fileName" -print | while read -r logFile; do + addfile "$logFile" + done + + # File prefix is the part that is before the last '.' in the file name + fileNamePrefix=`echo $fileName | rev | cut -d"." -f2- | rev` + + # File suffix is the part that is after the last '.' in the file name + fileNameSuffix=`echo $fileName | rev | cut -s -d"." -f1 | rev` + # Add numbers after the prefix to get all the backed up file names + # Also add the .suffix if suffix exists + if [ -z "$fileNameSuffix" ]; then + fileName="${fileNamePrefix}.*[0-9]" + else + fileName="${fileNamePrefix}.*[0-9].${fileNameSuffix}" + fi + + find "$dirName" -maxdepth 1 -name "$fileName" -print | while read -r logFile; do + addfile "$logFile" + done + done +} + + # runcmd($out, $cmd): executes the command redirected to a file runcmd() { @@ -191,6 +240,8 @@ stageLinux() runcmd "/tmp/apt-list.txt" apt list fi runcmd "/tmp/free.txt" free + + addLogFiles } @@ -254,7 +305,7 @@ collectNetworkDetails() export PATH=/bin:/sbin:/usr/bin:/usr/sbin TARFILE=vm-`date +%Y-%m-%d`.$$.tar.gz -VER=0.95 +VER=0.96 # Parse args for option in $@ diff --git a/open-vm-tools/toolbox/l10n/en.vmsg b/open-vm-tools/toolbox/l10n/en.vmsg index fda9d9fd6..4962cf172 100644 --- a/open-vm-tools/toolbox/l10n/en.vmsg +++ b/open-vm-tools/toolbox/l10n/en.vmsg @@ -1,5 +1,6 @@ ########################################################## -# Copyright (c) 2010-2017,2020-2021 VMware, Inc. All rights reserved. +# Copyright (c) 2010-2024 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 @@ -92,7 +93,7 @@ error.novirtual = "%1$s must be run inside a virtual machine.\n" error.unknown = "%1$s: Unknown %2$s '%3$s'\n" -help.config = "%1$s: modify Tools configuration\nUsage: %2$s %3$s \n\nSubcommands:\n get
: display current value for \n NOTE: If the is not present in tools.conf, its\n value from the global configuration is returned if present\n set
: set to \n\n remove
: remove \n\n
can be any supported section, such as logging, guestoperations or guestinfo.\n can be any configuration key.\n can be any value.\n" +help.config = "%1$s: modify Tools configuration\nUsage: %2$s %3$s \n\nSubcommands:\n get
: display all the key values in the
\n get
: display current value for \n NOTE: If the is not present in tools.conf, its\n value from the global configuration is returned if present\n set
: set to \n\n remove
: remove \n\n
can be any supported section, such as logging, guestoperations or guestinfo.\n can be any configuration key.\n can be any value.\n" help.device = "%1$s: functions related to the virtual machine's hardware devices\nUsage: %2$s %3$s [args]\ndev is the name of the device.\n\nSubcommands:\n enable : enable the device dev\n disable : disable the device dev\n list: list all available devices\n status : print the status of a device\n" diff --git a/open-vm-tools/toolbox/toolboxcmd-config.c b/open-vm-tools/toolbox/toolboxcmd-config.c index 8e7b03509..586567a72 100644 --- a/open-vm-tools/toolbox/toolboxcmd-config.c +++ b/open-vm-tools/toolbox/toolboxcmd-config.c @@ -1,5 +1,6 @@ /********************************************************* - * Copyright (c) 2016,2020-2021 VMware, Inc. All rights reserved. + * Copyright (c) 2016-2024 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 @@ -32,6 +33,7 @@ #include "vmware/tools/i18n.h" #include "vmware/tools/utils.h" #include "vmware/tools/log.h" +#include "vm_assert.h" /* @@ -108,7 +110,6 @@ ConfigGet(const char *section, // section { GKeyFile *confDict = NULL; int ret = EXIT_SUCCESS; - gchar *value = NULL; VMTools_LoadConfig(NULL, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, @@ -117,20 +118,44 @@ ConfigGet(const char *section, // section if (confDict) { TOOLBOXCMD_LOAD_GLOBALCONFIG(confDict) - value = g_key_file_get_string(confDict, section, - key, NULL); - } else { - ret = EX_UNAVAILABLE; - } - if (value) { - g_print("[%s] %s = %s\n", section, key, value); + // If there is no key, get all the key value pairs in the section + if (key == NULL) { + gchar **keys; + gsize numKeys; + GError *err = NULL; + int index; + + keys = g_key_file_get_keys(confDict, section, &numKeys, &err); + if (err) { + g_print("[%s] UNSET\n", section); + } else { + g_print("[%s]\n", section); + for (index = 0; index < numKeys; index++) { + gchar *value = g_key_file_get_string(confDict, + section, keys[index], NULL); + ASSERT(value != NULL); + if (value) { + g_print("%s = %s\n", keys[index], value); + } + g_free(value); + } + } + g_strfreev(keys); + } else { + gchar *value = g_key_file_get_string(confDict, section, key, NULL); + if (value) { + g_print("[%s] %s = %s\n", section, key, value); + } else { + g_print("[%s] %s UNSET\n", section, key); + } + g_free(value); + } } else { - g_print("[%s] %s UNSET\n", section, key); + ret = EX_UNAVAILABLE; } g_key_file_free(confDict); - g_free(value); return ret; } @@ -223,23 +248,30 @@ Config_Command(char **argv, // IN: Command line arguments SU_(arg.config.operation, "config operation")); return EX_USAGE; } + op = argv[optind]; if ((optind + 1) >= argc) { ToolsCmd_MissingEntityError(argv[0], SU_(arg.config.section, "config section")); return EX_USAGE; } + section = argv[optind + 1]; if ((optind + 2) >= argc) { - ToolsCmd_MissingEntityError(argv[0], + /* + * For 'get' operation, key is optional + * With no key, 'get' operation prints all key-value pairs in that section + */ + if (toolbox_strcmp(op, "get") != 0) { + ToolsCmd_MissingEntityError(argv[0], SU_(arg.config.key, "config key")); - return EX_USAGE; + return EX_USAGE; + } + key = NULL; + } else { + key = argv[optind + 2]; } - op = argv[optind]; - section = argv[optind + 1]; - key = argv[optind + 2]; - if (toolbox_strcmp(op, "set") == 0) { const char *value; @@ -288,6 +320,7 @@ Config_Help(const char *progName, // IN: The name of the program obtained from a "%s: modify Tools configuration\n" "Usage: %s %s \n\n" "Subcommands:\n" + " get
: display all the key values in the
\n" " get
: display current value for \n" " NOTE: If the is not present in tools.conf, its\n" " value from the global configuration is returned if present\n"