From nobody Wed May 14 07:55:10 2025 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 1524243431969180.22929562630213; Fri, 20 Apr 2018 09:57:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42F2F3182F42; Fri, 20 Apr 2018 16:57:10 +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 01A505BD65; Fri, 20 Apr 2018 16:57:10 +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 96D934CAA4; Fri, 20 Apr 2018 16:57:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3KGujbr019464 for ; Fri, 20 Apr 2018 12:56:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id DA53F11701C3; Fri, 20 Apr 2018 16:56:45 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 575AF11701C6; Fri, 20 Apr 2018 16:56:45 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 20 Apr 2018 17:56:38 +0100 Message-Id: <20180420165639.8386-4-berrange@redhat.com> In-Reply-To: <20180420165639.8386-1-berrange@redhat.com> References: <20180420165639.8386-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH 3/4] log: support logging using shell wildcard syntax 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: , Content-Type: text/plain; charset="utf-8" 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 20 Apr 2018 16:57:10 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Rather than specialcasing handling of the '*' character, use fnmatch() to get normal shell wildcard syntax, as described in 'man glob(7)'. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/virlog.c | 17 +++++++++++++++-- src/util/virlog.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/util/virlog.c b/src/util/virlog.c index 5262d613f6..1db10fcc71 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -40,6 +40,7 @@ #if HAVE_SYS_UN_H # include #endif +#include =20 #include "virerror.h" #include "virlog.h" @@ -508,7 +509,9 @@ virLogSourceUpdate(virLogSourcePtr source) size_t i; =20 for (i =3D 0; i < virLogNbFilters; i++) { - if (strstr(source->name, virLogFilters[i]->match)) { + if ((virLogFilters[i]->flags & VIR_LOG_GLOB) ? + (fnmatch(virLogFilters[i]->match, source->name, 0) =3D=3D = 0) : + (strstr(source->name, virLogFilters[i]->match) !=3D NULL))= { priority =3D virLogFilters[i]->priority; flags =3D virLogFilters[i]->flags; break; @@ -1409,7 +1412,7 @@ virLogFilterNew(const char *match, virLogFilterPtr ret =3D NULL; char *mdup =3D NULL; =20 - virCheckFlags(VIR_LOG_STACK_TRACE, NULL); + virCheckFlags(VIR_LOG_STACK_TRACE | VIR_LOG_GLOB, NULL); =20 if (priority < VIR_LOG_DEBUG || priority > VIR_LOG_ERROR) { virReportError(VIR_ERR_INVALID_ARG, _("Invalid log priority %d"), @@ -1718,6 +1721,16 @@ virLogParseFilter(const char *src) goto cleanup; } =20 + /* Only turn on fnmatch usage if we see special glob + * characters, so we use more efficient strstr() + * by default + */ + if (strchr(match, '*') || + strchr(match, '?') || + strchr(match, '[')) { + flags |=3D VIR_LOG_GLOB; + } + if (!(ret =3D virLogFilterNew(match, prio, flags))) goto cleanup; =20 diff --git a/src/util/virlog.h b/src/util/virlog.h index 35dba16cfe..95c405bac0 100644 --- a/src/util/virlog.h +++ b/src/util/virlog.h @@ -174,6 +174,7 @@ typedef void (*virLogCloseFunc) (void *data); =20 typedef enum { VIR_LOG_STACK_TRACE =3D (1 << 0), + VIR_LOG_GLOB =3D (1 << 1), } virLogFilterFlags; =20 int virLogGetNbFilters(void); --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list