]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix nested logging for VmxLogger with vsocket channel.
authorVMware, Inc <>
Wed, 18 Sep 2013 03:39:21 +0000 (20:39 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 23 Sep 2013 05:26:42 +0000 (22:26 -0700)
Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/include/vmware/tools/utils.h
open-vm-tools/libvmtools/vmtoolsLog.c
open-vm-tools/libvmtools/vmxLogger.c

index 6e1931d2dbab05add727a8183cb26fffd404983c..676d9000e4190a761c6aa8b5320cc6b2fb053dd3 100644 (file)
@@ -142,6 +142,12 @@ VMTools_CreateTimer(gint timeout);
 void
 VMTools_SetGuestSDKMode(void);
 
+void
+VMTools_StopLogging(void);
+
+void
+VMTools_RestartLogging(void);
+
 GArray *
 VMTools_WrapArray(gconstpointer data,
                   guint elemSize,
index 2a093c4aa21987aaea69dde65617f450a165010d..de5972dea34cb80886fb54273fc24c91abd48ca0 100644 (file)
@@ -114,6 +114,7 @@ static LogHandler *gDefaultData;
 static LogHandler *gErrorData;
 static GPtrArray *gDomains = NULL;
 static gboolean gLogInitialized = FALSE;
+static gboolean gLoggingStopped = FALSE;
 
 /* Internal functions. */
 
@@ -903,6 +904,11 @@ VMToolsLogWrapper(GLogLevelFlags level,
       return;
    }
 
+   if (gLoggingStopped) {
+      /* This is to avoid nested logging in vmxLogger */
+      return;
+   }
+
    if (gPanicCount == 0) {
       char *msg = Str_Vasprintf(NULL, fmt, args);
       if (msg != NULL) {
@@ -918,6 +924,28 @@ VMToolsLogWrapper(GLogLevelFlags level,
 }
 
 
+/**
+ * This is called to avoid nested logging in vmxLogger.
+ */
+
+void
+VMTools_StopLogging(void)
+{
+   gLoggingStopped = TRUE;
+}
+
+
+/**
+ * This is called to reset logging in vmxLogger.
+ */
+
+void
+VMTools_RestartLogging(void)
+{
+   gLoggingStopped = FALSE;
+}
+
+
 /**
  * Called if vmtools lib is used along with Guestlib SDK.
  */
index fa606935d076ec850a18800ff1eed33b0ef5cd9a..fecc69a70609d98bebcdea6c387161e2a340f99d 100644 (file)
@@ -36,7 +36,7 @@ typedef struct VMXLoggerData {
  *******************************************************************************
  * VMXLoggerLog --                                                        */ /**
  *
- * Logs a message to the VMX using the backdoor.
+ * Logs a message to the VMX using RpcChannel.
  *
  * The logger uses its own RpcChannel, opening and closing the channel for each
  * log message sent. This is not optimal, especially if the application already
@@ -61,20 +61,25 @@ VMXLoggerLog(const gchar *domain,
    VMXLoggerData *logger = data;
 
    g_static_mutex_lock(&logger->lock);
+
+   /*
+    * To avoid nested logging inside of RpcChannel, we need to disable logging
+    * here. See bug 1069390.
+    */
+
+   VMTools_StopLogging();
+
    if (RpcChannel_Start(logger->chan)) {
       gchar *msg;
       gint cnt = VMToolsAsprintf(&msg, "log %s", message);
 
-      /*
-       * XXX: RpcChannel_Send() can log stuff in certain situations, which will
-       * cause this to blow up. Hopefully we won't hit those too often since
-       * we're stopping / starting the channel for each log message.
-       */
       RpcChannel_Send(logger->chan, msg, cnt, NULL, NULL);
 
       g_free(msg);
       RpcChannel_Stop(logger->chan);
    }
+
+   VMTools_RestartLogging();
    g_static_mutex_unlock(&logger->lock);
 }