]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Add auto-upgrade command to toolbox CLI.
authorVMware, Inc <>
Thu, 17 Jun 2010 21:05:56 +0000 (14:05 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 17 Jun 2010 21:05:56 +0000 (14:05 -0700)
This change adds a new "upgrade" command to the toolbox CLI on Win32 and
Linux (non-open-vm-tools), which are the only platforms where we have
auto-upgrade.

Add a few utility functions to the common toolbox CLI code to do a few
useful things:
. print messages based on the status of the "quiet" flag.
. send RPCs to the host using the RpcChannel API.

On top of that, put some common definitions of commands and replies in a
shared header to avoid having duplicated strings in different parts of the
source code.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/include/vmware/guestrpc/tclodefs.h
open-vm-tools/toolbox/toolbox-cmd.c
open-vm-tools/toolbox/toolboxCmdInt.h
open-vm-tools/toolbox/toolboxcmd-shrink.c

index 49b399506f743964a827986a267269b3cb77bcf4..7c89312c526f0d279e2df9e944fd2c19cf2819f8 100644 (file)
@@ -40,6 +40,8 @@
 /** TCLO channel name for the HGFS driver. */
 #define TOOLS_HGFS_NAME           "tools-hgfs"
 
+/** Reply from host when the command is not recognized. */
+#define RPCI_UNKNOWN_COMMAND      "Unknown command"
 
 /*
  * Tools options.
 #define TOOLSOPTION_MAP_ROOT_HGFS_SHARE      "mapRootHgfsShare"
 #define TOOLSOPTION_LINK_ROOT_HGFS_SHARE     "linkRootHgfsShare"
 
+/*
+ * Auto-upgrade commands.
+ */
+
+#define AUTOUPGRADE_AVAILABLE_CMD   "vmx.capability.tools_is_upgradable"
+#define AUTOUPGRADE_START_CMD       "guest.initiateAutoUpgrade"
+
+/*
+ * Shrink commands.
+ */
+
+#define DISK_SHRINK_CMD             "disk.shrink"
+
 
 /*
  * The max selection buffer length has to be less than the
index 19f431fd56331871ede65ee6007006d756519296..abfa3723c3f1e0081c6471a3c2433f3f0bfbb081 100644 (file)
@@ -32,6 +32,7 @@
 #include "toolboxCmdInt.h"
 #include "toolboxcmd_version.h"
 #include "system.h"
+#include "vmware/tools/guestrpc.h"
 #include "vmware/tools/i18n.h"
 #include "vmware/tools/utils.h"
 
@@ -75,6 +76,7 @@ static struct option long_options[] = {
    { 0, 0, 0, 0 } };
 #endif
 
+static gboolean gQuiet = FALSE;
 static const char *options = "hqv";
 
 /*
@@ -101,6 +103,9 @@ static CmdTable commands[] = {
    { "disk",      Disk_Command,     TRUE,    TRUE,    Disk_Help},
    { "stat",      Stat_Command,     TRUE,    FALSE,   Stat_Help},
    { "device",    Device_Command,   TRUE,    FALSE,   Device_Help},
+#if (defined(_WIN32) || defined(linux)) && !defined(OPEN_VM_TOOLS)
+   { "upgrade",   Upgrade_Command,  TRUE,    FALSE,   Upgrade_Help},
+#endif
    { "help",      HelpCommand,      FALSE,   FALSE,   ToolboxCmdHelp},
 };
 
@@ -129,6 +134,112 @@ ToolsCmd_MissingEntityError(const char *name,     // IN: command name (argv[0])
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * ToolsCmd_Print --
+ *
+ *      Prints a message to stdout unless quiet output was requested.
+ *
+ * Results:
+ *      None.
+ *
+ * Side effects:
+ *      None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ToolsCmd_Print(const char *fmt,
+               ...)
+{
+   if (!gQuiet) {
+      gchar *str;
+      va_list args;
+
+      va_start(args, fmt);
+      g_vasprintf(&str, fmt, args);
+      va_end(args);
+
+      g_print(str);
+      g_free(str);
+   }
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * ToolsCmd_PrintErr --
+ *
+ *      Prints a message to stderr unless quiet output was requested.
+ *
+ * Results:
+ *      None.
+ *
+ * Side effects:
+ *      None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ToolsCmd_PrintErr(const char *fmt,
+                  ...)
+{
+   if (!gQuiet) {
+      gchar *str;
+      va_list args;
+
+      va_start(args, fmt);
+      g_vasprintf(&str, fmt, args);
+      va_end(args);
+
+      g_printerr(str);
+      g_free(str);
+   }
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * ToolsCmd_SendRPC --
+ *
+ *    Sends an RPC message to the host.
+ *
+ * Results:
+ *    The return value from the RPC.
+ *
+ * Side effects:
+ *    None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+gboolean
+ToolsCmd_SendRPC(const char *rpc,      // IN
+                 size_t rpcLen,        // IN
+                 char **result,        // OUT
+                 size_t *resultLen)    // OUT
+{
+   RpcChannel *chan = BackdoorChannel_New();
+   gboolean ret = RpcChannel_Start(chan);
+
+   if (!ret) {
+      g_warning("Error starting RPC channel.");
+      goto exit;
+   }
+
+   ret = RpcChannel_Send(chan, (char *) rpc, rpcLen, result, resultLen);
+
+exit:
+   RpcChannel_Destroy(chan);
+   return ret;
+}
+
+
 /*
  *-----------------------------------------------------------------------------
  *
@@ -184,7 +295,9 @@ ToolboxCmdHelp(const char *progName,   // IN
                           "   disk\n"
                           "   script\n"
                           "   stat\n"
-                          "   timesync\n\n"
+                          "   timesync\n"
+                          "   upgrade (not available on all operating systems)\n"
+                          "\n"
                           "For additional information please visit http://www.vmware.com/support/\n\n"),
            progName, progName, cmd, progName);
 }
@@ -293,7 +406,6 @@ main(int argc,    // IN: length of command line arguments
    CmdTable *cmd = NULL;
    int c;
    int retval;
-   gboolean quiet = FALSE;
 
    setlocale(LC_ALL, "");
    VMTools_ConfigLogging("toolboxcmd", NULL, FALSE, FALSE);
@@ -335,7 +447,7 @@ main(int argc,    // IN: length of command line arguments
          break;
 
       case 'q':
-         quiet = TRUE;
+         gQuiet = TRUE;
          break;
 
       case '?':
@@ -380,7 +492,7 @@ main(int argc,    // IN: length of command line arguments
          ToolsCmd_MissingEntityError(argv[0], SU_(arg.subcommand, "subcommand"));
          retval = EX_USAGE;
       } else {
-         retval = cmd->func(argv, argc, quiet);
+         retval = cmd->func(argv, argc, gQuiet);
       }
 
       if (retval == EX_USAGE && (cmd == NULL || strcmp(cmd->command, "help"))) {
index 55b456921e135144a8e7e7d2ab1112ddf1007091..693a3efc62a1a7d6370cb668dfd17b4625fd8053 100644 (file)
@@ -89,6 +89,23 @@ ToolsCmd_UnknownEntityError(const char *name,
                             const char *entity,
                             const char *str);
 
+void
+ToolsCmd_Print(const char *fmt,
+               ...) PRINTF_DECL(1, 2);
+
+void
+ToolsCmd_PrintErr(const char *fmt,
+                  ...) PRINTF_DECL(1, 2);
+
+gboolean
+ToolsCmd_SendRPC(const char *rpc,
+                 size_t rpcLen,
+                 char **result,
+                 size_t *resultLen);
+
+/*
+ * Command declarations.
+ */
 
 /**
  * A shorthand macro for declaring a command entry. This just declares
@@ -110,4 +127,8 @@ DECLARE_COMMAND(Script);
 DECLARE_COMMAND(Stat);
 DECLARE_COMMAND(TimeSync);
 
+#if defined(_WIN32) || (defined(linux) && !defined(OPEN_VM_TOOLS))
+DECLARE_COMMAND(Upgrade);
+#endif
+
 #endif /*_TOOLBOX_CMD_H_*/
index 9b1bca31e052de779d617940003136c39c23c9b8..60604291cd3879aecd6cecfd417724685f91ca70 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "toolboxCmdInt.h"
 #include "rpcout.h"
+#include "vmware/guestrpc/tclodefs.h"
 #include "vmware/tools/i18n.h"
 
 #ifndef _WIN32
@@ -243,7 +244,8 @@ ShrinkDoShrink(char *mountPoint, // IN: mount point
       char *result;
       size_t resultLen;
 
-      if (RpcOut_sendOne(&result, &resultLen, "disk.shrink")) {
+      if (ToolsCmd_SendRPC(DISK_SHRINK_CMD, sizeof DISK_SHRINK_CMD - 1,
+                           &result, &resultLen)) {
          if (!quiet) {
             printf("\nDisk shrinking complete\n");
          }
@@ -251,7 +253,7 @@ ShrinkDoShrink(char *mountPoint, // IN: mount point
          goto out;
       }
 
-      fprintf(stderr, "%s\n", result);
+      fprintf(stderr, "\n%s\n", result);
    }
 
    fprintf(stderr, "Shrinking not completed\n");