virsh: cmdStart: Rewrite ternary operator use to standard if conditions

Rewrite the invocation of the virDomainCreate(WithFiles/Flags) APIs
based on the arguments into if-else instead of (nested) ternary
operators.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-02-28 14:50:19 +01:00
parent 1cd95f858a
commit 38b600166f

View File

@ -4104,10 +4104,15 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
/* We can emulate force boot, even for older servers that reject it. */ /* We can emulate force boot, even for older servers that reject it. */
if (flags & VIR_DOMAIN_START_FORCE_BOOT) { if (flags & VIR_DOMAIN_START_FORCE_BOOT) {
if ((nfds ? if (nfds > 0) {
virDomainCreateWithFiles(dom, nfds, fds, flags) : rc = virDomainCreateWithFiles(dom, nfds, fds, flags);
virDomainCreateWithFlags(dom, flags)) == 0) } else {
rc = virDomainCreateWithFlags(dom, flags);
}
if (rc == 0)
goto started; goto started;
if (last_error->code != VIR_ERR_NO_SUPPORT && if (last_error->code != VIR_ERR_NO_SUPPORT &&
last_error->code != VIR_ERR_INVALID_ARG) { last_error->code != VIR_ERR_INVALID_ARG) {
vshReportError(ctl); vshReportError(ctl);
@ -4128,9 +4133,15 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
} }
/* Prefer older API unless we have to pass a flag. */ /* Prefer older API unless we have to pass a flag. */
if ((nfds ? virDomainCreateWithFiles(dom, nfds, fds, flags) : if (nfds > 0) {
(flags ? virDomainCreateWithFlags(dom, flags) rc = virDomainCreateWithFiles(dom, nfds, fds, flags);
: virDomainCreate(dom))) < 0) { } else if (flags != 0) {
rc = virDomainCreateWithFlags(dom, flags);
} else {
rc = virDomainCreate(dom);
}
if (rc < 0) {
vshError(ctl, _("Failed to start domain '%s'"), virDomainGetName(dom)); vshError(ctl, _("Failed to start domain '%s'"), virDomainGetName(dom));
return false; return false;
} }