From nobody Sat Feb 03 01:36:22 2024 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 4TRZx24p6Vz58kDh; Sat, 3 Feb 2024 01:36:22 +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 4TRZx23nSPz4QjN; Sat, 3 Feb 2024 01:36:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706924182; 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=ryb6yAtqS/Qjt5jmaEWAddbFmxySR5my4ikWGy+/ISQ=; b=gyeIh95GzGTD2vHng38abAYbwa+3bMa5VzFOSaXXGBRJQhqbPpu6akk13hr73O6sQmgKfR tNvZIWTL+WGlrihTPGQnRjvSRdZ5ZiULkX6oF9cLvmGTX316g67VuD7esuY9qwpMh9ASd9 f0uggP+koqkx4Hba0TAz5WOIMNh77qajom129jJ0ioXPfLhj6zyb5CHrH3UcVylGyLT9+/ J+iRdMXfaOvPjShnBL9BcO0QDb+hXTi8mA1SQGv8bREdeuKiLwVl/8fCBiQZmf8iBp/wTi pD8z02hkqXHFSr8Kqe9lhpLeHRc+i0uBv0hjZ540rpwDEhx9B4k/ZchYHea4iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706924182; 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=ryb6yAtqS/Qjt5jmaEWAddbFmxySR5my4ikWGy+/ISQ=; b=crOe5FEOkhEUEGfTvCOarDohjoz90uStZiEUOVI1qngrKegnJv5qAroLgIUyIiIF2u9If6 qXoTDxYSD++aKlsVLpq/L1SkYcOe5sqDeSS5ZbP+mpOVKMHGafi7i9UTOHUHEgEjkttYT/ hJ+jCi7JYWuf8qrANx7xEQ/U315/v0+aZqyHX3F09fA0M432mkaMpoAX9GJmmPmilG6HHK 9EL1K4jouiY9b+QCyozydcgVQHuW22X80SwY0xY3udOjXYLEeGUXFBBubUnNw2rRCaEopi 8ZtC6cyU3CQTf5ldC50jT8tH4IPDCi+mKSuhwXZT2cbwHVtyDrIYtntHrsX0FA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706924182; a=rsa-sha256; cv=none; b=Kpl03lf7nlmNDlzENEQDjORsgh/ZuMWAmhehudIgezD9lYHuBvtp8tl060XZgd9Bw3QGWp DyOL8wmcN20jstdEugbBhV+65r3064yR5D2j8HPaLdF5J0v1JDFmeHEo+bDyTqU9/Pe5Jx oX/xeYk/94OQjroQP4aNwgGGpVvgcCzfYnqnBZ87w45e6j4nhyudYShGcn4JQSEB96r8NY eph5uHOc8bZI7MyK4TdyGTMgE+M2e2tCLkmtI6GxmjW8AVlYx7y9gGbgGQQZPRDJKdE6d9 tYsmlzshfklgW3+YUiUc4G2IwprofS1RG0QELKL4RKiH2DU67I2MRLAMbKBN2A== 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 4TRZx22vByztwd; Sat, 3 Feb 2024 01:36:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4131aMmF010782; Sat, 3 Feb 2024 01:36:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4131aMjO010779; Sat, 3 Feb 2024 01:36:22 GMT (envelope-from git) Date: Sat, 3 Feb 2024 01:36:22 GMT Message-Id: <202402030136.4131aMjO010779@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 752a340419a7 - main - quot: Use getopt(3) and show usage() if no arguments 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: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 752a340419a7e2c1d3b624199f35435aecaf5828 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=752a340419a7e2c1d3b624199f35435aecaf5828 commit 752a340419a7e2c1d3b624199f35435aecaf5828 Author: Ricardo Branco AuthorDate: 2024-02-03 00:12:22 +0000 Commit: Warner Losh CommitDate: 2024-02-03 01:34:59 +0000 quot: Use getopt(3) and show usage() if no arguments Also update the man page and usage to be a little more accurate with the -a flag. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/983 --- usr.sbin/quot/quot.8 | 4 ++-- usr.sbin/quot/quot.c | 63 ++++++++++++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/usr.sbin/quot/quot.8 b/usr.sbin/quot/quot.8 index 0338457f6aeb..81abe28b41d5 100644 --- a/usr.sbin/quot/quot.8 +++ b/usr.sbin/quot/quot.8 @@ -35,8 +35,8 @@ .Nd display disk space occupied by each user .Sh SYNOPSIS .Nm -.Op Fl acfhknv -.Op Ar filesystem ... +.Op Fl cfhknv +.Op Fl a | Ar filesystem ... .Sh DESCRIPTION The .Nm diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c index 99aff61ae934..7ca8110bef76 100644 --- a/usr.sbin/quot/quot.c +++ b/usr.sbin/quot/quot.c @@ -526,9 +526,9 @@ static void usage(void) { #ifdef COMPAT - fprintf(stderr,"usage: quot [-nfcvha] [filesystem ...]\n"); + fprintf(stderr, "usage: quot [-cfhnv] [-a | filesystem ...]\n"); #else /* COMPAT */ - fprintf(stderr,"usage: quot [-acfhknv] [filesystem ...]\n"); + fprintf(stderr, "usage: quot [-cfhknv] [-a | filesystem ...]\n"); #endif /* COMPAT */ exit(1); } @@ -575,42 +575,47 @@ main(int argc, char *argv[]) struct statfs *mp; struct fstab *fs; int cnt; + int ch; func = douser; #ifndef COMPAT header = getbsize(&headerlen,&blocksize); #endif - while (--argc > 0 && **++argv == '-') { - while (*++*argv) { - switch (**argv) { - case 'n': - func = donames; - break; - case 'c': - func = dofsizes; - break; - case 'a': - all = 1; - break; - case 'f': - count = 1; - break; - case 'h': - estimate = 1; - break; + while ((ch = getopt(argc, argv, "acfhknv")) != -1) { + switch (ch) { + case 'a': + all = 1; + break; + case 'c': + func = dofsizes; + break; + case 'f': + count = 1; + break; + case 'h': + estimate = 1; + break; #ifndef COMPAT - case 'k': - blocksize = 1024; - break; + case 'k': + blocksize = 1024; + break; #endif /* COMPAT */ - case 'v': - unused = 1; - break; - default: - usage(); - } + case 'n': + func = donames; + break; + case 'v': + unused = 1; + break; + default: + usage(); } } + argc -= optind; + argv += optind; + + if ((argc == 0 && !all) || (all && argc)) + usage(); + if (all) { cnt = getmntinfo(&mp,MNT_NOWAIT); for (; --cnt >= 0; mp++) {