0a7476
From 9681d46b1fab8a779e66859dd8f0670c96e446bd Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <9681d46b1fab8a779e66859dd8f0670c96e446bd@dist-git>
0a7476
From: Jiri Denemark <jdenemar@redhat.com>
0a7476
Date: Thu, 4 Apr 2019 11:48:51 +0200
0a7476
Subject: [PATCH] virsh: Strip XML declaration when extracting CPU XMLs
0a7476
MIME-Version: 1.0
0a7476
Content-Type: text/plain; charset=UTF-8
0a7476
Content-Transfer-Encoding: 8bit
0a7476
0a7476
Since commit v4.3.0-336-gc84726fbdd all
0a7476
{hypervisor-,}cpu-{baseline,compare} commands use a generic
0a7476
vshExtractCPUDefXMLs helper for extracting individual CPU definitions
0a7476
from the provided input file. The helper wraps the input file in a
0a7476
<container> element so that several independent elements can be easily
0a7476
parsed from the file. This works fine except when the file starts with
0a7476
XML declaration () because the XML declaration
0a7476
cannot be put inside any element. In fact it has to be at the very
0a7476
beginning of the XML document without any preceding white space
0a7476
characters. We can just simply skip the XML declaration.
0a7476
0a7476
https://bugzilla.redhat.com/show_bug.cgi?id=1592737
0a7476
0a7476
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
0a7476
Reviewed-by: Ján Tomko <jtomko@redhat.com>
0a7476
(cherry picked from commit fcd1c865e168bdb9763b19e790c15e80aa29be66)
0a7476
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
0a7476
Message-Id: <40acb521c9fe289277a2863bbcdd9ad5a0935428.1554371326.git.jdenemar@redhat.com>
0a7476
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
0a7476
---
0a7476
 tools/virsh-host.c | 9 ++++++++-
0a7476
 1 file changed, 8 insertions(+), 1 deletion(-)
0a7476
0a7476
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
0a7476
index 16f504bafe..b7f86bdd91 100644
0a7476
--- a/tools/virsh-host.c
0a7476
+++ b/tools/virsh-host.c
0a7476
@@ -1130,13 +1130,20 @@ vshExtractCPUDefXMLs(vshControl *ctl,
0a7476
     xmlDocPtr xml = NULL;
0a7476
     xmlXPathContextPtr ctxt = NULL;
0a7476
     xmlNodePtr *nodes = NULL;
0a7476
+    char *doc;
0a7476
     size_t i;
0a7476
     int n;
0a7476
 
0a7476
     if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &buffer) < 0)
0a7476
         goto error;
0a7476
 
0a7476
-    if (virAsprintf(&xmlStr, "<container>%s</container>", buffer) < 0)
0a7476
+    /* Strip possible XML declaration */
0a7476
+    if (STRPREFIX(buffer, "")))
0a7476
+        doc += 2;
0a7476
+    else
0a7476
+        doc = buffer;
0a7476
+
0a7476
+    if (virAsprintf(&xmlStr, "<container>%s</container>", doc) < 0)
0a7476
         goto error;
0a7476
 
0a7476
     if (!(xml = virXMLParseStringCtxt(xmlStr, xmlFile, &ctxt)))
0a7476
-- 
0a7476
2.21.0
0a7476