]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Replace some RpcOut_* API using new RpcChannel API.
authorVMware, Inc <>
Wed, 18 Sep 2013 03:24:59 +0000 (20:24 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 23 Sep 2013 05:06:58 +0000 (22:06 -0700)
Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/include/vmware/tools/guestrpc.h
open-vm-tools/lib/rpcChannel/rpcChannel.c

index bb1d9a26b25ae34082600b19c68213e11d4e6d8c..b90e0b25fa04e2982b041f8dd47ff10ba680c7e3 100644 (file)
@@ -192,6 +192,12 @@ RpcChannel_SendOneRaw(const char *data,
                       char **result,
                       size_t *resultLen);
 
+gboolean
+RpcChannel_SendOne(char **reply,
+                   size_t *repLen,
+                   const char *reqFmt,
+                   ...);
+
 RpcChannel *
 RpcChannel_New(void);
 
index d22e5c8a3664ccfc13b550b68c03c020ac44c002..96a7869561ac6edf301ddd5e19052612f3f6549e 100644 (file)
@@ -899,3 +899,84 @@ sent:
 
    return status;
 }
+
+
+/**
+ * Open/close RpcChannel each time for sending a Rpc message, this is a wrapper
+ * for RpcChannel APIs.
+ *
+ * @param[out] reply       reply
+ * @param[out] repLen      reply length
+ * @param[in]  reqFmt      request data
+ * @param[in]  ...         optional arguments depending on reqFmt.
+
+ * @returns    TRUE on success.
+ */
+
+gboolean
+RpcChannel_SendOne(char **reply,
+                   size_t *repLen,
+                   char const *reqFmt,
+                   ...)
+{
+   va_list args;
+   gboolean status;
+   char *request;
+   size_t reqLen = 0;
+
+   status = FALSE;
+
+   /* Format the request string */
+   va_start(args, reqFmt);
+   request = Str_Vasprintf(&reqLen, reqFmt, args);
+   va_end(args);
+
+   /*
+    * If Str_Vasprintf failed, write NULL into the reply if the caller wanted
+    * a reply back.
+    */
+   if (request == NULL) {
+      goto error;
+   }
+
+   /*
+    * If the command doesn't contain a space, add one to the end to maintain
+    * compatibility with old VMXs.
+    *
+    * For a long time, the GuestRpc logic in the VMX was wired to expect a
+    * trailing space in every command, even commands without arguments. That is
+    * no longer true, but we must continue to add a trailing space because we
+    * don't know whether we're talking to an old or new VMX.
+    */
+   if (request[reqLen - 1] != ' ') {
+      char *tmp;
+
+      tmp = Str_Asprintf(NULL, "%s ", request);
+      free(request);
+      request = tmp;
+
+      /*
+       * If Str_Asprintf failed, write NULL into reply if the caller wanted
+       * a reply back.
+       */
+      if (request == NULL) {
+         goto error;
+      }
+   }
+
+   status = RpcChannel_SendOneRaw(request, reqLen, reply, repLen);
+
+   free(request);
+
+   return status;
+
+error:
+   if (reply) {
+      *reply = NULL;
+   }
+
+   if (repLen) {
+      *repLen = 0;
+   }
+   return FALSE;
+}