From: VMware, Inc <> Date: Wed, 18 Sep 2013 03:24:59 +0000 (-0700) Subject: Replace some RpcOut_* API using new RpcChannel API. X-Git-Tag: 2013.09.16-1328054~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2676c087a208e8bca090c741ef34d6ff1a8cc6b;p=thirdparty%2Fopen-vm-tools.git Replace some RpcOut_* API using new RpcChannel API. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/include/vmware/tools/guestrpc.h b/open-vm-tools/lib/include/vmware/tools/guestrpc.h index bb1d9a26b..b90e0b25f 100644 --- a/open-vm-tools/lib/include/vmware/tools/guestrpc.h +++ b/open-vm-tools/lib/include/vmware/tools/guestrpc.h @@ -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); diff --git a/open-vm-tools/lib/rpcChannel/rpcChannel.c b/open-vm-tools/lib/rpcChannel/rpcChannel.c index d22e5c8a3..96a786956 100644 --- a/open-vm-tools/lib/rpcChannel/rpcChannel.c +++ b/open-vm-tools/lib/rpcChannel/rpcChannel.c @@ -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; +}