From nobody Thu Apr 18 17:43:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552357137303335.1165789978734; Mon, 11 Mar 2019 19:18:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07195301E11B; Tue, 12 Mar 2019 02:18:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 55F7460C4C; Tue, 12 Mar 2019 02:18:52 +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 2CADF181A136; Tue, 12 Mar 2019 02:18:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2C2IkhV011405 for ; Mon, 11 Mar 2019 22:18:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id F02BC5D71A; Tue, 12 Mar 2019 02:18:46 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4A7E5D706 for ; Tue, 12 Mar 2019 02:18:44 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Mon, 11 Mar 2019 21:18:44 -0500 Message-Id: <20190312021844.27270-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virsh: Make self-test failures noisy 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 12 Mar 2019 02:18:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In local testing, I accidentally introduced a self-test failure, and spent way too much time debugging it. Make sure the testsuite log includes some hint as to why command option validation failed. Signed-off-by: Eric Blake Reviewed-by: Erik Skultety --- tools/vsh.c | 56 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 2fd1564d15..1d30019c2c 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -331,21 +331,26 @@ vshCmddefGetInfo(const vshCmdDef * cmd, const char *n= ame) /* Check if the internal command definitions are correct */ static int -vshCmddefCheckInternals(const vshCmdDef *cmd) +vshCmddefCheckInternals(vshControl *ctl, + const vshCmdDef *cmd) { size_t i; const char *help =3D NULL; /* in order to perform the validation resolve the alias first */ if (cmd->flags & VSH_CMD_FLAG_ALIAS) { - if (!cmd->alias) + if (!cmd->alias) { + vshError(ctl, _("command '%s' has inconsistent alias"), cmd->n= ame); return -1; + } cmd =3D vshCmddefSearch(cmd->alias); } /* Each command has to provide a non-empty help string. */ - if (!(help =3D vshCmddefGetInfo(cmd, "help")) || !*help) + if (!(help =3D vshCmddefGetInfo(cmd, "help")) || !*help) { + vshError(ctl, _("command '%s' lacks help"), cmd->name); return -1; + } if (!cmd->opts) return 0; @@ -353,14 +358,19 @@ vshCmddefCheckInternals(const vshCmdDef *cmd) for (i =3D 0; cmd->opts[i].name; i++) { const vshCmdOptDef *opt =3D &cmd->opts[i]; - if (i > 63) + if (i > 63) { + vshError(ctl, _("command '%s' has too many options"), cmd->nam= e); return -1; /* too many options */ + } switch (opt->type) { case VSH_OT_STRING: case VSH_OT_BOOL: - if (opt->flags & VSH_OFLAG_REQ) - return -1; /* nor bool nor string options can't be mandato= ry */ + if (opt->flags & VSH_OFLAG_REQ) { + vshError(ctl, _("command '%s' misused VSH_OFLAG_REQ"), + cmd->name); + return -1; /* neither bool nor string options can be manda= tory */ + } break; case VSH_OT_ALIAS: { @@ -368,11 +378,17 @@ vshCmddefCheckInternals(const vshCmdDef *cmd) char *name =3D (char *)opt->help; /* cast away const */ char *p; - if (opt->flags || !opt->help) + if (opt->flags || !opt->help) { + vshError(ctl, _("command '%s' has incorrect alias option"), + cmd->name); return -1; /* alias options are tracked by the original na= me */ + } if ((p =3D strchr(name, '=3D')) && - VIR_STRNDUP(name, name, p - name) < 0) + VIR_STRNDUP(name, name, p - name) < 0) { + vshError(ctl, _("allocation failure while checking command= '%s'"), + cmd->name); return -1; + } for (j =3D i + 1; cmd->opts[j].name; j++) { if (STREQ(name, cmd->opts[j].name) && cmd->opts[j].type !=3D VSH_OT_ALIAS) @@ -381,21 +397,33 @@ vshCmddefCheckInternals(const vshCmdDef *cmd) if (name !=3D opt->help) { VIR_FREE(name); /* If alias comes with value, replacement must not be bool= */ - if (cmd->opts[j].type =3D=3D VSH_OT_BOOL) + if (cmd->opts[j].type =3D=3D VSH_OT_BOOL) { + vshError(ctl, _("command '%s' has mismatched alias typ= e"), + cmd->name); return -1; + } } - if (!cmd->opts[j].name) + if (!cmd->opts[j].name) { + vshError(ctl, _("command '%s' has missing alias option"), + cmd->name); return -1; /* alias option must map to a later option name= */ + } } break; case VSH_OT_ARGV: - if (cmd->opts[i + 1].name) + if (cmd->opts[i + 1].name) { + vshError(ctl, _("command '%s' has option after argv"), + cmd->name); return -1; /* argv option must be listed last */ + } break; case VSH_OT_DATA: - if (!(opt->flags & VSH_OFLAG_REQ)) + if (!(opt->flags & VSH_OFLAG_REQ)) { + vshError(ctl, _("command '%s' has non-required VSH_OT_DATA= "), + cmd->name); return -1; /* OT_DATA should always be required. */ + } break; case VSH_OT_INT: @@ -3405,7 +3433,7 @@ const vshCmdInfo info_selftest[] =3D { * That runs vshCmddefOptParse which validates * the per-command options structure. */ bool -cmdSelfTest(vshControl *ctl ATTRIBUTE_UNUSED, +cmdSelfTest(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) { const vshCmdGrp *grp; @@ -3413,7 +3441,7 @@ cmdSelfTest(vshControl *ctl ATTRIBUTE_UNUSED, for (grp =3D cmdGroups; grp->name; grp++) { for (def =3D grp->commands; def->name; def++) { - if (vshCmddefCheckInternals(def) < 0) + if (vshCmddefCheckInternals(ctl, def) < 0) return false; } } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list