From nobody Tue Jan 18 21:13:38 2022 X-Original-To: dev-commits-src-all@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 5BEE619648AD; Tue, 18 Jan 2022 21:13:38 +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 4JdhMk25TRz3pRT; Tue, 18 Jan 2022 21:13:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642540418; 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=dGT3mRl+qws8HVgIXRHnNKuyNNfCxJFDh0jV43x/MkY=; b=YUnkH7hrI43ZwOwynFvQika3UraZEbBNFNl7tVPkLAjp1Ax3/tFv9lNOYaDFLffEg+xZ2O xrH0W6sOVagQng7ZLgFzUGcu0RXgLZSFj9KkQuPqx94QI+mbZ5mtrs9R0tJpEleR/Ii+Sl SSgMHiQ3/Cibp8460NNuucZL+NalgwH1badxobmqnR+jNZLEWkBepsIkjZCz3wy9L52Q2+ kquae8RGVtdtEubvvxRuB/ZBaEgWvdIWxv62B647SCpjq7A53zc6aR6dW3YIzA8HJbsT/T EMKZQzFRCgaXhPCf6BePfHUhYWSP4zrjvs5itY8WTHL0yh7MaQqpkJPThcC98g== 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 28D4E7C2; Tue, 18 Jan 2022 21:13:38 +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 20ILDcAn035230; Tue, 18 Jan 2022 21:13:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20ILDctx035228; Tue, 18 Jan 2022 21:13:38 GMT (envelope-from git) Date: Tue, 18 Jan 2022 21:13:38 GMT Message-Id: <202201182113.20ILDctx035228@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Joerg Wunsch Subject: git: a423411a1cad - stable/13 - usbconfig: use getopt(3) for option handling List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: joerg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a423411a1cad45531cf1ad86128bd4790e991f67 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642540418; 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=dGT3mRl+qws8HVgIXRHnNKuyNNfCxJFDh0jV43x/MkY=; b=csHdRzD1c+/WyV+WfRHGL4LmrQmRpOR4omirGX+q0qEuuHoNiD7ph3LkEO3X/fJALExoLF 5xkbpAN4/sQDnlJZm2RNU2ojWBcQuUaxZ4DK0FaEzrQ8gxhjHchfzfqaIs/8xRsuj5Ftk7 dbZ/v+ah4dUcQplEo0rTH8ZaS4o0pmsiXwlb0O919NWtKRw586KDa3F5bQQQTa+EzWcUe4 rSR5G02IW0dfXBLtf2M1huWYxf5Q0SeysF8vVD8sd0uQdD1bjIrsA5QclH2S0JUpDpgsqd MLTOZ6TGlxkyKhYW/lXn6pOOOLKg2bozOXz9CaI60Y7zxk+EN731NREdCfNOjw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642540418; a=rsa-sha256; cv=none; b=rLSLSlzH3Zi1DnR1HqZjMVdcB8EQu3M3kvaunf49/un59tVm4f0+ot5dmkVx31BxD1XyA6 R2fnDYovNuKslLSgczsqqtbNhxgm85Jp6y9SAJ8jGrfksuZ6BbBIWGRw1z6XGL07u+wnKF siH86wWPcUkTSLTMIMNBWWTztOJ8v/vCrtoAXbjKrHdvFMOGfZjSgJxQU9sEIZHqmiF2q/ Ne33HlofFWr1Y/novZGQY7a/YPrYJi1xuI7rzIRucuXM13gBJG/040/yuhuwQOxeprEXff a2hueAiCPXcQnb+05AKyEoP+lVaRjiLgPUeEQ2LCSTNuJojLPW8NpvKBRPQRxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by joerg: URL: https://cgit.FreeBSD.org/src/commit/?id=a423411a1cad45531cf1ad86128bd4790e991f67 commit a423411a1cad45531cf1ad86128bd4790e991f67 Author: Joerg Wunsch AuthorDate: 2021-12-19 22:49:23 +0000 Commit: Joerg Wunsch CommitDate: 2022-01-18 21:12:00 +0000 usbconfig: use getopt(3) for option handling This makes option handling consistent with other utilities as well as Posix rules. By that, it's no longer important whether option name and its argument are separated by a space or not, so -d5.3 works the same as -d 5.3. Also, recognize either /dev/ugen or ugen as prefix to the -d argument. Note that this removes the undocumented feature that allowed to specify multiple -d n.m options interleaved with commands referring to that particular device in a single run. (cherry picked from commit ae450e6de96b5ec65f425a52b08dc859576ab8d0) --- usr.sbin/usbconfig/usbconfig.8 | 4 +- usr.sbin/usbconfig/usbconfig.c | 104 +++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 56 deletions(-) diff --git a/usr.sbin/usbconfig/usbconfig.8 b/usr.sbin/usbconfig/usbconfig.8 index 79f070b169c6..ecfd0246eaac 100644 --- a/usr.sbin/usbconfig/usbconfig.8 +++ b/usr.sbin/usbconfig/usbconfig.8 @@ -51,7 +51,9 @@ Limit device range to the given USB device index. Should only be used in conjunction with the unit argument. .It Fl d Ar [ugen]. 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". +The unit and address coordinates may be prefixed by the lowercased word "ugen", +or the full path name +.Pa /dev/ugen . .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. diff --git a/usr.sbin/usbconfig/usbconfig.c b/usr.sbin/usbconfig/usbconfig.c index c25468fe6da4..a19ff8039186 100644 --- a/usr.sbin/usbconfig/usbconfig.c +++ b/usr.sbin/usbconfig/usbconfig.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -100,10 +101,6 @@ struct token { }; enum { - T_UNIT, - T_ADDR, - T_UGEN, - T_IFACE, T_SET_CONFIG, T_SET_ALT, T_SET_TEMPLATE, @@ -136,10 +133,6 @@ enum { static struct options options; static const struct token token[] = { - {"-u", T_UNIT, 1}, - {"-a", T_ADDR, 1}, - {"-d", T_UGEN, 1}, - {"-i", T_IFACE, 1}, {"set_config", T_SET_CONFIG, 1}, {"set_alt", T_SET_ALT, 1}, {"set_template", T_SET_TEMPLATE, 1}, @@ -563,6 +556,7 @@ main(int argc, char **argv) int addr; int n; int t; + int ch; if (argc < 1) { usage(); @@ -571,7 +565,53 @@ main(int argc, char **argv) if (pbe == NULL) err(1, "could not access USB backend\n"); - for (n = 1; n != argc; n++) { + while ((ch = getopt(argc, argv, "a:d:i:u:")) != -1) { + switch (ch) { + case 'a': + opt->addr = num_id(optarg, "addr"); + opt->got_addr = 1; + break; + + case 'd': + if (strncmp(optarg, "ugen", strlen("ugen")) == 0) { + ptr = optarg + strlen("ugen"); + } else if (strncmp(optarg, "/dev/ugen", + strlen("/dev/ugen")) == 0) { + ptr = optarg + strlen("/dev/ugen"); + } else { + ptr = optarg; + } + if ((sscanf(ptr, "%d.%d", + &unit, &addr) != 2) || + (unit < 0) || (unit > 65535) || + (addr < 0) || (addr > 65535)) { + errx(1, "cannot " + "parse '%s'", optarg); + } + opt->bus = unit; + opt->addr = addr; + opt->got_bus = 1; + opt->got_addr = 1; + break; + + case 'i': + opt->iface = num_id(optarg, "iface"); + opt->got_iface = 1; + break; + + case 'u': + opt->bus = num_id(optarg, "busnum"); + opt->got_bus = 1; + break; + + default: + usage(); + } + } + argc -= optind; + argv += optind; + + for (n = 0; n != argc; n++) { /* get number of additional options */ t = (argc - n - 1); @@ -654,52 +694,6 @@ main(int argc, char **argv) opt->got_show_iface_driver = 1; break; - case T_UGEN: - if (opt->got_any) { - /* allow multiple commands on the same line */ - flush_command(pbe, opt); - } - ptr = argv[n + 1]; - - if ((ptr[0] == 'u') && - (ptr[1] == 'g') && - (ptr[2] == 'e') && - (ptr[3] == 'n')) - ptr += 4; - - if ((sscanf(ptr, "%d.%d", - &unit, &addr) != 2) || - (unit < 0) || (unit > 65535) || - (addr < 0) || (addr > 65535)) { - errx(1, "cannot " - "parse '%s'", argv[n + 1]); - } - opt->bus = unit; - opt->addr = addr; - opt->got_bus = 1; - opt->got_addr = 1; - n++; - break; - - case T_UNIT: - if (opt->got_any) { - /* allow multiple commands on the same line */ - flush_command(pbe, opt); - } - opt->bus = num_id(argv[n + 1], "busnum"); - opt->got_bus = 1; - n++; - break; - case T_ADDR: - opt->addr = num_id(argv[n + 1], "addr"); - opt->got_addr = 1; - n++; - break; - case T_IFACE: - opt->iface = num_id(argv[n + 1], "iface"); - opt->got_iface = 1; - n++; - break; case T_SET_CONFIG: if (opt->got_set_config) duplicate_option(argv[n]);