From nobody Sat Apr 27 00:30:36 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 1542901607515624.6540867300014; Thu, 22 Nov 2018 07:46:47 -0800 (PST) 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 E721430832D4; Thu, 22 Nov 2018 15:46:43 +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 0F14E5C23E; Thu, 22 Nov 2018 15:46:43 +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 ABFD9181B9E4; Thu, 22 Nov 2018 15:46:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wAMFkdo6021007 for ; Thu, 22 Nov 2018 10:46:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id A2CE117ACA; Thu, 22 Nov 2018 15:46:39 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 747966128A for ; Thu, 22 Nov 2018 15:46:36 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B90E71039ED; Thu, 22 Nov 2018 16:46:34 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Thu, 22 Nov 2018 16:46:33 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virsh: Strip XML declaration when extracting CPU XMLs 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-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.44]); Thu, 22 Nov 2018 15:46:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Since commit v4.3.0-336-gc84726fbdd all {hypervisor-,}cpu-{baseline,compare} commands use a generic vshExtractCPUDefXMLs helper for extracting individual CPU definitions from the provided input file. The helper wraps the input file in a element so that several independent elements can be easily parsed from the file. This works fine except when the file starts with XML declaration () because the XML declaration cannot be put inside any element. In fact it has to be at the very beginning of the XML document without any preceding white space characters. We can just simply skip the XML declaration. https://bugzilla.redhat.com/show_bug.cgi?id=3D1595993 Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- tools/virsh-host.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 16f504bafe..b7f86bdd91 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1130,13 +1130,20 @@ vshExtractCPUDefXMLs(vshControl *ctl, xmlDocPtr xml =3D NULL; xmlXPathContextPtr ctxt =3D NULL; xmlNodePtr *nodes =3D NULL; + char *doc; size_t i; int n; =20 if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &buffer) < 0) goto error; =20 - if (virAsprintf(&xmlStr, "%s", buffer) < 0) + /* Strip possible XML declaration */ + if (STRPREFIX(buffer, ""))) + doc +=3D 2; + else + doc =3D buffer; + + if (virAsprintf(&xmlStr, "%s", doc) < 0) goto error; =20 if (!(xml =3D virXMLParseStringCtxt(xmlStr, xmlFile, &ctxt))) --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list