mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
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.
This commit is contained in:
parent
36428fa80b
commit
8941c800ec
@ -8942,21 +8942,18 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
|
|||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
const vshCmdOpt *opt = NULL;
|
const vshCmdOpt *opt = NULL;
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
bool pad = false;
|
|
||||||
virJSONValuePtr pretty = NULL;
|
virJSONValuePtr pretty = NULL;
|
||||||
|
|
||||||
VSH_EXCLUSIVE_OPTIONS("hmp", "pretty");
|
VSH_EXCLUSIVE_OPTIONS("hmp", "pretty");
|
||||||
|
|
||||||
dom = virshCommandOptDomain(ctl, cmd, NULL);
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
if (dom == NULL)
|
return false;
|
||||||
goto cleanup;
|
|
||||||
|
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)) {
|
if (virBufferError(&buf)) {
|
||||||
vshPrint(ctl, "%s", _("Failed to collect command"));
|
vshPrint(ctl, "%s", _("Failed to collect command"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -8987,8 +8984,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
|
|||||||
VIR_FREE(result);
|
VIR_FREE(result);
|
||||||
VIR_FREE(monitor_cmd);
|
VIR_FREE(monitor_cmd);
|
||||||
virJSONValueFree(pretty);
|
virJSONValueFree(pretty);
|
||||||
if (dom)
|
virDomainFree(dom);
|
||||||
virDomainFree(dom);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user