From nobody Sun Feb 8 14:12:09 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1569604681; cv=none; d=zoho.com; s=zohoarc; b=n+rjVdbF7WMr/I2iexFzqcOmSIJzwtXvO2qQbPPKZPx4fNg0GIRPSi0PPhR+aXZ8sfl0y6qNbeZZyuEHBRLyHQ2XW4Ew9HhEaxkzxfh5xdwtIUKm+yYXe9kqUP+0YFEGd2rqL9mKO3fFgfUIefItcRJTGc/Vp3RE8OTaFo06QyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569604681; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=kwYc1zuoN2FgyRNuflcikQc0asi8B9bgFy+B7aXvoIA=; b=kMaVivQxy25XI24rOIl2kHalfIeqKV9Ey8dn5ogjsk2tdljHKRf23EtEHFCfkT/i/DI1xkn3ifFXTe8DlS0C3fEpBt2aiWxXlCxLZH+zsKxDw/wPDApCWL6sF0g/EGYjBh8UR+aY9HVshNH3rrKJmiUW76a7H5kkB69Ch94IiUs= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156960468142342.138747184753015; Fri, 27 Sep 2019 10:18:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D842C309DEE8; Fri, 27 Sep 2019 17:17:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ABE635C224; Fri, 27 Sep 2019 17:17:59 +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 6FE60180B761; Fri, 27 Sep 2019 17:17:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8RHHo26016591 for ; Fri, 27 Sep 2019 13:17:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3B9536012A; Fri, 27 Sep 2019 17:17:50 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-55.ams2.redhat.com [10.36.112.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 758E0600C6; Fri, 27 Sep 2019 17:17:49 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Sep 2019 18:17:30 +0100 Message-Id: <20190927171733.10842-9-berrange@redhat.com> In-Reply-To: <20190927171733.10842-1-berrange@redhat.com> References: <20190927171733.10842-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/11] src: convert over to use GRegex for regular exprssions 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 27 Sep 2019 17:18:00 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- src/conf/domain_event.c | 25 ++++++++----------- src/libxl/libxl_capabilities.c | 44 ++++++++++++++++------------------ 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index b33589f472..f7d1a38e46 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -22,8 +22,6 @@ =20 #include =20 -#include - #include "domain_event.h" #include "object_event.h" #include "object_event_private.h" @@ -2009,7 +2007,7 @@ virDomainQemuMonitorEventNew(int id, * deregisters. */ struct virDomainQemuMonitorEventData { char *event; - regex_t regex; + GRegex *regex; unsigned int flags; void *opaque; virFreeCallback freecb; @@ -2241,7 +2239,7 @@ virDomainQemuMonitorEventFilter(virConnectPtr conn AT= TRIBUTE_UNUSED, if (data->flags =3D=3D -1) return true; if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX) - return regexec(&data->regex, monitorEvent->event, 0, NULL, 0) =3D= =3D 0; + return g_regex_match(data->regex, monitorEvent->event, 0, NULL) = =3D=3D TRUE; if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCAS= E) return STRCASEEQ(monitorEvent->event, data->event); return STREQ(monitorEvent->event, data->event); @@ -2255,7 +2253,7 @@ virDomainQemuMonitorEventCleanup(void *opaque) =20 VIR_FREE(data->event); if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX) - regfree(&data->regex); + g_regex_unref(data->regex); if (data->freecb) (data->freecb)(data->opaque); VIR_FREE(data); @@ -2306,20 +2304,17 @@ virDomainQemuMonitorEventStateRegisterID(virConnect= Ptr conn, return -1; data->flags =3D flags; if (event && flags !=3D -1) { - int rflags =3D REG_NOSUB; - - if (flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE) - rflags |=3D REG_ICASE; if (flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX) { - int err =3D regcomp(&data->regex, event, rflags); + int cflags =3D 0; + g_autoptr(GError) err =3D NULL; =20 - if (err) { - char error[100]; - regerror(err, &data->regex, error, sizeof(error)); + if (flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOC= ASE) + cflags |=3D G_REGEX_CASELESS; + data->regex =3D g_regex_new(event, cflags, 0, &err); + if (!data->regex) { virReportError(VIR_ERR_INVALID_ARG, _("failed to compile regex '%s': %s"), - event, error); - regfree(&data->regex); + event, err->message); VIR_FREE(data); return -1; } diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index 73ae0b3fa1..90d9bac9c7 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -21,7 +21,6 @@ #include =20 #include -#include =20 #include "internal.h" #include "virlog.h" @@ -374,10 +373,10 @@ static int libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) { const libxl_version_info *ver_info; - int err; - regex_t regex; + g_autoptr(GRegex) regex =3D NULL; + g_autoptr(GError) err =3D NULL; + g_autoptr(GMatchInfo) info =3D NULL; char *str, *token; - regmatch_t subs[4]; char *saveptr =3D NULL; size_t i; =20 @@ -398,12 +397,10 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) return -1; } =20 - err =3D regcomp(®ex, XEN_CAP_REGEX, REG_EXTENDED); - if (err !=3D 0) { - char error[100]; - regerror(err, ®ex, error, sizeof(error)); + regex =3D g_regex_new(XEN_CAP_REGEX, G_REGEX_EXTENDED, 0, &err); + if (!regex) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to compile regex %s"), error); + _("Failed to compile regex %s"), err->message); return -1; } =20 @@ -436,31 +433,33 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) nr_guest_archs < sizeof(guest_archs) / sizeof(guest_archs[0]) && (token =3D strtok_r(str, " ", &saveptr)) !=3D NULL; str =3D NULL) { - if (regexec(®ex, token, sizeof(subs) / sizeof(subs[0]), - subs, 0) =3D=3D 0) { - int hvm =3D STRPREFIX(&token[subs[1].rm_so], "hvm"); + if (g_regex_match(regex, token, 0, &info)) { + g_autofree char *modestr =3D g_match_info_fetch(info, 1); + g_autofree char *archstr =3D g_match_info_fetch(info, 2); + g_autofree char *suffixstr =3D g_match_info_fetch(info, 3); + int hvm =3D STRPREFIX(modestr, "hvm"); virArch arch; int pae =3D 0, nonpae =3D 0, ia64_be =3D 0; =20 - if (STRPREFIX(&token[subs[2].rm_so], "x86_32")) { + if (STRPREFIX(archstr, "x86_32")) { arch =3D VIR_ARCH_I686; - if (subs[3].rm_so !=3D -1 && - STRPREFIX(&token[subs[3].rm_so], "p")) + if (suffixstr !=3D NULL && + STRPREFIX(suffixstr, "p")) pae =3D 1; else nonpae =3D 1; - } else if (STRPREFIX(&token[subs[2].rm_so], "x86_64")) { + } else if (STRPREFIX(archstr, "x86_64")) { arch =3D VIR_ARCH_X86_64; - } else if (STRPREFIX(&token[subs[2].rm_so], "ia64")) { + } else if (STRPREFIX(archstr, "ia64")) { arch =3D VIR_ARCH_ITANIUM; - if (subs[3].rm_so !=3D -1 && - STRPREFIX(&token[subs[3].rm_so], "be")) + if (suffixstr !=3D NULL && + STRPREFIX(suffixstr, "be")) ia64_be =3D 1; - } else if (STRPREFIX(&token[subs[2].rm_so], "powerpc64")) { + } else if (STRPREFIX(archstr, "powerpc64")) { arch =3D VIR_ARCH_PPC64; - } else if (STRPREFIX(&token[subs[2].rm_so], "armv7l")) { + } else if (STRPREFIX(archstr, "armv7l")) { arch =3D VIR_ARCH_ARMV7L; - } else if (STRPREFIX(&token[subs[2].rm_so], "aarch64")) { + } else if (STRPREFIX(archstr, "aarch64")) { arch =3D VIR_ARCH_AARCH64; } else { continue; @@ -515,7 +514,6 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps) #endif } } - regfree(®ex); =20 for (i =3D 0; i < nr_guest_archs; ++i) { virCapsGuestPtr guest; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list