This patch changes the way functions return bool value from pattern: if (functionCall() < 0) return false; return true; into a more readable and modern way of direct return: return functionCall() == 0; I know that not everybody will agree this is more readable so I am open to discussion and I leave merging this patch up to the reviewer. Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx> --- tools/virsh-domain.c | 114 ++++++++++--------------------------------- 1 file changed, 26 insertions(+), 88 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 3232463485..ec427443c4 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -765,7 +765,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) return false; } - vshPrintExtra(ctl, "%s", _("Disk attached successfully\n")); return true; } @@ -1432,7 +1431,6 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) goto save_error; } - if (nparams == 0) { if (virDomainGetBlockIoTune(dom, NULL, NULL, &nparams, flags) != 0) { vshError(ctl, "%s", @@ -2673,10 +2671,7 @@ virshBlockJobSetSpeed(vshControl *ctl, if (vshBlockJobOptionBandwidth(ctl, cmd, bytes, &bandwidth) < 0) return false; - if (virDomainBlockJobSetSpeed(dom, path, bandwidth, flags) < 0) - return false; - - return true; + return virDomainBlockJobSetSpeed(dom, path, bandwidth, flags) == 0; } @@ -2693,10 +2688,7 @@ virshBlockJobAbort(virDomainPtr dom, if (pivot) flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT; - if (virDomainBlockJobAbort(dom, path, flags) < 0) - return false; - - return true; + return virDomainBlockJobAbort(dom, path, flags) == 0; } @@ -3010,10 +3002,8 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom, vshPrintExtra(ctl, " (Ctrl + %c)", priv->escapeChar[1]); vshPrintExtra(ctl, "\n"); fflush(stdout); - if (virshRunConsole(ctl, dom, name, flags) == 0) - return true; - return false; + return virshRunConsole(ctl, dom, name, flags) == 0; } static bool @@ -7079,15 +7069,10 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) return false; /* use old API without any explicit flags */ - if (flags == VIR_DOMAIN_AFFECT_CURRENT && !current) { - if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0) - return false; - } else { - if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != 0) - return false; - } + if (flags == VIR_DOMAIN_AFFECT_CURRENT && !current) + return virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) == 0; - return true; + return virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) == 0; } /* @@ -7184,10 +7169,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) if (flags == -1) flags = VIR_DOMAIN_AFFECT_LIVE; - if (virDomainPinEmulator(dom, cpumap, cpumaplen, flags) != 0) - return false; - - return true; + return virDomainPinEmulator(dom, cpumap, cpumaplen, flags) == 0; } /* @@ -7270,15 +7252,10 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) } /* none of the options were specified */ - if (!current && flags == 0) { - if (virDomainSetVcpus(dom, count) != 0) - return false; - } else { - if (virDomainSetVcpusFlags(dom, count, flags) < 0) - return false; - } + if (!current && flags == 0) + return virDomainSetVcpus(dom, count) == 0; - return true; + return virDomainSetVcpusFlags(dom, count, flags) == 0; } @@ -7439,10 +7416,7 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) if (enable) state = 1; - if (virDomainSetVcpu(dom, vcpulist, state, flags) < 0) - return false; - - return true; + return virDomainSetVcpu(dom, vcpulist, state, flags) == 0; } @@ -7493,10 +7467,7 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; - if (virDomainSetBlockThreshold(dom, dev, threshold, 0) < 0) - return false; - - return true; + return virDomainSetBlockThreshold(dom, dev, threshold, 0) == 0; } @@ -7656,11 +7627,8 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) return false; - if (virDomainPinIOThread(dom, iothread_id, - cpumap, cpumaplen, flags) != 0) - return false; - - return true; + return virDomainPinIOThread(dom, iothread_id, cpumap, + cpumaplen, flags) == 0; } /* @@ -7717,10 +7685,7 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) return false; } - if (virDomainAddIOThread(dom, iothread_id, flags) < 0) - return false; - - return true; + return virDomainAddIOThread(dom, iothread_id, flags) == 0; } @@ -7877,15 +7842,13 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) return false; + if (iothread_id <= 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); return false; } - if (virDomainDelIOThread(dom, iothread_id, flags) < 0) - return false; - - return true; + return virDomainDelIOThread(dom, iothread_id, flags) == 0; } /* @@ -8593,10 +8556,7 @@ cmdInjectNMI(vshControl *ctl, const vshCmd *cmd) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; - if (virDomainInjectNMI(dom, 0) < 0) - return false; - - return true; + return virDomainInjectNMI(dom, 0) == 0; } /* @@ -8693,10 +8653,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) count++; } - if (virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) < 0) - return false; - - return true; + return virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) == 0; } /* @@ -8788,10 +8745,7 @@ cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd) return false; } - if (virDomainSendProcessSignal(dom, pid_value, signum, 0) < 0) - return false; - - return true; + return virDomainSendProcessSignal(dom, pid_value, signum, 0) == 0; } /* @@ -8862,10 +8816,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) return false; kibibytes = VIR_DIV_UP(bytes, 1024); - if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) - return false; - - return true; + return virDomainSetMemoryFlags(dom, kibibytes, flags) == 0; } /* @@ -11118,10 +11069,7 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "postcopy")) flags |= VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY; - if (virDomainMigrateSetMaxSpeed(dom, bandwidth, flags) < 0) - return false; - - return true; + return virDomainMigrateSetMaxSpeed(dom, bandwidth, flags) == 0; } /* @@ -11194,10 +11142,7 @@ cmdMigratePostCopy(vshControl *ctl, const vshCmd *cmd) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; - if (virDomainMigrateStartPostCopy(dom, 0) < 0) - return false; - - return true; + return virDomainMigrateStartPostCopy(dom, 0) == 0; } /* @@ -13801,10 +13746,7 @@ cmdGuestAgentTimeout(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptInt(ctl, cmd, "timeout", &timeout) < 0) return false; - if (virDomainAgentSetResponseTimeout(dom, timeout, flags) < 0) - return false; - - return true; + return virDomainAgentSetResponseTimeout(dom, timeout, flags) == 0; } /* @@ -14032,12 +13974,8 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) } } - if (virDomainAuthorizedSSHKeysSet(dom, user, - (const char **) keys, nkeys, flags) < 0) { - return false; - } - - return true; + return virDomainAuthorizedSSHKeysSet(dom, user, (const char **) keys, + nkeys, flags) == 0; } -- 2.31.1