aboutsummaryrefslogtreecommitdiff
path: root/sbin/sysctl/sysctl.c
diff options
context:
space:
mode:
authorLuigi Rizzo <luigi@FreeBSD.org>2001-12-16 02:55:41 +0000
committerLuigi Rizzo <luigi@FreeBSD.org>2001-12-16 02:55:41 +0000
commit6105f815658a08bdf488d8b4ff3a39b59b812660 (patch)
tree1989073654ca57877e1de5559db56b11c61e4e7b /sbin/sysctl/sysctl.c
parent42e82026b79968782f39b2f05c23bc2df1a7173e (diff)
downloadsrc-6105f815658a08bdf488d8b4ff3a39b59b812660.tar.gz
src-6105f815658a08bdf488d8b4ff3a39b59b812660.zip
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
Notes
Notes: svn path=/head/; revision=88006
Diffstat (limited to 'sbin/sysctl/sysctl.c')
-rw-r--r--sbin/sysctl/sysctl.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c
index 5ffb810a4b5b..eb30b6e0303b 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);