From: Peter Krempa Date: Thu, 1 Dec 2022 15:47:29 +0000 (+0100) Subject: qemu: monitor: Unify and refactor 'PTY' case in qemuMonitorJSONAttachCharDev X-Git-Tag: v9.0.0-rc1~249 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=962ce78175f010ce3a0947a89c63422af925ec14;p=thirdparty%2Flibvirt.git qemu: monitor: Unify and refactor 'PTY' case in qemuMonitorJSONAttachCharDev Use qemuMonitorJSONGetReply and unify the two blocks with the same condition. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 47df4a5160..a5800e182c 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -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;