summaryrefslogtreecommitdiffstats
path: root/sbin/sysctl
diff options
context:
space:
mode:
authorluigi <luigi@FreeBSD.org>2001-12-16 02:55:41 +0000
committerluigi <luigi@FreeBSD.org>2001-12-16 02:55:41 +0000
commite39284a68819ffd7e22f09e6afa95bef09a2b285 (patch)
tree1989073654ca57877e1de5559db56b11c61e4e7b /sbin/sysctl
parent22f5b26d81d78fe6779dfd9c8c42940e528876d4 (diff)
downloadFreeBSD-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')
-rw-r--r--sbin/sysctl/sysctl.84
-rw-r--r--sbin/sysctl/sysctl.c20
2 files changed, 19 insertions, 5 deletions
diff --git a/sbin/sysctl/sysctl.8 b/sbin/sysctl/sysctl.8
index f6c1bb9..ec2e054 100644
--- a/sbin/sysctl/sysctl.8
+++ b/sbin/sysctl/sysctl.8
@@ -44,7 +44,7 @@
.Ar name Ns Op = Ns Ar value
.Ar ...
.Nm
-.Op Fl beNnox
+.Op Fl bdeNnox
.Fl a
.Sh DESCRIPTION
The
@@ -71,6 +71,8 @@ the command line.
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 d
+Print the description of the variable instead of its value.
.It Fl e
Separate the name and the value of the variable(s) with
.Ql = .
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);
OpenPOWER on IntegriCloud