git: 45c11d540199 - main - blacklistd: Fix usage for blacklistd/blacklistctl

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Wed, 12 Oct 2022 14:30:37 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=45c11d5401996f51a05b92e0ef238d225989b5ca

commit 45c11d5401996f51a05b92e0ef238d225989b5ca
Author:     Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2022-10-12 13:28:43 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-10-12 14:30:12 +0000

    blacklistd: Fix usage for blacklistd/blacklistctl
    
    If getopt(3) encounters a character not found in optstring or if it
    detects a missing option argument, it returns ? (question mark).
    
    Obtained from:   https://github.com/zoulasc/blocklist
    Differential Revision:  https://reviews.freebsd.org/D36087
---
 contrib/blacklist/bin/blacklistctl.c | 3 +--
 contrib/blacklist/bin/blacklistd.c   | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/contrib/blacklist/bin/blacklistctl.c b/contrib/blacklist/bin/blacklistctl.c
index aebbf72acc5e..89b72921caf5 100644
--- a/contrib/blacklist/bin/blacklistctl.c
+++ b/contrib/blacklist/bin/blacklistctl.c
@@ -61,7 +61,7 @@ usage(int c)
 {
 	if (c == 0)
 		warnx("Missing/unknown command");
-	else
+	else if (c != '?')
 		warnx("Unknown option `%c'", (char)c);
 	fprintf(stderr, "Usage: %s dump [-abdnrw]\n", getprogname());
 	exit(EXIT_FAILURE);
@@ -123,7 +123,6 @@ main(int argc, char *argv[])
 			break;
 		default:
 			usage(o);
-			break;
 		}
 
 	db = state_open(dbname, O_RDONLY, 0);
diff --git a/contrib/blacklist/bin/blacklistd.c b/contrib/blacklist/bin/blacklistd.c
index e880eb457df0..11c73451b84e 100644
--- a/contrib/blacklist/bin/blacklistd.c
+++ b/contrib/blacklist/bin/blacklistd.c
@@ -105,7 +105,7 @@ sigdone(int n __unused)
 static __dead void
 usage(int c)
 {
-	if (c)
+	if (c != '?')
 		warnx("Unknown option `%c'", (char)c);
 	fprintf(stderr, "Usage: %s [-vdfr] [-c <config>] [-R <rulename>] "
 	    "[-P <sockpathsfile>] [-C <controlprog>] [-D <dbfile>] "
@@ -480,7 +480,7 @@ main(int argc, char *argv[])
 
 	argc -= optind;
 	if (argc)
-		usage(0);
+		usage('?');
 
 	signal(SIGHUP, sighup);
 	signal(SIGINT, sigdone);