Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Jan 2022 21:13:40 GMT
From:      Joerg Wunsch <joerg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 800bc81676f7 - stable/13 - usbconfig: implement a -v option
Message-ID:  <202201182113.20ILDe5V035280@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by joerg:

URL: https://cgit.FreeBSD.org/src/commit/?id=800bc81676f75d467680c03dcc1d6b1781a32dd2

commit 800bc81676f75d467680c03dcc1d6b1781a32dd2
Author:     Joerg Wunsch <joerg@FreeBSD.org>
AuthorDate: 2021-12-20 19:33:05 +0000
Commit:     Joerg Wunsch <joerg@FreeBSD.org>
CommitDate: 2022-01-18 21:12:43 +0000

    usbconfig: implement a -v option
    
    Implement a -v option to usbconfig(8), as a shortcut for the most
    frequently needed commands dump_device_desc, dump_curr_config_desc,
    and show_ifdrv.
    
    While here, implement a real -h option that has been promised by the
    man page.
    
    Use <sysexits.h> to declare the utility return codes.
    
    Reviewed by:    hselasky
    Differential Revision:  https://reviews.freebsd.org/D33586
    MFC after:      2 weeks
    
    (cherry picked from commit d69b9cc26d1c24a4cbc37478a571b1f531aa7bcc)
---
 usr.sbin/usbconfig/usbconfig.8 | 16 +++++++++++++---
 usr.sbin/usbconfig/usbconfig.c | 28 ++++++++++++++++++++--------
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/usr.sbin/usbconfig/usbconfig.8 b/usr.sbin/usbconfig/usbconfig.8
index dd6264451cf7..e34cf7cfd5d0 100644
--- a/usr.sbin/usbconfig/usbconfig.8
+++ b/usr.sbin/usbconfig/usbconfig.8
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd December 20, 2021
+.Dd December 21, 2021
 .Dt USBCONFIG 8
 .Os
 .Sh NAME
@@ -34,10 +34,12 @@
 .Op Fl u Ar unit
 .Op Fl a Ar addr
 .Op Fl i Ar interface_index
+.Op Fl v
 .Op cmds...
 .Nm
 .Fl d Ar [[/dev/]ugen]<unit>.<addr>
 .Op Fl i Ar interface_index
+.Op Fl v
 .Op cmds...
 .Sh DESCRIPTION
 The
@@ -56,11 +58,19 @@ Limit device range to USB devices connected to the given unit and address.
 The unit and address coordinates may be prefixed by the lowercased word "ugen",
 or the full path name
 .Pa /dev/ugen .
+.It Fl h
+Show help and available commands.
 .It Fl i Ar interface_index
 Specify interface index as indicated by the command description.
 If this argument is not specified a value of zero will be used for the interface index.
-.It Fl h
-Show help and available commands.
+.It Fl v
+Shortcut to activate the
+.Cm dump_device_desc ,
+.Cm dump_curr_config_desc ,
+and
+.Cm show_ifdrv
+commands
+.Pq Dq verbose mode .
 .El
 .Pp
 The following commands may be used with
diff --git a/usr.sbin/usbconfig/usbconfig.c b/usr.sbin/usbconfig/usbconfig.c
index 986aa6cd8f7b..49acbf68b33c 100644
--- a/usr.sbin/usbconfig/usbconfig.c
+++ b/usr.sbin/usbconfig/usbconfig.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <err.h>
+#include <sysexits.h>
 #include <string.h>
 #include <unistd.h>
 #include <pwd.h>
@@ -267,12 +268,12 @@ duplicate_option(const char *ptr)
 }
 
 static void
-usage(void)
+usage(int exitcode)
 {
 	fprintf(stderr, ""
 	    "usbconfig - configure the USB subsystem" "\n"
-	    "usage: usbconfig [-u <busnum>] [-a <devaddr>] [-i <ifaceindex>] [cmds...]" "\n"
-	    "usage: usbconfig -d [ugen]<busnum>.<devaddr> [-i <ifaceindex>] [cmds...]" "\n"
+	    "usage: usbconfig [-u <busnum>] [-a <devaddr>] [-i <ifaceindex>] [-v] [cmds...]" "\n"
+	    "usage: usbconfig -d [ugen]<busnum>.<devaddr> [-i <ifaceindex>] [-v] [cmds...]" "\n"
 	    "commands:" "\n"
 	    "  set_config <cfg_index>" "\n"
 	    "  set_alt <alt_index>" "\n"
@@ -558,13 +559,13 @@ main(int argc, char **argv)
 	int ch;
 
 	if (argc < 1) {
-		usage();
+		usage(EX_USAGE);
 	}
 	pbe = libusb20_be_alloc_default();
 	if (pbe == NULL)
 		err(1, "could not access USB backend\n");
 
-	while ((ch = getopt(argc, argv, "a:d:i:u:")) != -1) {
+	while ((ch = getopt(argc, argv, "a:d:hi:u:v")) != -1) {
 		switch (ch) {
 		case 'a':
 			opt->addr = num_id(optarg, "addr");
@@ -593,6 +594,10 @@ main(int argc, char **argv)
 			opt->got_addr = 1;
 			break;
 
+		case 'h':
+			usage(EX_OK);
+			break;
+
 		case 'i':
 			opt->iface = num_id(optarg, "iface");
 			break;
@@ -602,8 +607,15 @@ main(int argc, char **argv)
 			opt->got_bus = 1;
 			break;
 
+		case 'v':
+			opt->got_dump_device_desc = 1;
+			opt->got_dump_curr_config = 1;
+			opt->got_show_iface_driver = 1;
+			opt->got_any += 2; /* only the dump options count */
+			break;
+
 		default:
-			usage();
+			usage(EX_USAGE);
 		}
 	}
 	argc -= optind;
@@ -856,7 +868,7 @@ main(int argc, char **argv)
 				    &unit, &addr) != 2) ||
 				    (unit < 0) || (unit > 65535) ||
 				    (addr < 0) || (addr > 65535)) {
-					usage();
+					usage(EX_USAGE);
 					break;
 				}
 
@@ -866,7 +878,7 @@ main(int argc, char **argv)
 				opt->got_addr = 1;
 				break;
 			}
-			usage();
+			usage(EX_USAGE);
 			break;
 		}
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202201182113.20ILDe5V035280>