]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: domain: Convert from virXPathLong
authorPeter Krempa <pkrempa@redhat.com>
Wed, 5 Oct 2022 11:52:07 +0000 (13:52 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 2 Nov 2022 08:20:57 +0000 (09:20 +0100)
Convert the two uses of virXPathLong to proper
virXMLPropInt/virXMLPropLongLong so that virXPathLong can be removed in
an upcoming patch.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index 7984a15c46b6180e08596cdd56974a73f955e205..8be37a4040f56c06523ad0cc7aade55234d5b7e3 100644 (file)
@@ -17420,13 +17420,15 @@ virDomainDefParseIDs(virDomainDef *def,
 {
     g_autofree xmlNodePtr *nodes = NULL;
     g_autofree char *tmp = NULL;
-    long id = -1;
     int n;
 
-    if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
-        if (virXPathLong("string(./@id)", ctxt, &id) < 0)
-            id = -1;
-    def->id = (int)id;
+    def->id = -1;
+
+    if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) {
+        if (virXMLPropInt(ctxt->node, "id", 10, VIR_XML_PROP_NONNEGATIVE,
+                          &def->id, -1) < 0)
+            return -1;
+    }
 
     /* Extract domain name */
     if (!(def->name = virXPathString("string(./name[1])", ctxt))) {
@@ -18983,7 +18985,7 @@ virDomainObjParseXML(xmlXPathContextPtr ctxt,
                      virDomainXMLOption *xmlopt,
                      unsigned int flags)
 {
-    long val;
+    long long vmpid;
     xmlNodePtr config;
     xmlNodePtr oldnode;
     g_autoptr(virDomainObj) obj = NULL;
@@ -19026,12 +19028,11 @@ virDomainObjParseXML(xmlXPathContextPtr ctxt,
 
     virDomainObjSetState(obj, state, reason);
 
-    if (virXPathLong("string(./@pid)", ctxt, &val) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("invalid pid"));
+    if (virXMLPropLongLong(ctxt->node, "pid", 10, VIR_XML_PROP_REQUIRED,
+                           &vmpid, 0) < 0)
         return NULL;
-    }
-    obj->pid = (pid_t)val;
+
+    obj->pid = (pid_t) vmpid;
 
     if ((n = virXPathNodeSet("./taint", ctxt, &taintNodes)) < 0)
         return NULL;