From nobody Mon Feb 9 12:09:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632409714; cv=none; d=zohomail.com; s=zohoarc; b=HjyiccpPs84tOruEAn+DQyFr06PiZssU5NCAshrcBbfujVg7ST0Qq9MjQIH0hEhXB5BCCUmwSVsztqFVnyistUl9N7wX13fywAajvrwnWHhEdi4X5m5OA6iDePDh1h5MLtp74uhXN/7hJZNA86qXzl+rTUsRVzz5Ep6+8lN+exw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632409714; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dVCMt/PnBUMCamRXhJn9ob8tzp3mYH8knPS1DwkCu4E=; b=WIRp/BPhZw4TmNe4iUTyWFv0Wmwk9nHxzth9z4emoqv6AeblSGBz58s+mBhvLk3LgUc0vTUblmESpt5/EpFAXzmVqNtpyIawM6FL4qWkYoz99GbBdKOxTFuUof+ZOeXg0c9hRCzpp9b+iuza0uuq6RDGSQEGx0F//J1I1nsm0Sc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632409714673932.0983327361237; Thu, 23 Sep 2021 08:08:34 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-TH8GJsRSO_mdK13X3Z1r4Q-1; Thu, 23 Sep 2021 11:08:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B9F49127D; Thu, 23 Sep 2021 15:08:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0742C652A5; Thu, 23 Sep 2021 15:08:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6EBB74EA29; Thu, 23 Sep 2021 15:08:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18NF8Lg7030560 for ; Thu, 23 Sep 2021 11:08:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3EB53177C0; Thu, 23 Sep 2021 15:08:21 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 578425F707 for ; Thu, 23 Sep 2021 15:08:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632409713; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dVCMt/PnBUMCamRXhJn9ob8tzp3mYH8knPS1DwkCu4E=; b=NOqT5bQEfgyKC90vTqclC+PBHqLadoEK/IWxAodIBVl9d3qJrekLe91uz/1ffQPDstujYb 2UR4jqyX0L4tKcVenYV2ccNI7Rh1cMzlEyP+2kMJkW4wuYuKIYkvPHI0ZpYNrAJg3YlpJQ xPXfsSlFb3FNw0pMkVJZD8NlCb+T+/U= X-MC-Unique: TH8GJsRSO_mdK13X3Z1r4Q-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 1/5] virsh: checkpoint & domain-monitor: small refactoring Date: Thu, 23 Sep 2021 17:08:00 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632409715887100001 Content-Type: text/plain; charset="utf-8" This patch includes small refactoring such as: * early return in case of an error - helps with indentation * removal of 'else' branch after return - unnecessary * altering code to be more consistent with the rest of the file - function calls inside of parentheses, etc. * removal of unnecessary variables - mainly the ones used for return value instead of returning it directly * missing parentheses around multi-line block of code Signed-off-by: Kristina Hanicova --- tools/virsh-checkpoint.c | 19 +-- tools/virsh-domain-monitor.c | 314 ++++++++++++++++------------------- 2 files changed, 155 insertions(+), 178 deletions(-) diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index 8ad37ece69..c1a9e66a24 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -292,12 +292,12 @@ virshLookupCheckpoint(vshControl *ctl, if (vshCommandOptStringReq(ctl, cmd, arg, &chkname) < 0) return -1; =20 - if (chkname) { - *chk =3D virDomainCheckpointLookupByName(dom, chkname, 0); - } else { + if (!chkname) { vshError(ctl, _("--%s is required"), arg); return -1; } + + *chk =3D virDomainCheckpointLookupByName(dom, chkname, 0); if (!*chk) { vshReportError(ctl); return -1; @@ -931,13 +931,13 @@ cmdCheckpointParent(vshControl *ctl, =20 if (virshGetCheckpointParent(ctl, checkpoint, &parent) < 0) return false; + if (!parent) { vshError(ctl, _("checkpoint '%s' has no parent"), name); return false; } =20 vshPrint(ctl, "%s", parent); - return true; } =20 @@ -1002,16 +1002,15 @@ cmdCheckpointDelete(vshControl *ctl, if (vshCommandOptBool(cmd, "metadata")) flags |=3D VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY; =20 - if (virDomainCheckpointDelete(checkpoint, flags) =3D=3D 0) { - if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) - vshPrintExtra(ctl, _("Domain checkpoint %s children deleted\n"= ), name); - else - vshPrintExtra(ctl, _("Domain checkpoint %s deleted\n"), name); - } else { + if (virDomainCheckpointDelete(checkpoint, flags) < 0) { vshError(ctl, _("Failed to delete checkpoint %s"), name); return false; } =20 + if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) + vshPrintExtra(ctl, _("Domain checkpoint %s children deleted\n"), n= ame); + else + vshPrintExtra(ctl, _("Domain checkpoint %s deleted\n"), name); return true; } =20 diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index eb3e0ef11a..d9bc869080 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -58,6 +58,7 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr d= om, bool title, g_autoptr(xmlDoc) doc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; int type; + int errCode; =20 if (title) type =3D VIR_DOMAIN_METADATA_TITLE; @@ -66,19 +67,18 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr= dom, bool title, =20 if ((desc =3D virDomainGetMetadata(dom, type, NULL, flags))) { return desc; - } else { - int errCode =3D virGetLastErrorCode(); - - if (errCode =3D=3D VIR_ERR_NO_DOMAIN_METADATA) { - desc =3D g_strdup(""); - vshResetLibvirtError(); - return desc; - } + } + errCode =3D virGetLastErrorCode(); =20 - if (errCode !=3D VIR_ERR_NO_SUPPORT) - return desc; + if (errCode =3D=3D VIR_ERR_NO_DOMAIN_METADATA) { + desc =3D g_strdup(""); + vshResetLibvirtError(); + return desc; } =20 + if (errCode !=3D VIR_ERR_NO_SUPPORT) + return desc; + /* fall back to xml */ if (virshDomainGetXMLFromDom(ctl, dom, flags, &doc, &ctxt) < 0) return NULL; @@ -467,79 +467,72 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) =20 human =3D vshCommandOptBool(cmd, "human"); =20 - if (all) { - bool active =3D virDomainIsActive(dom) =3D=3D 1; - int rc; + if (!all) { + g_autofree char *cap =3D NULL; + g_autofree char *alloc =3D NULL; + g_autofree char *phy =3D NULL; =20 - if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0) + if (virDomainGetBlockInfo(dom, device, &info, 0) < 0) return false; =20 - ndisks =3D virXPathNodeSet("./devices/disk", ctxt, &disks); - if (ndisks < 0) + if (!cmdDomblkinfoGet(&info, &cap, &alloc, &phy, human)) return false; =20 - /* title */ - table =3D vshTableNew(_("Target"), _("Capacity"), _("Allocation"),= _("Physical"), NULL); - if (!table) - return false; + vshPrint(ctl, "%-15s %s\n", _("Capacity:"), cap); + vshPrint(ctl, "%-15s %s\n", _("Allocation:"), alloc); + vshPrint(ctl, "%-15s %s\n", _("Physical:"), phy); + return true; + } =20 - for (i =3D 0; i < ndisks; i++) { - g_autofree char *target =3D NULL; - g_autofree char *protocol =3D NULL; - g_autofree char *cap =3D NULL; - g_autofree char *alloc =3D NULL; - g_autofree char *phy =3D NULL; - - ctxt->node =3D disks[i]; - protocol =3D virXPathString("string(./source/@protocol)", ctxt= ); - target =3D virXPathString("string(./target/@dev)", ctxt); - - if (virXPathBoolean("boolean(./source)", ctxt) =3D=3D 1) { - - rc =3D virDomainGetBlockInfo(dom, target, &info, 0); - - if (rc < 0) { - /* If protocol is present that's an indication of a - * networked storage device which cannot provide stati= stics, - * so generate 0 based data and get the next disk. */ - if (protocol && !active && - virGetLastErrorCode() =3D=3D VIR_ERR_INTERNAL_ERRO= R && - virGetLastErrorDomain() =3D=3D VIR_FROM_STORAGE) { - memset(&info, 0, sizeof(info)); - vshResetLibvirtError(); - } else { - return false; - } - } - } else { - /* if we don't call virDomainGetBlockInfo() who clears 'in= fo' - * we have to do it manually */ - memset(&info, 0, sizeof(info)); - } + if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0) + return false; =20 - if (!cmdDomblkinfoGet(&info, &cap, &alloc, &phy, human)) - return false; - if (vshTableRowAppend(table, target, cap, alloc, phy, NULL) < = 0) - return false; - } + ndisks =3D virXPathNodeSet("./devices/disk", ctxt, &disks); + if (ndisks < 0) + return false; =20 - vshTablePrintToStdout(table, ctl); + /* title */ + table =3D vshTableNew(_("Target"), _("Capacity"), _("Allocation"), _("= Physical"), NULL); + if (!table) + return false; =20 - } else { + for (i =3D 0; i < ndisks; i++) { + g_autofree char *target =3D NULL; + g_autofree char *protocol =3D NULL; g_autofree char *cap =3D NULL; g_autofree char *alloc =3D NULL; g_autofree char *phy =3D NULL; =20 - if (virDomainGetBlockInfo(dom, device, &info, 0) < 0) - return false; + ctxt->node =3D disks[i]; + protocol =3D virXPathString("string(./source/@protocol)", ctxt); + target =3D virXPathString("string(./target/@dev)", ctxt); + + if (virXPathBoolean("boolean(./source)", ctxt) =3D=3D 1) { + if (virDomainGetBlockInfo(dom, target, &info, 0) < 0) { + /* If protocol is present that's an indication of a + * networked storage device which cannot provide statistic= s, + * so generate 0 based data and get the next disk. */ + if (!protocol || (virDomainIsActive(dom) !=3D 1) || + virGetLastErrorCode() !=3D VIR_ERR_INTERNAL_ERROR || + virGetLastErrorDomain() !=3D VIR_FROM_STORAGE) + return false; + + memset(&info, 0, sizeof(info)); + vshResetLibvirtError(); + } + } else { + /* if we don't call virDomainGetBlockInfo() who clears 'info' + * we have to do it manually */ + memset(&info, 0, sizeof(info)); + } =20 if (!cmdDomblkinfoGet(&info, &cap, &alloc, &phy, human)) return false; - vshPrint(ctl, "%-15s %s\n", _("Capacity:"), cap); - vshPrint(ctl, "%-15s %s\n", _("Allocation:"), alloc); - vshPrint(ctl, "%-15s %s\n", _("Physical:"), phy); + if (vshTableRowAppend(table, target, cap, alloc, phy, NULL) < 0) + return false; } =20 + vshTablePrintToStdout(table, ctl); return true; } =20 @@ -584,8 +577,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "inactive")) flags |=3D VIR_DOMAIN_XML_INACTIVE; =20 - details =3D vshCommandOptBool(cmd, "details"); - if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0) return false; =20 @@ -593,7 +584,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) if (ndisks < 0) return false; =20 - if (details) + if ((details =3D vshCommandOptBool(cmd, "details"))) table =3D vshTableNew(_("Type"), _("Device"), _("Target"), _("Sour= ce"), NULL); else table =3D vshTableNew(_("Target"), _("Source"), NULL); @@ -618,8 +609,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) } } =20 - target =3D virXPathString("string(./target/@dev)", ctxt); - if (!target) { + if (!(target =3D virXPathString("string(./target/@dev)", ctxt))) { vshError(ctl, "unable to query block list"); return false; } @@ -648,19 +638,16 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) "|./source/@path)", ctxt); } =20 - if (details) { - if (vshTableRowAppend(table, type, device, target, - NULLSTR_MINUS(source), NULL) < 0) - return false; - } else { - if (vshTableRowAppend(table, target, - NULLSTR_MINUS(source), NULL) < 0) - return false; - } + if (details && (vshTableRowAppend(table, type, device, target, + NULLSTR_MINUS(source), NULL) < 0= )) + return false; + + if (!details && (vshTableRowAppend(table, target, + NULLSTR_MINUS(source), NULL) < = 0)) + return false; } =20 vshTablePrintToStdout(table, ctl); - return true; } =20 @@ -808,16 +795,15 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) return false; } =20 - if (ninterfaces < 1) { - if (macstr[0]) + if (ninterfaces !=3D 1) { + if (ninterfaces > 1) + vshError(ctl, _("multiple matching interfaces found")); + else if (macstr[0]) vshError(ctl, _("Interface (mac: %s) not found."), macstr); else vshError(ctl, _("Interface (dev: %s) not found."), iface); =20 return false; - } else if (ninterfaces > 1) { - vshError(ctl, _("multiple matching interfaces found")); - return false; } =20 ctxt->node =3D interfaces[0]; @@ -952,8 +938,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) virDomainBlockStatsStruct stats; g_autofree virTypedParameterPtr params =3D NULL; virTypedParameterPtr par =3D NULL; - const char *field =3D NULL; - int rc, nparams =3D 0; + int nparams =3D 0; size_t i; bool human =3D vshCommandOptBool(cmd, "human"); /* human readable outp= ut */ =20 @@ -970,13 +955,11 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) if (!device) device =3D ""; =20 - rc =3D virDomainBlockStatsFlags(dom, device, NULL, &nparams, 0); - /* It might fail when virDomainBlockStatsFlags is not * supported on older libvirt, fallback to use virDomainBlockStats * then. */ - if (rc < 0) { + if (virDomainBlockStatsFlags(dom, device, NULL, &nparams, 0) < 0) { /* try older API if newer is not supported */ if (last_error->code !=3D VIR_ERR_NO_SUPPORT) return false; @@ -1001,57 +984,58 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) DOMBLKSTAT_LEGACY_PRINT(2, stats.wr_req); DOMBLKSTAT_LEGACY_PRINT(3, stats.wr_bytes); DOMBLKSTAT_LEGACY_PRINT(4, stats.errs); - } else { - params =3D g_new0(virTypedParameter, nparams); - if (virDomainBlockStatsFlags(dom, device, params, &nparams, 0) < 0= ) { - vshError(ctl, _("Failed to get block stats for domain '%s' dev= ice '%s'"), name, device); - return false; - } + return true; + } =20 - /* set for prettier output */ - if (human) { - vshPrint(ctl, N_("Device: %s\n"), device); - device =3D ""; - } + params =3D g_new0(virTypedParameter, nparams); + if (virDomainBlockStatsFlags(dom, device, params, &nparams, 0) < 0) { + vshError(ctl, _("Failed to get block stats for domain '%s' device = '%s'"), name, device); + return false; + } =20 - /* at first print all known values in desired order */ - for (i =3D 0; domblkstat_output[i].field !=3D NULL; i++) { - g_autofree char *value =3D NULL; + /* set for prettier output */ + if (human) { + vshPrint(ctl, N_("Device: %s\n"), device); + device =3D ""; + } =20 - if (!(par =3D virTypedParamsGet(params, nparams, - domblkstat_output[i].field))) - continue; + /* at first print all known values in desired order */ + for (i =3D 0; domblkstat_output[i].field !=3D NULL; i++) { + g_autofree char *value =3D NULL; + const char *field =3D NULL; =20 - value =3D vshGetTypedParamValue(ctl, par); + if (!(par =3D virTypedParamsGet(params, nparams, + domblkstat_output[i].field))) + continue; =20 - /* to print other not supported fields, mark the already print= ed */ - par->field[0] =3D '\0'; /* set the name to empty string */ + value =3D vshGetTypedParamValue(ctl, par); =20 - /* translate into human readable or legacy spelling */ - field =3D NULL; - if (human) - field =3D _(domblkstat_output[i].human); - else - field =3D domblkstat_output[i].legacy; + /* to print other not supported fields, mark the already printed */ + par->field[0] =3D '\0'; /* set the name to empty string */ =20 - /* use the provided spelling if no translation is available */ - if (!field) - field =3D domblkstat_output[i].field; + /* translate into human readable or legacy spelling */ + if (human) + field =3D domblkstat_output[i].human; + else + field =3D domblkstat_output[i].legacy; =20 - vshPrint(ctl, "%s %-*s %s\n", device, - human ? 31 : 0, field, value); - } + /* use the provided spelling if no translation is available */ + if (!field) + field =3D domblkstat_output[i].field; + + vshPrint(ctl, "%s %-*s %s\n", device, + human ? 31 : 0, field, value); + } =20 - /* go through the fields again, for remaining fields */ - for (i =3D 0; i < nparams; i++) { - g_autofree char *value =3D NULL; + /* go through the fields again, for remaining fields */ + for (i =3D 0; i < nparams; i++) { + g_autofree char *value =3D NULL; =20 - if (!*params[i].field) - continue; + if (!*params[i].field) + continue; =20 - value =3D vshGetTypedParamValue(ctl, params+i); - vshPrint(ctl, "%s %s %s\n", device, params[i].field, value); - } + value =3D vshGetTypedParamValue(ctl, params+i); + vshPrint(ctl, "%s %s %s\n", device, params[i].field, value); } =20 return true; @@ -1292,11 +1276,9 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) /* Security model and label information */ memset(&secmodel, 0, sizeof(secmodel)); if (virNodeGetSecurityModel(priv->conn, &secmodel) =3D=3D -1) { - if (last_error->code !=3D VIR_ERR_NO_SUPPORT) { + if (last_error->code !=3D VIR_ERR_NO_SUPPORT) return false; - } else { - vshResetLibvirtError(); - } + vshResetLibvirtError(); } else { /* Only print something if a security model is active */ if (secmodel.model[0] !=3D '\0') { @@ -1309,10 +1291,11 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) if (virDomainGetSecurityLabel(dom, seclabel) =3D=3D -1) { VIR_FREE(seclabel); return false; - } else { - if (seclabel->label[0] !=3D '\0') - vshPrint(ctl, "%-15s %s (%s)\n", _("Security label:"), - seclabel->label, seclabel->enforcing ? "enfor= cing" : "permissive"); + } + + if (seclabel->label[0] !=3D '\0') { + vshPrint(ctl, "%-15s %s (%s)\n", _("Security label:"), + seclabel->label, seclabel->enforcing ? "enforcing= " : "permissive"); } =20 VIR_FREE(seclabel); @@ -1421,7 +1404,6 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) long long seconds =3D 0; unsigned int nseconds =3D 0; unsigned int flags =3D 0; - bool doSet =3D false; int rv; =20 VSH_EXCLUSIVE_OPTIONS("time", "now"); @@ -1433,15 +1415,12 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) =20 rv =3D vshCommandOptLongLong(ctl, cmd, "time", &seconds); =20 - if (rv < 0) { - /* invalid integer format */ + /* invalid integer format */ + if (rv < 0) return false; - } else if (rv > 0) { - /* valid integer to set */ - doSet =3D true; - } =20 - if (doSet || now || rtcSync) { + /* valid integer to set */ + if (rv > 0 || now || rtcSync) { if (now && ((seconds =3D time(NULL)) =3D=3D (time_t) -1)) { vshError(ctl, _("Unable to get current time")); return false; @@ -1453,21 +1432,22 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) if (virDomainSetTime(dom, seconds, nseconds, flags) < 0) return false; =20 - } else { - if (virDomainGetTime(dom, &seconds, &nseconds, flags) < 0) - return false; + return true; + } =20 - if (pretty) { - g_autoptr(GDateTime) then =3D NULL; - g_autofree char *thenstr =3D NULL; + if (virDomainGetTime(dom, &seconds, &nseconds, flags) < 0) + return false; =20 - then =3D g_date_time_new_from_unix_utc(seconds); - thenstr =3D g_date_time_format(then, "%Y-%m-%d %H:%M:%S"); + if (pretty) { + g_autoptr(GDateTime) then =3D NULL; + g_autofree char *thenstr =3D NULL; =20 - vshPrint(ctl, _("Time: %s"), thenstr); - } else { - vshPrint(ctl, _("Time: %lld"), seconds); - } + then =3D g_date_time_new_from_unix_utc(seconds); + thenstr =3D g_date_time_format(then, "%Y-%m-%d %H:%M:%S"); + + vshPrint(ctl, _("Time: %s"), thenstr); + } else { + vshPrint(ctl, _("Time: %lld"), seconds); } =20 return true; @@ -1508,17 +1488,15 @@ virshDomainSorter(const void *a, const void *b) if (ida =3D=3D inactive && idb =3D=3D inactive) return vshStrcasecmp(virDomainGetName(*da), virDomainGetName(*db)); =20 - if (ida !=3D inactive && idb !=3D inactive) { + if (ida !=3D inactive && idb !=3D inactive && ida !=3D idb) { if (ida > idb) return 1; - else if (ida < idb) - return -1; + return -1; } =20 if (ida !=3D inactive) return -1; - else - return 1; + return 1; } =20 struct virshDomainList { @@ -1994,10 +1972,9 @@ cmdList(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%s%s", sep, id_buf); sep =3D " "; } - if (optName) { + if (optName) vshPrint(ctl, "%s%s", sep, virDomainGetName(dom)); - sep =3D " "; - } + vshPrint(ctl, "\n"); } } @@ -2372,13 +2349,14 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) ip_addr_str =3D g_strdup(""); =20 /* Don't repeat interface name */ - if (full || !j) + if (full || !j) { vshPrint(ctl, " %-10s %-17s %s\n", iface->name, NULLSTR_EMPTY(iface->hwaddr), ip_addr_str); - else + } else { vshPrint(ctl, " %-10s %-17s %s\n", "-", "-", ip_addr_str); + } } } =20 --=20 2.31.1