]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Change GuestLIB SDK to use new RpcChannel API.
authorVMware, Inc <>
Wed, 18 Sep 2013 03:32:52 +0000 (20:32 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 23 Sep 2013 05:19:59 +0000 (22:19 -0700)
Change GuestLIB SDK to use new RpcChannel API.
1) Change RpcOut_* calls to RpcChanneel_* calls.
2) guestlib SDK now has extra dependency on GLIB and vmtoolslib as
secure guestRPC brings a lot new dependencies (rpcin, asyncsocket, ssl,
datamap, hashmap etc).
3) ship new glib and vmtoolslib for linux and windows packages.
4) merge logging functions (Debug(), Warning()) in vmtools and guestlib
into one to avoid having same function names defined in two libs.
5) update build in open vm tools.
6) app monitor needs to do similar thing, which will be handled by HA
team.

Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/include/vmware/tools/utils.h
open-vm-tools/libguestlib/Makefile.am
open-vm-tools/libguestlib/vmGuestLib.c
open-vm-tools/libvmtools/Makefile.am
open-vm-tools/libvmtools/guestSDKLog.c [new file with mode: 0644]
open-vm-tools/libvmtools/vmtoolsInt.h
open-vm-tools/libvmtools/vmtoolsLog.c

index 13a5e3d84323529be1eca11480510f792a45cccc..6e1931d2dbab05add727a8183cb26fffd404983c 100644 (file)
@@ -139,6 +139,9 @@ VMTools_GetLibdir(void);
 GSource *
 VMTools_CreateTimer(gint timeout);
 
