[PATCH 04/16] virLockDaemonClientPreExecRestart: Modernize JSON object construction

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

 



Use virJSONValueObjectAdd instead of step-by-step construction of the
object. This also removes a handful impossible to reach errors with
translatable messages.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/locking/lock_daemon.c | 40 ++++++++++-----------------------------
 1 file changed, 10 insertions(+), 30 deletions(-)

diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index cf33d9732b..fc714052be 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -549,41 +549,21 @@ virLockDaemonClientPreExecRestart(virNetServerClient *client G_GNUC_UNUSED,
                                   void *opaque)
 {
     virLockDaemonClient *priv = opaque;
-    virJSONValue *object = virJSONValueNewObject();
+    virJSONValue *object = NULL;
     char uuidstr[VIR_UUID_STRING_BUFLEN];

-    if (virJSONValueObjectAppendBoolean(object, "restricted", priv->restricted) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Cannot set restricted data in JSON document"));
-        goto error;
-    }
-    if (virJSONValueObjectAppendNumberUint(object, "ownerPid", priv->ownerPid) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Cannot set ownerPid data in JSON document"));
-        goto error;
-    }
-    if (virJSONValueObjectAppendNumberUint(object, "ownerId", priv->ownerId) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Cannot set ownerId data in JSON document"));
-        goto error;
-    }
-    if (virJSONValueObjectAppendString(object, "ownerName", priv->ownerName) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Cannot set ownerName data in JSON document"));
-        goto error;
-    }
     virUUIDFormat(priv->ownerUUID, uuidstr);
-    if (virJSONValueObjectAppendString(object, "ownerUUID", uuidstr) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Cannot set ownerUUID data in JSON document"));
-        goto error;
-    }

-    return object;
+    if (virJSONValueObjectAdd(&object,
+                              "b:restricted", priv->restricted,
+                              "u:ownerPid", priv->ownerPid,
+                              "u:ownerId", priv->ownerId,
+                              "s:ownerName", priv->ownerName,
+                              "s:ownerUUID", uuidstr,
+                              NULL) < 0)
+        return NULL;

- error:
-    virJSONValueFree(object);
-    return NULL;
+    return object;
 }


-- 
2.31.1




[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