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
This commit is contained in:
Jose Luis Duran 2022-10-12 09:28:43 -04:00 committed by Ed Maste
parent 00ffd6b5e8
commit 45c11d5401
2 changed files with 3 additions and 4 deletions

View File

@ -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);

View File

@ -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);