From nobody Sun Apr 28 23:23:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518249796880620.7979842457404; Sat, 10 Feb 2018 00:03:16 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3B595F7B5; Sat, 10 Feb 2018 08:03:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDCF260BE2; Sat, 10 Feb 2018 08:03:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 929A64A46C; Sat, 10 Feb 2018 08:03:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1A8384G001291 for ; Sat, 10 Feb 2018 03:03:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id CE9492166BB3; Sat, 10 Feb 2018 08:03:08 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-25.brq.redhat.com [10.40.204.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1F5A2166BAE; Sat, 10 Feb 2018 08:03:07 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Sat, 10 Feb 2018 09:02:59 +0100 Message-Id: <1580575fd2a3302586e8eeae25834b8752d31b3e.1518249754.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: lkundrak@v3.sk Subject: [libvirt] [PATCH] virlog: Allow opting out from logging X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 10 Feb 2018 08:03:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" After 759b4d1b0fe5f we are getting hostname in virLogOnceInit(). Problem with this approach is in the NSS module because the module calls some internal APIs which occasionally want to log something. This results in virLogInitialize() to be called which in turn ends up calling virGetHostnameQuiet() and effectively the control gets to NSS plugin again which calls some internal APIs which occasionally want to log something. You can see the deadlock now. One way out from this is to turn logging into no-op. Which kind of makes sense - the NSS module shouldn't log anything. To achieve this, the virLogVMessage() function is provided with separate no-op implementation if DISABLE_LOGGING_FOR_NSS macro is set. Signed-off-by: Michal Privoznik --- config-post.h | 1 + src/util/virlog.c | 119 ++++++++++++++++++++++++++++++++------------------= ---- 2 files changed, 71 insertions(+), 49 deletions(-) diff --git a/config-post.h b/config-post.h index f7eba0d7c..95e834f8e 100644 --- a/config-post.h +++ b/config-post.h @@ -72,6 +72,7 @@ # undef WITH_SECDRIVER_SELINUX # undef WITH_SECDRIVER_APPARMOR # undef WITH_CAPNG +# define DISABLE_LOGGING_FOR_NSS #endif /* LIBVIRT_NSS */ =20 #ifndef __GNUC__ diff --git a/src/util/virlog.c b/src/util/virlog.c index 8f1e4800d..3284bdc03 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -241,23 +241,6 @@ virLogGetDefaultOutput(void) } =20 =20 -static const char * -virLogPriorityString(virLogPriority lvl) -{ - switch (lvl) { - case VIR_LOG_DEBUG: - return "debug"; - case VIR_LOG_INFO: - return "info"; - case VIR_LOG_WARN: - return "warning"; - case VIR_LOG_ERROR: - return "error"; - } - return "unknown"; -} - - static int virLogOnceInit(void) { @@ -429,6 +412,60 @@ virLogOutputListFree(virLogOutputPtr *list, int count) } =20 =20 +/** + * virLogMessage: + * @source: where is that message coming from + * @priority: the priority level + * @filename: file where the message was emitted + * @linenr: line where the message was emitted + * @funcname: the function emitting the (debug) message + * @metadata: NULL or metadata array, terminated by an item with NULL key + * @fmt: the string format + * @...: the arguments + * + * Call the libvirt logger with some information. Based on the configurati= on + * the message may be stored, sent to output or just discarded + */ +void +virLogMessage(virLogSourcePtr source, + virLogPriority priority, + const char *filename, + int linenr, + const char *funcname, + virLogMetadataPtr metadata, + const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + virLogVMessage(source, priority, + filename, linenr, funcname, + metadata, fmt, ap); + va_end(ap); +} + + +/* For the library we compile in logging code and then turn it + * on/off depending on user settings. However, for the NSS plugin + * we might get into deadlock and logging there is not really + * needed. */ +#ifndef DISABLE_LOGGING_FOR_NSS +static const char * +virLogPriorityString(virLogPriority lvl) +{ + switch (lvl) { + case VIR_LOG_DEBUG: + return "debug"; + case VIR_LOG_INFO: + return "info"; + case VIR_LOG_WARN: + return "warning"; + case VIR_LOG_ERROR: + return "error"; + } + return "unknown"; +} + + static int virLogFormatString(char **msg, int linenr, @@ -514,38 +551,6 @@ virLogSourceUpdate(virLogSourcePtr source) virLogUnlock(); } =20 -/** - * virLogMessage: - * @source: where is that message coming from - * @priority: the priority level - * @filename: file where the message was emitted - * @linenr: line where the message was emitted - * @funcname: the function emitting the (debug) message - * @metadata: NULL or metadata array, terminated by an item with NULL key - * @fmt: the string format - * @...: the arguments - * - * Call the libvirt logger with some information. Based on the configurati= on - * the message may be stored, sent to output or just discarded - */ -void -virLogMessage(virLogSourcePtr source, - virLogPriority priority, - const char *filename, - int linenr, - const char *funcname, - virLogMetadataPtr metadata, - const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - virLogVMessage(source, priority, - filename, linenr, funcname, - metadata, fmt, ap); - va_end(ap); -} - - /** * virLogVMessage: * @source: where is that message coming from @@ -678,6 +683,22 @@ virLogVMessage(virLogSourcePtr source, errno =3D saved_errno; } =20 +#else /* DISABLE_LOGGING_FOR_NSS */ + +void +virLogVMessage(virLogSourcePtr source ATTRIBUTE_UNUSED, + virLogPriority priority ATTRIBUTE_UNUSED, + const char *filename ATTRIBUTE_UNUSED, + int linenr ATTRIBUTE_UNUSED, + const char *funcname ATTRIBUTE_UNUSED, + virLogMetadataPtr metadata ATTRIBUTE_UNUSED, + const char *fmt ATTRIBUTE_UNUSED, + va_list vargs ATTRIBUTE_UNUSED) +{ + return; +} + +#endif /* DISABLE_LOGGING_FOR_NSS */ =20 static void virLogStackTraceToFd(int fd) --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list