From 386fe237b2aa9a9284be948b390978384da3e6e0 Mon Sep 17 00:00:00 2001 From: Peter Krempa <pkrempa@redhat.com> Date: Mon, 26 Sep 2016 17:19:43 +0200 Subject: [PATCH] qemu: monitor: Simplify construction of chardev backends --- src/qemu/qemu_monitor_json.c | 39 ++++++++++++++---------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 349a64fa30..6d22c059e1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5929,22 +5929,17 @@ qemuMonitorJSONBuildInetSocketAddress(const char *host, virJSONValuePtr addr = NULL; virJSONValuePtr data = NULL; - if (!(data = virJSONValueNewObject()) || - !(addr = virJSONValueNewObject())) - goto error; + if (virJSONValueObjectCreate(&data, "s:host", host, + "s:port", port, NULL) < 0) + return NULL; - /* port is really expected as a string here by qemu */ - if (virJSONValueObjectAppendString(data, "host", host) < 0 || - virJSONValueObjectAppendString(data, "port", port) < 0 || - virJSONValueObjectAppendString(addr, "type", "inet") < 0 || - virJSONValueObjectAppend(addr, "data", data) < 0) - goto error; + if (virJSONValueObjectCreate(&addr, "s:type", "inet", + "a:data", data, NULL) < 0) { + virJSONValueFree(data); + return NULL; + } return addr; - error: - virJSONValueFree(data); - virJSONValueFree(addr); - return NULL; } static virJSONValuePtr @@ -5953,20 +5948,16 @@ qemuMonitorJSONBuildUnixSocketAddress(const char *path) virJSONValuePtr addr = NULL; virJSONValuePtr data = NULL; - if (!(data = virJSONValueNewObject()) || - !(addr = virJSONValueNewObject())) - goto error; + if (virJSONValueObjectCreate(&data, "s:path", path, NULL) < 0) + return NULL; - if (virJSONValueObjectAppendString(data, "path", path) < 0 || - virJSONValueObjectAppendString(addr, "type", "unix") < 0 || - virJSONValueObjectAppend(addr, "data", data) < 0) - goto error; + if (virJSONValueObjectCreate(&addr, "s:type", "unix", + "a:data", data, NULL) < 0) { + virJSONValueFree(data); + return NULL; + } return addr; - error: - virJSONValueFree(data); - virJSONValueFree(addr); - return NULL; } int -- GitLab