devmatch: introduce quiet command line option

In setups without hints whatsoever one can get a long list of
"Can't read linker hints file" error messages during boot.
Add a -q/--quiet option which would suppress the noise and leave
space for more essential information.

While here switch to a pre-defined exit code from sysexits.

MFC after:	4 weeks
Reviewed by:	imp
Differential Revision: https://reviews.freebsd.org/D41443
This commit is contained in:
Bjoern A. Zeeb 2023-08-13 21:33:48 +00:00
parent 34d55be074
commit a1df36f1b9
2 changed files with 19 additions and 4 deletions

View file

@ -23,7 +23,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd November 3, 2022
.Dd August 13, 2023
.Dt DEVMATCH 8
.Os
.Sh NAME
@ -35,6 +35,7 @@
.Op Fl d | -dump
.Op Oo Fl h | -hints Oc Ar file
.Op Oo Fl p | -nomatch Oc Ar event
.Op Fl q | -quiet
.Op Fl u | -unbound
.Op Fl v | -verbose
.Sh DESCRIPTION
@ -59,6 +60,10 @@ guessed from the current module load path.
Parse and use a standard NOMATCH event from
.Xr devd 8
for matching instead of searching the device tree.
.It Fl q Fl -quiet
Suppress some error messages and simply return a non-zero exit code.
This is helpful to avoid an endless list of warnings during bootup if
no hints are available.
.It Fl u Fl -unbound
Attempt to produce a list of those drivers with PNP info whose driver
tables with that PNP info cannot be found.

View file

@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
#include <sys/linker.h>
#include <sys/module.h>
@ -48,6 +49,7 @@ static struct option longopts[] = {
{ "dump", no_argument, NULL, 'd' },
{ "hints", required_argument, NULL, 'h' },
{ "nomatch", required_argument, NULL, 'p' },
{ "quiet", no_argument, NULL, 'q' },
{ "unbound", no_argument, NULL, 'u' },
{ "verbose", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0 }
@ -59,6 +61,7 @@ static int all_flag;
static int dump_flag;
static char *linker_hints;
static char *nomatch_str;
static int quiet_flag;
static int unbound_flag;
static int verbose_flag;
@ -114,8 +117,12 @@ read_linker_hints(void)
continue;
break;
}
if (q == NULL)
errx(1, "Can't read linker hints file.");
if (q == NULL) {
if (quiet_flag)
exit(EX_UNAVAILABLE);
else
errx(EX_UNAVAILABLE, "Can't read linker hints file.");
}
} else {
hints = read_hints(linker_hints, &len);
if (hints == NULL)
@ -565,7 +572,7 @@ main(int argc, char **argv)
{
int ch;
while ((ch = getopt_long(argc, argv, "adh:p:uv",
while ((ch = getopt_long(argc, argv, "adh:p:quv",
longopts, NULL)) != -1) {
switch (ch) {
case 'a':
@ -580,6 +587,9 @@ main(int argc, char **argv)
case 'p':
nomatch_str = optarg;
break;
case 'q':
quiet_flag++;
break;
case 'u':
unbound_flag++;
break;