]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
With this modification to VMware Tools Support script, the files listed under
authorKruti Pendharkar <kp025370@broadcom.com>
Wed, 8 Jan 2025 06:05:51 +0000 (22:05 -0800)
committerKruti Pendharkar <kp025370@broadcom.com>
Wed, 8 Jan 2025 06:05:51 +0000 (22:05 -0800)
"logging" section in tools.conf file are additionally bundled into tar
archive.

open-vm-tools/scripts/common/vm-support
open-vm-tools/toolbox/l10n/en.vmsg
open-vm-tools/toolbox/toolboxcmd-config.c

index f949d6bd4763a82b39a1678ad7ed5912b6619d58..9813ac614c7fb55482ed99f3e4ba7e5333a7b0e0 100644 (file)
@@ -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 $@
index fda9d9fd63974fab552a5eecb0cf309bab3b5c4a..4962cf172fbb288ff101bc57eec951a8054aa3f4 100644 (file)
@@ -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 <subcommand>\n\nSubcommands:\n   get <section> <key>: display current value for <key>\n   NOTE: If the <key> is not present in tools.conf, its\n   value from the global configuration is returned if present\n   set <section> <key> <value>: set <key> to <value>\n\n   remove <section> <key>: remove <key>\n\n<section> can be any supported section, such as logging, guestoperations or guestinfo.\n<key> can be any configuration key.\n<value> can be any value.\n"
+help.config = "%1$s: modify Tools configuration\nUsage: %2$s %3$s <subcommand>\n\nSubcommands:\n   get <section> : display all the key values in the <section>\n   get <section> <key>: display current value for <key>\n   NOTE: If the <key> is not present in tools.conf, its\n   value from the global configuration is returned if present\n   set <section> <key> <value>: set <key> to <value>\n\n   remove <section> <key>: remove <key>\n\n<section> can be any supported section, such as logging, guestoperations or guestinfo.\n<key> can be any configuration key.\n<value> can be any value.\n"
 
 help.device = "%1$s: functions related to the virtual machine's hardware devices\nUsage: %2$s %3$s <subcommand> [args]\ndev is the name of the device.\n\nSubcommands:\n   enable <dev>: enable the device dev\n   disable <dev>: disable the device dev\n   list: list all available devices\n   status <dev>: print the status of a device\n"
 
index 8e7b03509bd88bfb30777b4968a95f75308815da..586567a725a48828b30fe2666d038d516372d135 100644 (file)
@@ -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 <subcommand>\n\n"
                "Subcommands:\n"
+               "   get <section> : display all the key values in the <section>\n"
                "   get <section> <key>: display current value for <key>\n"
                "   NOTE: If the <key> is not present in tools.conf, its\n"
                "   value from the global configuration is returned if present\n"