]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Unify and refactor 'PTY' case in qemuMonitorJSONAttachCharDev
authorPeter Krempa <pkrempa@redhat.com>
Thu, 1 Dec 2022 15:47:29 +0000 (16:47 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 2 Dec 2022 15:18:37 +0000 (16:18 +0100)
Use qemuMonitorJSONGetReply and unify the two blocks with the same
condition.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_monitor_json.c

index 47df4a516053b4025152641ba65ebac0809d6b63..a5800e182ce33ec4bc3549899017de39331176c1 100644 (file)
@@ -6578,24 +6578,19 @@ qemuMonitorJSONAttachCharDev(qemuMonitor *mon,
         return -1;
 
     if (chr->type == VIR_DOMAIN_CHR_TYPE_PTY) {
-        if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
-            return -1;
-    } else {
-        if (qemuMonitorJSONCheckError(cmd, reply) < 0)
-            return -1;
-    }
+        virJSONValue *data;
 
-    if (chr->type == VIR_DOMAIN_CHR_TYPE_PTY) {
-        virJSONValue *data = virJSONValueObjectGetObject(reply, "return");
-        const char *path;
+        if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
+            return -1;
 
-        if (!(path = virJSONValueObjectGetString(data, "pty"))) {
+        if (!(chr->data.file.path = g_strdup(virJSONValueObjectGetString(data, "pty")))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("chardev-add reply was missing pty path"));
             return -1;
         }
-
-        chr->data.file.path = g_strdup(path);
+    } else {
+        if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+            return -1;
     }
 
     return 0;