From nobody Mon Feb 9 10:57:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1637845171; cv=none; d=zohomail.com; s=zohoarc; b=mOuz6IYA/ByFMKr12aoEWxNylubZvuoTSwxq82awzp3EtryrIU+ewfWyWDVWaj8TYMZs0MXhkoXRvJYrJ7aL/SPB/cY7zBZb4I7CLLAn8n+XNaF3k+u1875dOwF3EOn3XE7elYUv83ehcKF/r6hDI7iXcKIumb3BQ5UBpj/n114= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637845171; 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; bh=BvmsshhNFYuSt5jKJErG4SEKFw6cVYNFRKk7Nkdbfds=; b=KevXdhi/ow0LAoCing+A4rWYpfDxBOX+pjdDOA9VyxEc9PBsXG3DA+KpLHvqrNjvI66jiwc8Bhk1d15XiiS4iYKCqywcT2bqgrEY9juiaMgi0+9i0xQENMrEYJnG7FDhFimRMHW1fMCPAPFVBhHvzhLGrJ4WLwc3FU+UWs3Ls0Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1637845171255107.91548524447649; Thu, 25 Nov 2021 04:59:31 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-150-6i3Pt2iPPRqx_2LrlIwlUw-1; Thu, 25 Nov 2021 07:59:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0A89E2F21; Thu, 25 Nov 2021 12:59:22 +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 C07D560C4A; Thu, 25 Nov 2021 12:59:21 +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 76B151809CB7; Thu, 25 Nov 2021 12:59:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1APCxFwj030990 for ; Thu, 25 Nov 2021 07:59:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id AB0EF5D740; Thu, 25 Nov 2021 12:59:15 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06FA75F4EF for ; Thu, 25 Nov 2021 12:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637845170; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=BvmsshhNFYuSt5jKJErG4SEKFw6cVYNFRKk7Nkdbfds=; b=c8TTxKhALDRaKnXaKkDmVqbAZPtV/u3LkK3l0Rbb2ZNhX29ye4Hos54j1CP1F4bmUTwYFh dJwTTcdjrKcI5QE2IEXR0svaXBsco2mp0L2/717yUH/RJjdGe9dM0LYbUbRg9HsPtcImGy akJMg84I4VpgySZC4HKUEmX4iL+4pyY= X-MC-Unique: 6i3Pt2iPPRqx_2LrlIwlUw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/6] conf: seclabel: Parse booleans using virXMLPropTristateBool instead of virStringParseYesNo Date: Thu, 25 Nov 2021 13:59:07 +0100 Message-Id: <42b87672fdc30b6d46209b5705561d6ede7b33c5.1637845012.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637845172030100001 Content-Type: text/plain; charset="utf-8" Reduce the extent of custom logcic and custom error messages by using virXMLPropTristateBool. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f88405ab02..0203d17e9d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7801,7 +7801,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, unsigned int flags) { g_autofree char *model =3D NULL; - g_autofree char *relabel =3D NULL; + virTristateBool relabel =3D VIR_TRISTATE_BOOL_ABSENT; g_autoptr(virSecurityLabelDef) seclabel =3D NULL; if ((model =3D virXMLPropString(ctxt->node, "model")) && @@ -7824,13 +7824,10 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, seclabel->type =3D=3D VIR_DOMAIN_SECLABEL_NONE) seclabel->relabel =3D false; - if ((relabel =3D virXMLPropString(ctxt->node, "relabel"))) { - if (virStringParseYesNo(relabel, &seclabel->relabel) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid security relabel value '%s'"), relab= el); - return NULL; - } - } + if (virXMLPropTristateBool(ctxt->node, "relabel", VIR_XML_PROP_NONZERO= , &relabel) < 0) + return NULL; + + virTristateBoolToBool(relabel, &seclabel->relabel); if (seclabel->type =3D=3D VIR_DOMAIN_SECLABEL_DYNAMIC && !seclabel->relabel) { @@ -8029,9 +8026,8 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLa= belDef ***seclabels_rtn, for (i =3D 0; i < n; i++) { g_autofree char *model =3D NULL; - g_autofree char *relabel =3D NULL; g_autofree char *label =3D NULL; - g_autofree char *labelskip =3D NULL; + virTristateBool t; /* get model associated to this override */ model =3D virXMLPropString(list[i], "model"); @@ -8047,23 +8043,20 @@ virSecurityDeviceLabelDefParseXML(virSecurityDevice= LabelDef ***seclabels_rtn, seclabels[i]->model =3D g_steal_pointer(&model); } - relabel =3D virXMLPropString(list[i], "relabel"); - if (relabel !=3D NULL) { - if (virStringParseYesNo(relabel, &seclabels[i]->relabel) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid security relabel value %s"), - relabel); - goto error; - } - } else { - seclabels[i]->relabel =3D true; - } + if (virXMLPropTristateBool(list[i], "relabel", VIR_XML_PROP_NONZER= O, &t) < 0) + goto error; + + seclabels[i]->relabel =3D true; + virTristateBoolToBool(t, &seclabels[i]->relabel); /* labelskip is only parsed on live images */ - labelskip =3D virXMLPropString(list[i], "labelskip"); seclabels[i]->labelskip =3D false; - if (labelskip && !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) - ignore_value(virStringParseYesNo(labelskip, &seclabels[i]->lab= elskip)); + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) { + if (virXMLPropTristateBool(list[i], "labelskip", VIR_XML_PROP_= NONZERO, &t) < 0) + goto error; + + virTristateBoolToBool(t, &seclabels[i]->labelskip); + } ctxt->node =3D list[i]; label =3D virXPathString("string(./label)", ctxt); --=20 2.31.1