Add "-q" argument to sysctl(8), which suppresses a limited set of warnings/

errors generated.  In particular, it suppresses "unknown oid" when
attempting to get or set a sysctl not present in the kernel.

MFC after:	1 week
This commit is contained in:
Robert Watson 2005-09-15 16:08:04 +00:00
parent ca17bccaa1
commit f93d36fd92
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=150167
2 changed files with 17 additions and 5 deletions

View File

@ -40,7 +40,7 @@
.Ar name Ns Op = Ns Ar value
.Ar ...
.Nm
.Op Fl bdehNnox
.Op Fl bdehNnoqx
.Fl a
.Sh DESCRIPTION
The
@ -111,6 +111,10 @@ use:
Show opaque variables (which are normally suppressed).
The format and length are printed, as well as a hex dump of the first
sixteen bytes of the value.
.It Fl q
Suppress some warnings generated by
.Nm
to standard error.
.It Fl X
Equivalent to
.Fl x a

View File

@ -60,7 +60,8 @@ static const char rcsid[] =
#include <string.h>
#include <unistd.h>
static int aflag, bflag, dflag, eflag, hflag, Nflag, nflag, oflag, xflag;
static int aflag, bflag, dflag, eflag, hflag, Nflag, nflag, oflag;
static int qflag, xflag;
static int oidfmt(int *, int, char *, u_int *);
static void parse(char *);
@ -89,7 +90,7 @@ main(int argc, char **argv)
setbuf(stdout,0);
setbuf(stderr,0);
while ((ch = getopt(argc, argv, "AabdehNnowxX")) != -1) {
while ((ch = getopt(argc, argv, "AabdehNnoqwxX")) != -1) {
switch (ch) {
case 'A':
/* compatibility */
@ -119,6 +120,9 @@ main(int argc, char **argv)
case 'o':
oflag = 1;
break;
case 'q':
qflag = 1;
break;
case 'w':
/* compatibility */
/* ignored */
@ -181,8 +185,12 @@ parse(char *string)
}
len = name2oid(bufp, mib);
if (len < 0)
errx(1, "unknown oid '%s'", bufp);
if (len < 0) {
if (qflag)
exit(1);
else
errx(1, "unknown oid '%s'", bufp);
}
if (oidfmt(mib, len, fmt, &kind))
err(1, "couldn't find format of oid '%s'", bufp);