From 123814b7bba93fa2db52339e8cdbb58607fd841d Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 6 Aug 2025 21:50:14 -0400 Subject: kernel: sysctl: Add sysctl_clearstr() Introduce the sysctl_clearstr() function to clear string variables that aren't readonly to a known state. Signed-off-by: Ian Moffett --- sys/kern/kern_sysctl.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'sys/kern') diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 7679aa1..f5d8bdc 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -154,6 +154,33 @@ done: return retval; } +/* + * Clear a writable sysctl string variable to the + * value of "(undef)" + * + * @name: Name to clear + */ +int +sysctl_clearstr(int name) +{ + struct sysctl_args args; + char val[] = "(undef)"; + int error; + + args.name = &name; + args.nlen = 1; + args.oldlenp = 0; + args.oldp = NULL; + args.newp = val; + args.newlen = sizeof(val); + + if ((error = sysctl(&args)) != 0) { + return error; + } + + return 0; +} + int sysctl(struct sysctl_args *args) { -- cgit v1.2.3