summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_sysctl.c
diff options
context:
space:
mode:
authormux <mux@FreeBSD.org>2003-05-29 21:19:18 +0000
committermux <mux@FreeBSD.org>2003-05-29 21:19:18 +0000
commit2618a96d5eaa02adcc4f5043ef029e9c1bc51c81 (patch)
tree8cbeded88d20e0cef689f31e25f6207e0a622d9a /sys/kern/kern_sysctl.c
parent8c86272540080808f88917a48792b24b06cacedb (diff)
downloadFreeBSD-src-2618a96d5eaa02adcc4f5043ef029e9c1bc51c81.zip
FreeBSD-src-2618a96d5eaa02adcc4f5043ef029e9c1bc51c81.tar.gz
When loading a module that contains a sysctl which is already compiled
in the kernel, the sysctl_register() call would fail, as expected. However, when unloading this module again, the kernel would then panic in sysctl_unregister(). Print a message error instead. Submitted by: Nicolai Petri <nicolai@catpipe.net> Reviewed by: imp Approved by: re@ (jhb)
Diffstat (limited to 'sys/kern/kern_sysctl.c')
-rw-r--r--sys/kern/kern_sysctl.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 26b309c..ab585e1 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -153,7 +153,30 @@ sysctl_register_oid(struct sysctl_oid *oidp)
void
sysctl_unregister_oid(struct sysctl_oid *oidp)
{
- SLIST_REMOVE(oidp->oid_parent, oidp, sysctl_oid, oid_link);
+ struct sysctl_oid *p;
+ int error;
+
+ error = ENOENT;
+ if (oidp->oid_number == OID_AUTO) {
+ error = EINVAL;
+ } else {
+ SLIST_FOREACH(p, oidp->oid_parent, oid_link) {
+ if (p == oidp) {
+ SLIST_REMOVE(oidp->oid_parent, oidp,
+ sysctl_oid, oid_link);
+ error = 0;
+ break;
+ }
+ }
+ }
+
+ /*
+ * This can happen when a module fails to register and is
+ * being unloaded afterwards. It should not be a panic()
+ * for normal use.
+ */
+ if (error)
+ printf("%s: failed to unregister sysctl\n", __func__);
}
/* Initialize a new context to keep track of dynamically added sysctls. */
OpenPOWER on IntegriCloud