summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_sysctl.c
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 /sys/kern/kern_sysctl.c
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 'sys/kern/kern_sysctl.c')
-rw-r--r--sys/kern/kern_sysctl.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 94e4a72..39decc7 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -310,6 +310,8 @@ sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse)
}
sysctl_unregister_oid(oidp);
if (del) {
+ if (oidp->descr)
+ free(oidp->descr, M_SYSCTLOID);
free((void *)(uintptr_t)(const void *)oidp->oid_name,
M_SYSCTLOID);
free(oidp, M_SYSCTLOID);
@@ -370,6 +372,12 @@ sysctl_add_oid(struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent,
oidp->oid_arg2 = arg2;
}
oidp->oid_fmt = fmt;
+ if (descr) {
+ int len = strlen(descr) + 1;
+ oidp->descr = malloc(len, M_SYSCTLOID, M_WAITOK);
+ if (oidp->descr)
+ strcpy(oidp->descr, descr);
+ }
/* Update the context, if used */
if (clist != NULL)
sysctl_ctx_entry_add(clist, oidp);
@@ -409,6 +417,7 @@ SYSINIT(sysctl, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_all, 0);
* {0,2,...} return the next OID.
* {0,3} return the OID of the name in "new"
* {0,4,...} return the kind & format info for the "..." OID.
+ * {0,5,...} return the description the "..." OID.
*/
static void
@@ -708,6 +717,24 @@ sysctl_sysctl_oidfmt(SYSCTL_HANDLER_ARGS)
SYSCTL_NODE(_sysctl, 4, oidfmt, CTLFLAG_RD, sysctl_sysctl_oidfmt, "");
+static int
+sysctl_sysctl_oiddescr(SYSCTL_HANDLER_ARGS)
+{
+ struct sysctl_oid *oid;
+ int error;
+
+ error = sysctl_find_oid(arg1, arg2, &oid, NULL, req);
+ if (error)
+ return (error);
+
+ if (!oid->descr)
+ return (ENOENT);
+ error = SYSCTL_OUT(req, oid->descr, strlen(oid->descr) + 1);
+ return (error);
+}
+
+SYSCTL_NODE(_sysctl, 5, oiddescr, CTLFLAG_RD, sysctl_sysctl_oiddescr, "");
+
/*
* Default "handler" functions.
*/
OpenPOWER on IntegriCloud