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