From nobody Sun Feb 8 20:53:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1608153217; cv=none; d=zohomail.com; s=zohoarc; b=luig5mtM1o2Ehvn1J6/XLBsG79wXMoN1ZeSi51BgSwwvaz2AJKu6CIrivWCDV8t0r6MOHB2LeunUXwVMDjdnhNl9tHZqlHdE1n8dMJ0gcU2EsgpCXZ+hT12RA7iileaunzzqstFy0/Jnjr9UloWy8Q8FuXW6ZtFQrMuVw9IGZic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608153217; 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=isfvCwdh5Sl2X6gnloTtROwpQB0rpIfCw8AIBiNbOIQ=; b=atatnWaLVyz3tRzE8kMdph3w4Mu0j0PQTcPwjND+7a9+bXCuuptEbAigJdifbI/wi/9cSV0URmeNUOqkI/62FXU7drAmwHvKmysu/8WDa9gMLmZYRn4P29Khm4munepIxlORl8qEt+ck8CZAPyep+yhifirnyHkDrb3O124Qh2Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1608153217224901.6061839807252; Wed, 16 Dec 2020 13:13:37 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-510-BAE2m0_GPDGgmbCCQiysbw-1; Wed, 16 Dec 2020 16:13:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3E875801817; Wed, 16 Dec 2020 21:13:14 +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 0AF3A27C4F; Wed, 16 Dec 2020 21:13:14 +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 C171A180954D; Wed, 16 Dec 2020 21:13:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BGLD97k005937 for ; Wed, 16 Dec 2020 16:13:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 752DE1F4; Wed, 16 Dec 2020 21:13:09 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9D141971D for ; Wed, 16 Dec 2020 21:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608153203; 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=isfvCwdh5Sl2X6gnloTtROwpQB0rpIfCw8AIBiNbOIQ=; b=Aq0xr/AFb9/cMYl/TAT2874ks2BERxTeikV7/g0nGG6HKOw/z8Bcii/P44x1XaFVnZAAji JoeUcHqgW4E3GNIfIsuaEsjFCbhgxLYwRL9SoLEBf53Mq1+d+gIXnia69g5Uz0dh7MDlJx lwHV2/6Nl4+xOOUAJCoRQ2dxRg7qwPU= X-MC-Unique: BAE2m0_GPDGgmbCCQiysbw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/4] lxc: Rework lxcDomainDefNamespaceParse() Date: Wed, 16 Dec 2020 22:13:00 +0100 Message-Id: <3c4ef431e08c0674dd90ae9dc64235f366e951a6.1608153074.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.84 on 10.5.11.23 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) Content-Type: text/plain; charset="utf-8" While fixing our schema for I've looked into the parser and realized it could use some treating. Signed-off-by: Michal Privoznik Reviewed-by: Laine Stump --- src/lxc/lxc_domain.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index 707262336b..255bfab495 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -208,26 +208,31 @@ static int lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt, void **data) { - lxcDomainDefPtr lxcDef =3D g_new0(lxcDomainDef, 1); + lxcDomainDefPtr lxcDef =3D NULL; g_autofree xmlNodePtr *nodes =3D NULL; - bool uses_lxc_ns =3D false; VIR_XPATH_NODE_AUTORESTORE(ctxt) - int feature; int n; size_t i; + int ret =3D -1; =20 if ((n =3D virXPathNodeSet("./lxc:namespace/*", ctxt, &nodes)) < 0) - goto error; - uses_lxc_ns |=3D n > 0; + return -1; + + if (n =3D=3D 0) + return 0; + + lxcDef =3D g_new0(lxcDomainDef, 1); =20 for (i =3D 0; i < n; i++) { g_autofree char *tmp =3D NULL; + int feature; + if ((feature =3D virLXCDomainNamespaceTypeFromString( (const char *)nodes[i]->name)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unsupported Namespace feature: %s"), - nodes[i]->name); - goto error; + _("unsupported Namespace feature: %s"), + nodes[i]->name); + goto cleanup; } =20 ctxt->node =3D nodes[i]; @@ -235,31 +240,30 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt, if (!(tmp =3D virXMLPropString(nodes[i], "type"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No lxc environment type specified")); - goto error; + goto cleanup; } if ((lxcDef->ns_source[feature] =3D virLXCDomainNamespaceSourceTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown LXC namespace source '%s'"), tmp); - goto error; + goto cleanup; } =20 if (!(lxcDef->ns_val[feature] =3D virXMLPropString(nodes[i], "value"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No lxc environment type specified")); - goto error; + goto cleanup; } } - if (uses_lxc_ns) - *data =3D lxcDef; - else - g_free(lxcDef); - return 0; - error: + + *data =3D g_steal_pointer(&lxcDef); + ret =3D 0; + + cleanup: lxcDomainDefNamespaceFree(lxcDef); - return -1; + return ret; } =20 =20 --=20 2.26.2