diff options
author | luigi <luigi@FreeBSD.org> | 2001-12-16 02:55:41 +0000 |
---|---|---|
committer | luigi <luigi@FreeBSD.org> | 2001-12-16 02:55:41 +0000 |
commit | e39284a68819ffd7e22f09e6afa95bef09a2b285 (patch) | |
tree | 1989073654ca57877e1de5559db56b11c61e4e7b /sbin/sysctl/sysctl.c | |
parent | 22f5b26d81d78fe6779dfd9c8c42940e528876d4 (diff) | |
download | FreeBSD-src-e39284a68819ffd7e22f09e6afa95bef09a2b285.zip FreeBSD-src-e39284a68819ffd7e22f09e6afa95bef09a2b285.tar.gz |
Add code to export and print the description associated to sysctl
variables. Use the -d flag in sysctl(8) to see this information.
Possible extensions to sysctl:
+ report variables that do not have a description
+ given a name, report the oid it maps to.
Note to developers: have a look at your code, there are a number of
variables which do not have a description.
Note to developers: do we want this in 4.5 ? It is a very small change
and very useful for documentation purposes.
Suggested by: Orion Hodson
Diffstat (limited to 'sbin/sysctl/sysctl.c')
-rw-r--r-- | sbin/sysctl/sysctl.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 5ffb810..eb30b6e 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -58,7 +58,7 @@ static const char rcsid[] = #include <string.h> #include <unistd.h> -static int aflag, bflag, eflag, Nflag, nflag, oflag, xflag; +static int aflag, bflag, dflag, eflag, Nflag, nflag, oflag, xflag; static int oidfmt(int *, int, char *, u_int *); static void parse(char *); @@ -71,8 +71,8 @@ usage(void) { (void)fprintf(stderr, "%s\n%s\n", - "usage: sysctl [-beNnox] variable[=value] ...", - " sysctl [-beNnox] -a"); + "usage: sysctl [-bdeNnox] variable[=value] ...", + " sysctl [-bdeNnox] -a"); exit(1); } @@ -83,7 +83,7 @@ main(int argc, char **argv) setbuf(stdout,0); setbuf(stderr,0); - while ((ch = getopt(argc, argv, "AabeNnowxX")) != -1) { + while ((ch = getopt(argc, argv, "AabdeNnowxX")) != -1) { switch (ch) { case 'A': /* compatibility */ @@ -95,6 +95,9 @@ main(int argc, char **argv) case 'b': bflag = 1; break; + case 'd': + dflag = 1; + break; case 'e': eflag = 1; break; @@ -409,6 +412,15 @@ show_var(int *oid, int nlen) else sep = ": "; + if (dflag) { /* just print description */ + qoid[1] = 5; + j = sizeof(buf); + i = sysctl(qoid, nlen + 2, buf, &j, 0, 0); + if (!nflag) + printf("%s%s", name, sep); + printf("%s", buf); + return (0); + } /* find an estimate of how much we need for this var */ j = 0; i = sysctl(oid, nlen, 0, &j, 0, 0); |