Use qemuMonitorJSONGetReply and unify the two blocks with the same
condition.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_monitor_json.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
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;
--
2.38.1