Instead of using XPath, parse the <nvram> using the XML node and
property helpers so the code is consistent with the parsing of
<loader>.

Reviewed-by: Michal Privoznik <mpriv...@redhat.com>
Signed-off-by: Daniel P. Berrangé <berra...@redhat.com>
---
 src/conf/domain_conf.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 34fec887a3..1b423298ce 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18211,21 +18211,30 @@ virDomainDefParseBootLoaderOptions(virDomainDef *def,
                                    xmlXPathContextPtr ctxt)
 {
     xmlNodePtr loader_node = virXPathNode("./os/loader[1]", ctxt);
+    xmlNodePtr nvram_node = virXPathNode("./os/nvram[1]", ctxt);
     const bool fwAutoSelect = def->os.firmware != 
VIR_DOMAIN_OS_DEF_FIRMWARE_NONE;
+    virDomainLoaderDef *loader;
 
     if (!loader_node)
         return 0;
 
-    def->os.loader = g_new0(virDomainLoaderDef, 1);
+    def->os.loader = loader = g_new0(virDomainLoaderDef, 1);
 
     if (virDomainLoaderDefParseXML(loader_node,
                                    def->os.loader,
                                    fwAutoSelect) < 0)
         return -1;
 
-    def->os.loader->nvram = virXPathString("string(./os/nvram[1])", ctxt);
-    if (!fwAutoSelect)
-        def->os.loader->nvramTemplate = 
virXPathString("string(./os/nvram[1]/@template)", ctxt);
+    if (nvram_node) {
+        if (!(loader->nvram = virXMLNodeContentString(nvram_node)))
+            return -1;
+
+        if (STREQ(loader->nvram, ""))
+            VIR_FREE(loader->nvram);
+
+        if (!fwAutoSelect)
+            def->os.loader->nvramTemplate = virXMLPropString(nvram_node, 
"template");
+    }
 
     return 0;
 }
-- 
2.34.1

Reply via email to