]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: cmdStart: Rewrite ternary operator use to standard if conditions
authorPeter Krempa <pkrempa@redhat.com>
Mon, 28 Feb 2022 13:50:19 +0000 (14:50 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 3 Mar 2022 10:06:56 +0000 (11:06 +0100)
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>
tools/virsh-domain.c

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