From 21885af505b396ec8136e19022143ea2c9b2dff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Fri, 27 Feb 2004 17:13:23 +0000 Subject: [PATCH] Add sysctl_move_oid() which reparents an existing OID. --- sys/kern/kern_sysctl.c | 20 ++++++++++++++++++++ sys/sys/sysctl.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 62f87e769b98..e608b64e7917 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -415,6 +415,26 @@ sysctl_add_oid(struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent, return (oidp); } +/* + * Reparent an existing oid. + */ +int +sysctl_move_oid(struct sysctl_oid *oid, struct sysctl_oid_list *parent) +{ + struct sysctl_oid *oidp; + + if (oid->oid_parent == parent) + return (0); + oidp = sysctl_find_oidname(oid->oid_name, parent); + if (oidp != NULL) + return (EEXIST); + sysctl_unregister_oid(oid); + oid->oid_parent = parent; + oid->oid_number = OID_AUTO; + sysctl_register_oid(oid); + return (0); +} + /* * Register the kernel's oids on startup. */ diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 98e8d32aed0f..b4b66e7b5555 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -603,6 +603,8 @@ struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist, int kind, void *arg1, int arg2, int (*handler) (SYSCTL_HANDLER_ARGS), const char *fmt, const char *descr); +int sysctl_move_oid(struct sysctl_oid *oidp, + struct sysctl_oid_list *parent); int sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse); int sysctl_ctx_init(struct sysctl_ctx_list *clist); int sysctl_ctx_free(struct sysctl_ctx_list *clist);