From: VMware, Inc <> Date: Wed, 18 Sep 2013 03:39:21 +0000 (-0700) Subject: Fix nested logging for VmxLogger with vsocket channel. X-Git-Tag: 2013.09.16-1328054~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb790dbad75717d0ffb99bc268ee9ed6214c93ba;p=thirdparty%2Fopen-vm-tools.git Fix nested logging for VmxLogger with vsocket channel. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/include/vmware/tools/utils.h b/open-vm-tools/lib/include/vmware/tools/utils.h index 6e1931d2d..676d9000e 100644 --- a/open-vm-tools/lib/include/vmware/tools/utils.h +++ b/open-vm-tools/lib/include/vmware/tools/utils.h @@ -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, diff --git a/open-vm-tools/libvmtools/vmtoolsLog.c b/open-vm-tools/libvmtools/vmtoolsLog.c index 2a093c4aa..de5972dea 100644 --- a/open-vm-tools/libvmtools/vmtoolsLog.c +++ b/open-vm-tools/libvmtools/vmtoolsLog.c @@ -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. */ diff --git a/open-vm-tools/libvmtools/vmxLogger.c b/open-vm-tools/libvmtools/vmxLogger.c index fa606935d..fecc69a70 100644 --- a/open-vm-tools/libvmtools/vmxLogger.c +++ b/open-vm-tools/libvmtools/vmxLogger.c @@ -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); }