From nobody Tue Sep 9 03:13:17 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1749111193; cv=none; d=zohomail.com; s=zohoarc; b=UWjvF2y1XtS/kdWa/pY9ejSK2FvvEqDei4O4BlXJdKRr1WM+qnlsrHv1U9kLBR0qceWElfvqRJXz3o3s2jIvGZtN4qTcCg4nG48BANS0qU92NlRuomNX8qltNt8QPMftAfqRR39DKdI9ZXJd8I0ggMd+XYhKu8TD3QBLktw/gzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749111193; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=debTQf++9iJ8yRlmHyggxORbGG3Slh5/N/nTYmpND+A=; b=OvNATHDFPL+OTsDOrjhIfKV67XWpNWl+crBH5ELx0IO05FUJthw7aIe/IvnCFUau4cPZBIJskkz5tTD18WZkQ8I7H5BncA24gv4fJJtqXJx77oXY2EdyxTuxqDvEgRE3SeaZNYmdRgNpz7NrIazFSn8/68T2JuV7dgUlMMqZSZ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1749111193942811.2155622854247; Thu, 5 Jun 2025 01:13:13 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 025B214F8; Thu, 5 Jun 2025 04:13:12 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C3FA11452; Thu, 5 Jun 2025 04:11:07 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 45DD4E90; Thu, 5 Jun 2025 04:10:58 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id B0DE1A3E for ; Thu, 5 Jun 2025 04:10:57 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-356-lVE7cXgoOgCbZbtoBLrFuQ-1; Thu, 05 Jun 2025 04:10:56 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 355D61800773 for ; Thu, 5 Jun 2025 08:10:55 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6F99B18002A5 for ; Thu, 5 Jun 2025 08:10:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749111057; h=from:from: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; bh=LHiRSv4qusla+e+L5tFhS5qvz3XbmXkNGJYQ42wXYsA=; b=YfJVNUTZmb5gr5nrby1xhogY2ygj/h1wjOuER1QwAI6Tix/g9GAcVJpsLnn+wFtFMaUXVG a76Aj3NbSUAfWpMGS9qdnTIcn9i1HLqNBzy/xikjmctYRl0UyUcvpuKMwRVB8k3Ku0fgOb FGg08rjIaiw46/OKPwP2XSruKmYAy+E= X-MC-Unique: lVE7cXgoOgCbZbtoBLrFuQ-1 X-Mimecast-MFC-AGG-ID: lVE7cXgoOgCbZbtoBLrFuQ_1749111055 To: devel@lists.libvirt.org Subject: [PATCH 4/7] vshCommandRun: Convert to directly return the exit code Date: Thu, 5 Jun 2025 10:10:44 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: uxeoHtb50OTRmeq_iA3XU4eyG7zjawxr4bpv3fZopB0_1749111055 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TWNI6D3TIRXD4EZYYRB4PPKTEWKRZQOK X-Message-ID-Hash: TWNI6D3TIRXD4EZYYRB4PPKTEWKRZQOK X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749111196415116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Currently the handler functions in the virt shells return only a boolean signalling if the command was successful or not. In preparation for a command which will want to return another value (timeout) convert vshCommand run to actually return the requested exit code instead and document the conversion from boolean. Signed-off-by: Peter Krempa --- tools/virsh.c | 4 ++-- tools/virt-admin.c | 4 ++-- tools/vsh.c | 29 ++++++++++++++++++++--------- tools/vsh.h | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 244ca655ee..643ef6b453 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -836,7 +836,7 @@ main(int argc, char **argv) vshControl _ctl =3D { 0 }; vshControl *ctl =3D &_ctl; virshControl virshCtl =3D { 0 }; - bool ret =3D true; + int ret =3D EXIT_SUCCESS; ctl->name =3D "virsh"; /* hardcoded name of the binary */ ctl->env_prefix =3D "VIRSH"; @@ -930,5 +930,5 @@ main(int argc, char **argv) } virshDeinit(ctl); - exit(ret ? EXIT_SUCCESS : EXIT_FAILURE); + exit(ret); } diff --git a/tools/virt-admin.c b/tools/virt-admin.c index b701ed1fe4..ac8f3202b6 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1530,7 +1530,7 @@ main(int argc, char **argv) vshControl _ctl =3D { 0 }; vshControl *ctl =3D &_ctl; vshAdmControl virtAdminCtl =3D { 0 }; - bool ret =3D true; + int ret =3D EXIT_SUCCESS; ctl->name =3D "virt-admin"; /* hardcoded name of the binary */ ctl->env_prefix =3D "VIRT_ADMIN"; @@ -1612,5 +1612,5 @@ main(int argc, char **argv) } vshAdmDeinit(ctl); - exit(ret ? EXIT_SUCCESS : EXIT_FAILURE); + exit(ret); } diff --git a/tools/vsh.c b/tools/vsh.c index e892cbca22..497b7ec631 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1341,14 +1341,22 @@ vshBlockJobOptionBandwidth(vshControl *ctl, } -/* - * Executes command(s) and returns return code from last command +/** + * vshCommandRun: + * @ctl: virt shell data + * @cmd: command to execute + * + * Returns return code from last command. Return values from command handl= ers + * which return boolean are converted as: + * true -> EXIT_SUCCESS + * false -> EXIT_FAILURE */ -bool -vshCommandRun(vshControl *ctl, const vshCmd *cmd) +int +vshCommandRun(vshControl *ctl, + const vshCmd *cmd) { const vshClientHooks *hooks =3D ctl->hooks; - bool ret =3D true; + int ret =3D EXIT_SUCCESS; while (cmd) { gint64 before, after; @@ -1358,16 +1366,19 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd) if ((cmd->def->flags & VSH_CMD_FLAG_NOCONNECT) || (hooks && hooks->connHandler && hooks->connHandler(ctl))) { - ret =3D cmd->def->handler(ctl, cmd); + if (cmd->def->handler(ctl, cmd)) + ret =3D EXIT_SUCCESS; + else + ret =3D EXIT_FAILURE; } else { /* connection is not usable, return error */ - ret =3D false; + ret =3D EXIT_FAILURE; } after =3D g_get_real_time(); /* try to automatically catch disconnections */ - if (!ret && + if (ret !=3D EXIT_SUCCESS && ((last_error !=3D NULL) && (((last_error->code =3D=3D VIR_ERR_SYSTEM_ERROR) && (last_error->domain =3D=3D VIR_FROM_REMOTE)) || @@ -1376,7 +1387,7 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd) (last_error->code =3D=3D VIR_ERR_INVALID_CONN)))) disconnected++; - if (!ret) + if (ret !=3D EXIT_SUCCESS) vshReportError(ctl); if (STREQ(cmd->def->name, "quit") || diff --git a/tools/vsh.h b/tools/vsh.h index 3b75216e11..284da36e32 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -287,7 +287,7 @@ int vshBlockJobOptionBandwidth(vshControl *ctl, bool bytes, unsigned long *bandwidth); bool vshCommandOptBool(const vshCmd *cmd, const char *name); -bool vshCommandRun(vshControl *ctl, const vshCmd *cmd); +int vshCommandRun(vshControl *ctl, const vshCmd *cmd); bool vshCommandStringParse(vshControl *ctl, char *cmdstr, vshCmd **partial); --=20 2.49.0