From: Peter Krempa Date: Mon, 1 Aug 2016 04:24:35 +0000 (+0200) Subject: virsh: qemu-monitor-command: Simplify control flow X-Git-Tag: v2.2.0-rc1~210 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8941c800ec683877dd5e33dfd8f7f1c81798e2f6;p=thirdparty%2Flibvirt.git virsh: qemu-monitor-command: Simplify control flow Construct the query string by using virBufferTrim rather than having to remember to add a space and simplify cleanup path. --- diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 6c1bc2f309..9c496b90dd 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8942,21 +8942,18 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; const vshCmdOpt *opt = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; - bool pad = false; virJSONValuePtr pretty = NULL; VSH_EXCLUSIVE_OPTIONS("hmp", "pretty"); - dom = virshCommandOptDomain(ctl, cmd, NULL); - if (dom == NULL) - goto cleanup; + if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + while ((opt = vshCommandOptArgv(ctl, cmd, opt))) + virBufferAsprintf(&buf, "%s ", opt->data); + + virBufferTrim(&buf, " ", -1); - while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { - if (pad) - virBufferAddChar(&buf, ' '); - pad = true; - virBufferAdd(&buf, opt->data, -1); - } if (virBufferError(&buf)) { vshPrint(ctl, "%s", _("Failed to collect command")); goto cleanup; @@ -8987,8 +8984,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) VIR_FREE(result); VIR_FREE(monitor_cmd); virJSONValueFree(pretty); - if (dom) - virDomainFree(dom); + virDomainFree(dom); return ret; }