+void
+VMTools_SetGuestSDKMode(void);
+
 GArray *
 VMTools_WrapArray(gconstpointer data,
                   guint elemSize,
index 0ebe8c6ef4f671ad8c0d7c15e52a0c6161f1d603..0d24743a7020658284029c545769106854628064 100644 (file)
@@ -52,6 +52,10 @@ CLEANFILES += $(BUILT_SOURCES)
 
 CFLAGS += -Wno-unused
 
+libguestlib_la_CPPFLAGS =
+libguestlib_la_CPPFLAGS += -DVMTOOLS_USE_GLIB
+libguestlib_la_CPPFLAGS += @GLIB2_CPPFLAGS@
+
 EXTRA_DIST = vmguestlib.pc.in
 
 pkgconfigdir   = $(libdir)/pkgconfig
index 29c7161c4567c876bfe8a8cba53513a18ee666f0..4328ea734559cc17c5f4ec2858830a269f372989 100644 (file)
@@ -27,7 +27,7 @@
 #include "vmGuestLib.h"
 #include "vmGuestLibInt.h"
 #include "str.h"
-#include "rpcout.h"
+#include "vmware/tools/guestrpc.h"
 #include "vmcheck.h"
 #include "util.h"
 #include "debug.h"
@@ -259,6 +259,8 @@ VMGuestLib_OpenHandle(VMGuestLibHandle *handle) // OUT
 {
    VMGuestLibHandleType *data;
 
+   VMTools_SetGuestSDKMode();
+
    if (!VmCheck_IsVirtualWorld()) {
       Debug("VMGuestLib_OpenHandle: Not in a VM.\n");
       return VMGUESTLIB_ERROR_NOT_RUNNING_IN_VM;
@@ -379,7 +381,7 @@ VMGuestLibUpdateInfo(VMGuestLibHandle handle) // IN
                   hostVersion);
 
       /* Send the request. */
-      if (RpcOut_sendOne(&reply, &replyLen, commandBuf)) {
+      if (RpcChannel_SendOne(&reply, &replyLen, commandBuf)) {
          VMGuestLibDataV2 *v2reply = (VMGuestLibDataV2 *)reply;
          VMSessionId sessionId = HANDLE_SESSIONID(handle);
 
@@ -1798,7 +1800,8 @@ VMGuestLibIoctl(const GuestLibIoctlParam *param,
       DynXdr_Destroy(&xdrs, TRUE);
       return FALSE;
    }
-   ret = RpcOut_SendOneRaw(DynXdr_Get(&xdrs), xdr_getpos(&xdrs), reply, replySize);
+   ret = RpcChannel_SendOneRaw(DynXdr_Get(&xdrs), xdr_getpos(&xdrs),
+                               reply, replySize);
    DynXdr_Destroy(&xdrs, TRUE);
    return ret;
 }
index 2bc00dc3c643ee52877e8c73b3cc7a0597bf0562..d01a9717b7c2e4c765284f0928538b488dd3226c 100644 (file)
@@ -67,6 +67,7 @@ libvmtools_la_SOURCES += vmtools.c
 libvmtools_la_SOURCES += vmtoolsConfig.c
 libvmtools_la_SOURCES += vmtoolsLog.c
 libvmtools_la_SOURCES += vmxLogger.c
+libvmtools_la_SOURCES += guestSDKLog.c
 
 # Recompile the stub for Log_* functions, but not Log() itself (see -DNO_LOG_STUB).
 libvmtools_la_SOURCES += $(top_srcdir)/lib/stubs/stub-log.c
diff --git a/open-vm-tools/libvmtools/guestSDKLog.c b/open-vm-tools/libvmtools/guestSDKLog.c
new file mode 100644 (file)
index 0000000..b19f3a5
--- /dev/null
@@ -0,0 +1,149 @@
+/*********************************************************
+ * Copyright (C) 2013 VMware, Inc. All rights reserved.
+ *
+ * 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
+ * by the Free Software Foundation version 2.1 and no later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
+ *
+ *********************************************************/
+
+/*
+ * guestSDKLog.c --
+ *
+ *   guestSDK logging stubs. In guestSDK, we only do logging in OBJ builds.
+ *
+ */
+
+#include <stdio.h>
+#include "str.h"
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * GuestSDK_Debug --
+ *
+ *    Log debug messages.
+ *
+ * Results:
+ *    None.
+ *
+ * Side effects:
+ *    Death.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+GuestSDK_Debug(const char *fmt, ...)
+{
+#ifdef VMX86_LOG /* only do logging on OBJ builds */
+   va_list args;
+
+   va_start(args, fmt);
+   vfprintf(stderr, fmt, args);
+   va_end(args);
+#endif
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * GuestSDK_Log --
+ *
+ *    Log messages.
+ *
+ * Results:
+ *    None.
+ *
+ * Side effects:
+ *    Death.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+GuestSDK_Log(const char *fmt, ...)
+{
+#ifdef VMX86_LOG /* only do logging on OBJ builds */
+   va_list args;
+
+   va_start(args, fmt);
+   vfprintf(stderr, fmt, args);
+   va_end(args);
+#endif
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * GuestSDK_Warning --
+ *
+ *    Log warning messages.
+ *
+ * Results:
+ *    None.
+ *
+ * Side effects:
+ *    Death.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+GuestSDK_Warning(const char *fmt, ...)
+{
+#ifdef VMX86_LOG /* only do logging on OBJ builds */
+   va_list args;
+
+   va_start(args, fmt);
+   vfprintf(stderr, fmt, args);
+   va_end(args);
+#endif
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * GuestSDK_Panic --
+ *
+ *    Panic.  Apps have to implement this for themselves.
+ *
+ * Results:
+ *    None.
+ *
+ * Side effects:
+ *    Death.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+GuestSDK_Panic(const char *fmt, ...) // IN
+{
+   va_list args;
+   char buffer[1024];
+   volatile char *p = NULL;
+
+   va_start(args, fmt);
+   Str_Vsnprintf(buffer, sizeof buffer, fmt, args);
+   va_end(args);
+
+   printf("PANIC: %s", buffer);
+
+   /* force segfault */
+   buffer[0] = *p;
+   while (1) ; // avoid compiler warning
+}
index cc512217cb34d78bf5e2d928e8bc2646e5a41d60..a2ff9c640fbc40b8699918e9a6f20e3a2eaf6cbd 100644 (file)
@@ -52,5 +52,17 @@ VMToolsAsprintf(gchar **string,
                 gchar const *format,
                 ...)  PRINTF_DECL(2, 3);
 
+void
+GuestSDK_Debug(const char *fmt, ...);
+
+void
+GuestSDK_Log(const char *fmt, ...);
+
+void
+GuestSDK_Warning(const char *fmt, ...);
+
+void
+GuestSDK_Panic(const char *fmt, ...);
+
 #endif /* _VMTOOLSINT_H_ */
 
index b576724a6cc86cced27afe83c9352d7c01c35407..2a093c4aa21987aaea69dde65617f450a165010d 100644 (file)
@@ -108,6 +108,7 @@ typedef struct LogHandler {
 static gchar *gLogDomain = NULL;
 static gboolean gEnableCoreDump = TRUE;
 static gboolean gLogEnabled = FALSE;
+static gboolean gGuestSDKMode = FALSE;
 static guint gPanicCount = 0;
 static LogHandler *gDefaultData;
 static LogHandler *gErrorData;
@@ -917,6 +918,17 @@ VMToolsLogWrapper(GLogLevelFlags level,
 }
 
 
+/**
+ * Called if vmtools lib is used along with Guestlib SDK.
+ */
+
+void
+VMTools_SetGuestSDKMode(void)
+{
+   gGuestSDKMode = TRUE;
+}
+
+
 /**
  * Logs a message using the G_LOG_LEVEL_DEBUG level.
  *
@@ -928,7 +940,11 @@ Debug(const char *fmt, ...)
 {
    va_list args;
    va_start(args, fmt);
-   VMToolsLogWrapper(G_LOG_LEVEL_DEBUG, fmt, args);
+   if (gGuestSDKMode) {
+      GuestSDK_Debug(fmt, args);
+   } else {
+      VMToolsLogWrapper(G_LOG_LEVEL_DEBUG, fmt, args);
+   }
    va_end(args);
 }
 
@@ -944,7 +960,11 @@ Log(const char *fmt, ...)
 {
    va_list args;
    va_start(args, fmt);
-   VMToolsLogWrapper(G_LOG_LEVEL_INFO, fmt, args);
+   if (gGuestSDKMode) {
+      GuestSDK_Log(fmt, args);
+   } else {
+      VMToolsLogWrapper(G_LOG_LEVEL_INFO, fmt, args);
+   }
    va_end(args);
 }
 
@@ -1010,31 +1030,37 @@ Panic(const char *fmt, ...)
    va_list args;
 
    va_start(args, fmt);
-   if (gPanicCount == 0) {
-      char *msg = Str_Vasprintf(NULL, fmt, args);
-      if (msg != NULL) {
-         g_log(gLogDomain, G_LOG_LEVEL_ERROR, "%s", msg);
-         free(msg);
-      }
-      /*
-       * In case an user-installed custom handler doesn't panic on error, force a
-       * core dump. Also force a dump in the recursive case.
-       */
-      VMToolsLogPanic();
-   } else if (gPanicCount == 1) {
-      /*
-       * Use a stack allocated string since we're in a recursive panic, so
-       * probably already in a weird state.
-       */
-      gchar msg[1024];
-      Str_Vsnprintf(msg, sizeof msg, fmt, args);
-      fprintf(stderr, "Recursive panic: %s\n", msg);
-      VMToolsLogPanic();
+
+   if (gGuestSDKMode) {
+      GuestSDK_Panic(fmt, args);
    } else {
-      fprintf(stderr, "Recursive panic, giving up.\n");
-      exit(-1);
+      if (gPanicCount == 0) {
+         char *msg = Str_Vasprintf(NULL, fmt, args);
+         if (msg != NULL) {
+            g_log(gLogDomain, G_LOG_LEVEL_ERROR, "%s", msg);
+            free(msg);
+         }
+         /*
+          * In case an user-installed custom handler doesn't panic on error,
+          * force a core dump. Also force a dump in the recursive case.
+          */
+         VMToolsLogPanic();
+      } else if (gPanicCount == 1) {
+         /*
+          * Use a stack allocated string since we're in a recursive panic, so
+          * probably already in a weird state.
+          */
+         gchar msg[1024];
+         Str_Vsnprintf(msg, sizeof msg, fmt, args);
+         fprintf(stderr, "Recursive panic: %s\n", msg);
+         VMToolsLogPanic();
+      } else {
+         fprintf(stderr, "Recursive panic, giving up.\n");
+         exit(-1);
+      }
    }
    va_end(args);
+   while (1) ; // avoid compiler warning
 }
 
 
@@ -1049,7 +1075,11 @@ Warning(const char *fmt, ...)
 {
    va_list args;
    va_start(args, fmt);
-   VMToolsLogWrapper(G_LOG_LEVEL_WARNING, fmt, args);
+   if (gGuestSDKMode) {
+      GuestSDK_Warning(fmt, args);
+   } else {
+      VMToolsLogWrapper(G_LOG_LEVEL_WARNING, fmt, args);
+   }
    va_end(args);
 }