From nobody Tue Nov 23 23:05:17 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 05A6F189C535; Tue, 23 Nov 2021 23:05:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HzKVP3Xf4z3r26; Tue, 23 Nov 2021 23:05:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 527931F34D; Tue, 23 Nov 2021 23:05:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1ANN5Hdq023707; Tue, 23 Nov 2021 23:05:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ANN5Hbf023706; Tue, 23 Nov 2021 23:05:17 GMT (envelope-from git) Date: Tue, 23 Nov 2021 23:05:17 GMT Message-Id: <202111232305.1ANN5Hbf023706@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kirk McKusick Subject: git: 0fdc76eaabb7 - stable/13 - Allow GEOM utilities to specify a -v option. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 0fdc76eaabb7d4760723dbb1c63d15d7d4f792f6 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637708717; 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; bh=4y7UlC2OZsYv2Te6b08tJFbYFnIILMEwbsslQ/nkyJQ=; b=Ozpj8aOP+8zi3kbBrfBCwtgII6B6yG3pDben0vPRjAiK3aORTOuyHWBiiBba3h+lT9J22L LlbAEeRlqL4Na7imRgWEeprLu2Alax3KiAY6TwAEonCh8Bib6yFhe2FGcAQPHGlOEm+MqF xnK3bReTL2niQvHvF9ywrxByAs/IIIpQ7/FdOWQTJ9qvUax6T2daZCorNq0K0hiXDkZets I5pa1o5A4A591ujWK+fNHA9Y5NPbLbPxgWZ1PWAUpUScvcI4VGqESiPWTFrdfb7qTAk225 mzNRIsun5q/H3907Y4SJAZgNkmU152ADZmGd8IeGxii41W1h7FdDq8FHhkNDHA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637708717; a=rsa-sha256; cv=none; b=NT2tnJnjzImryttlA16ap0PujYY+n/DoHWWOl5SILb/U1NAgJ5MwMtiA4yR6+eAT/Nybmo 4UaMSMdrkh0JyHr2wr/+RvLufFRV7/N7MKDXvK6K8btzY9AK0ImdWe7D2s043/uvi4rnlw eylo8hbfgUwuHC9/S5P2JgMAoJ0Dt35Uh05EpjQYxKijHOrFtKFZ2adBtMu4LyJWhR3V6d oIFLxAfScI+8isljPMBwE8DpPIYL61VWNCY//metoSbKtRppoJAo/lhBI77IElSJ2oSRG7 1b1CJksqL+2PKYDyOVFcek6tUBwhpEIYK75OZlFm+TbPHPKaCDKntx861+e/GA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=0fdc76eaabb7d4760723dbb1c63d15d7d4f792f6 commit 0fdc76eaabb7d4760723dbb1c63d15d7d4f792f6 Author: Kirk McKusick AuthorDate: 2021-10-29 05:49:48 +0000 Commit: Kirk McKusick CommitDate: 2021-11-23 23:04:33 +0000 Allow GEOM utilities to specify a -v option. (cherry picked from commit 68bff4a07e3fa6c30a0c0ff6cf5f0bef95dcbd72) --- sbin/geom/core/geom.c | 19 ++++++++++++------- sbin/geom/core/geom.h | 13 +++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c index 58b33a067700..2e0d8683df49 100644 --- a/sbin/geom/core/geom.c +++ b/sbin/geom/core/geom.c @@ -314,7 +314,7 @@ parse_arguments(struct g_command *cmd, struct gctl_req *req, int *argc, struct g_option *opt; char opts[64]; unsigned i; - int ch; + int ch, vcount; *opts = '\0'; if ((cmd->gc_flags & G_FLAG_VERBOSE) != 0) @@ -336,17 +336,22 @@ parse_arguments(struct g_command *cmd, struct gctl_req *req, int *argc, /* * Add specified arguments. */ + vcount = 0; while ((ch = getopt(*argc, *argv, opts)) != -1) { /* Standard (not passed to kernel) options. */ - switch (ch) { - case 'v': + if (ch == 'v' && (cmd->gc_flags & G_FLAG_VERBOSE) != 0) verbose = 1; - continue; - } /* Options passed to kernel. */ opt = find_option(cmd, ch); - if (opt == NULL) + if (opt == NULL) { + if (ch == 'v' && (cmd->gc_flags & G_FLAG_VERBOSE) != 0){ + if (++vcount < 2) + continue; + else + warnx("Option 'v' specified twice."); + } usage(); + } if (!G_OPT_ISMULTI(opt) && G_OPT_ISDONE(opt)) { warnx("Option '%c' specified twice.", opt->go_char); usage(); @@ -440,7 +445,7 @@ set_flags(struct g_command *cmd) { unsigned flags = 0; - if ((cmd->gc_flags & G_FLAG_VERBOSE) != 0 && verbose) + if ((cmd->gc_flags & G_FLAG_VERBOSE) != 0) flags |= G_FLAG_VERBOSE; return (flags); diff --git a/sbin/geom/core/geom.h b/sbin/geom/core/geom.h index 89c5828c6429..38a99032f692 100644 --- a/sbin/geom/core/geom.h +++ b/sbin/geom/core/geom.h @@ -32,6 +32,19 @@ #define _GEOM_H_ #define G_LIB_VERSION 5 +/* + * The G_FLAG_VERBOSE flag on a command specification means that the + * comand will accept a -v option and the GEOM framework will print + * out status information after the command when it is run with -v. + * Additionally a GEOM command can explicitly specify a -v option and + * handle it as it would any other option. If both a -v option and + * G_FLAG_VERBOSE are specified for a command then both types of verbose + * information will be output when that command is run with -v. + * + * When the G_FLAG_LOADKLD is specified for a command, the GEOM kernel + * module will be loaded when that command is run if it has not yet been + * loaded. This flag is typically specified for the `create' command. + */ #define G_FLAG_NONE 0x0000 #define G_FLAG_VERBOSE 0x0001 #define G_FLAG_LOADKLD 0x0002