Date: 07 May 2001 19:23:35 +0200 From: Dag-Erling Smorgrav <des@ofug.org> To: Sheldon Hearn <sheldonh@uunet.co.za> Cc: hackers@FreeBSD.ORG Subject: Re: sysctl(8) and opaque MIB entries Message-ID: <xzpae4pm5t4.fsf@flood.ping.uio.no> In-Reply-To: <xzpoft5m7at.fsf@flood.ping.uio.no> References: <98295.989251948@axl.fw.uunet.co.za> <xzpoft5m7at.fsf@flood.ping.uio.no>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Here's a patch that:
1) introduces the -x option, which makes opaque variables visible.
2) allows variables to be set without the -w option.
3) undocuments the now-superfluous -w option.
DES
--
Dag-Erling Smorgrav - des@ofug.org
[-- Attachment #2 --]
Index: sysctl.8
===================================================================
RCS file: /home/ncvs/src/sbin/sysctl/sysctl.8,v
retrieving revision 1.31
diff -u -r1.31 sysctl.8
--- sysctl.8 2001/02/01 16:32:12 1.31
+++ sysctl.8 2001/05/07 17:21:58
@@ -40,14 +40,11 @@
.Nd get or set kernel state
.Sh SYNOPSIS
.Nm
-.Op Fl bNn
-.Ar name ...
+.Op Fl bNnx
+.Ar name Ns Op = Ns Ar value
+.Ar ...
.Nm
-.Op Fl bNn
-.Fl w
-.Ar name Ns = Ns Ar value ...
-.Nm
-.Op Fl bNn
+.Op Fl bNnx
.Fl aAX
.Sh DESCRIPTION
The
@@ -69,10 +66,10 @@
flag; for the opaque values,
information about the format and the length is printed in addition the first
few bytes is dumped in hex.
-.It Fl X
+.It Fl X
Same as
.Fl A
-except the entire value of opaque variables is hexdumped.
+.Fl x .
.It Fl N
Show only variable names, not their values.
.It Fl n
@@ -87,17 +84,8 @@
Force the value of the variable(s) to be output in raw, binary
format. No names are printed and no terminating newlines are output.
This is mostly useful with a single variable.
-.It Fl w Xo
-.Ar name Ns = Ns Ar value ...
-.Xc
-Set the MIB
-.Ar name
-to the new
-.Ar value .
-If just a MIB style
-.Ar name
-is given,
-the corresponding value is retrieved.
+.It Fl x
+Display opaque variables (in hex).
.El
.Pp
The information available from
Index: sysctl.c
===================================================================
RCS file: /home/ncvs/src/sbin/sysctl/sysctl.c,v
retrieving revision 1.31
diff -u -r1.31 sysctl.c
--- sysctl.c 2001/01/14 19:08:58 1.31
+++ sysctl.c 2001/05/07 17:10:44
@@ -58,7 +58,7 @@
#include <string.h>
#include <unistd.h>
-static int Aflag, aflag, bflag, Nflag, nflag, wflag, Xflag;
+static int Aflag, aflag, bflag, Nflag, nflag, xflag;
static int oidfmt(int *, int, char *, u_int *);
static void parse(char *);
@@ -70,12 +70,10 @@
usage(void)
{
- (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
- "usage: sysctl [-bNn] variable ...",
- " sysctl [-bNn] -w variable=value ...",
- " sysctl [-bNn] -a",
- " sysctl [-bNn] -A",
- " sysctl [-bNn] -X");
+ (void)fprintf(stderr, "%s\n%s\n%s\n",
+ "usage: sysctl [-bxNn] variable[=value] ...",
+ " sysctl [-bxNn] -a",
+ " sysctl [-bxNn] -A");
exit(1);
}
@@ -86,7 +84,7 @@
setbuf(stdout,0);
setbuf(stderr,0);
- while ((ch = getopt(argc, argv, "AabNnwX")) != -1) {
+ while ((ch = getopt(argc, argv, "AabNnwxX")) != -1) {
switch (ch) {
case 'A':
Aflag = 1;
@@ -104,10 +102,14 @@
nflag = 1;
break;
case 'w':
- wflag = 1;
+ /* compatibility */
break;
+ case 'x':
+ xflag = 1;
+ break;
case 'X':
- Xflag = Aflag = 1;
+ /* backwards compatibility */
+ xflag = Aflag = 1;
break;
default:
usage();
@@ -116,7 +118,7 @@
argc -= optind;
argv += optind;
- if ((wflag && (Aflag || aflag)) || (Nflag && nflag))
+ if (Nflag && nflag)
usage();
if (Aflag || aflag)
exit (sysctl_all(0, 0));
@@ -146,17 +148,12 @@
bufp = buf;
snprintf(buf, BUFSIZ, "%s", string);
if ((cp = strchr(string, '=')) != NULL) {
- if (!wflag)
- errx(2, "must specify -w to set variables");
*strchr(buf, '=') = '\0';
*cp++ = '\0';
while (isspace(*cp))
cp++;
newval = cp;
newsize = strlen(cp);
- } else {
- if (wflag)
- usage();
}
len = name2oid(bufp, mib);
@@ -166,7 +163,7 @@
if (oidfmt(mib, len, 0, &kind))
err(1, "couldn't find format of oid '%s'", bufp);
- if (!wflag) {
+ if (newval == NULL) {
if ((kind & CTLTYPE) == CTLTYPE_NODE) {
sysctl_all(mib, len);
} else {
@@ -468,14 +465,14 @@
}
/* FALL THROUGH */
default:
- if (!Aflag)
+ if (!Aflag && !xflag)
return (1);
if (!nflag)
printf("%s: ", name);
printf("Format:%s Length:%d Dump:0x", fmt, len);
while (len--) {
printf("%02x", *p++);
- if (Xflag || p < val+16)
+ if (xflag || p < val+16)
continue;
printf("...");
break;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpae4pm5t4.fsf>
