[libvirt PATCH 2/9] conf: introduce virDomainDefParseBootInitOptions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Extract the code to it's own function.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 109 +++++++++++++++++++++++------------------
 1 file changed, 61 insertions(+), 48 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 47756ff0be..31b908d8fe 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19523,12 +19523,70 @@ virDomainVcpuParse(virDomainDefPtr def,
 }
 
 
+static int
+virDomainDefParseBootInitOptions(virDomainDefPtr def,
+                                 xmlXPathContextPtr ctxt)
+{
+    char *name = NULL;
+    size_t i;
+    int n;
+    g_autofree xmlNodePtr *nodes = NULL;
+
+    def->os.init = virXPathString("string(./os/init[1])", ctxt);
+    def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
+    def->os.initdir = virXPathString("string(./os/initdir[1])", ctxt);
+    def->os.inituser = virXPathString("string(./os/inituser[1])", ctxt);
+    def->os.initgroup = virXPathString("string(./os/initgroup[1])", ctxt);
+
+    if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0)
+        return -1;
+
+    def->os.initargv = g_new0(char *, n+1);
+    for (i = 0; i < n; i++) {
+        if (!nodes[i]->children ||
+            !nodes[i]->children->content) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("No data supplied for <initarg> element"));
+            return -1;
+        }
+        def->os.initargv[i] = g_strdup((const char *)nodes[i]->children->content);
+    }
+    def->os.initargv[n] = NULL;
+    VIR_FREE(nodes);
+
+    if ((n = virXPathNodeSet("./os/initenv", ctxt, &nodes)) < 0)
+        return -1;
+
+    def->os.initenv = g_new0(virDomainOSEnvPtr, n+1);
+    for (i = 0; i < n; i++) {
+        if (!(name = virXMLPropString(nodes[i], "name"))) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("No name supplied for <initenv> element"));
+            return -1;
+        }
+
+        if (!nodes[i]->children ||
+            !nodes[i]->children->content) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("No value supplied for <initenv name='%s'> element"),
+                           name);
+            return -1;
+        }
+
+        def->os.initenv[i] = g_new0(virDomainOSEnv, 1);
+        def->os.initenv[i]->name = name;
+        def->os.initenv[i]->value = g_strdup((const char *)nodes[i]->children->content);
+    }
+    def->os.initenv[n] = NULL;
+
+    return 0;
+}
+
+
 static int
 virDomainDefParseBootOptions(virDomainDefPtr def,
                              xmlXPathContextPtr ctxt)
 {
-    char *name = NULL;
-    size_t i;
     int n;
     g_autofree xmlNodePtr *nodes = NULL;
     g_autofree char *tmp = NULL;
@@ -19543,53 +19601,8 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
      */
 
     if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) {
-        def->os.init = virXPathString("string(./os/init[1])", ctxt);
-        def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
-        def->os.initdir = virXPathString("string(./os/initdir[1])", ctxt);
-        def->os.inituser = virXPathString("string(./os/inituser[1])", ctxt);
-        def->os.initgroup = virXPathString("string(./os/initgroup[1])", ctxt);
-
-        if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0)
+        if (virDomainDefParseBootInitOptions(def, ctxt) < 0)
             return -1;
-
-        def->os.initargv = g_new0(char *, n+1);
-        for (i = 0; i < n; i++) {
-            if (!nodes[i]->children ||
-                !nodes[i]->children->content) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("No data supplied for <initarg> element"));
-                return -1;
-            }
-            def->os.initargv[i] = g_strdup((const char *)nodes[i]->children->content);
-        }
-        def->os.initargv[n] = NULL;
-        VIR_FREE(nodes);
-
-        if ((n = virXPathNodeSet("./os/initenv", ctxt, &nodes)) < 0)
-            return -1;
-
-        def->os.initenv = g_new0(virDomainOSEnvPtr, n+1);
-        for (i = 0; i < n; i++) {
-            if (!(name = virXMLPropString(nodes[i], "name"))) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                                _("No name supplied for <initenv> element"));
-                return -1;
-            }
-
-            if (!nodes[i]->children ||
-                !nodes[i]->children->content) {
-                virReportError(VIR_ERR_XML_ERROR,
-                               _("No value supplied for <initenv name='%s'> element"),
-                               name);
-                return -1;
-            }
-
-            def->os.initenv[i] = g_new0(virDomainOSEnv, 1);
-            def->os.initenv[i]->name = name;
-            def->os.initenv[i]->value = g_strdup((const char *)nodes[i]->children->content);
-        }
-        def->os.initenv[n] = NULL;
-        VIR_FREE(nodes);
     }
 
     if (def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
-- 
2.30.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux