summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-08-06 21:50:14 -0400
committerIan Moffett <ian@osmora.org>2025-08-06 21:50:14 -0400
commit123814b7bba93fa2db52339e8cdbb58607fd841d (patch)
tree1d83cd4e5da68526c10f18401e7464c68a0d6099 /sys
parent1864719a2d1d529489a9faa37c563dcbb17e3476 (diff)
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 <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/include/sys/sysctl.h1
-rw-r--r--sys/kern/kern_sysctl.c27
2 files changed, 28 insertions, 0 deletions
diff --git a/sys/include/sys/sysctl.h b/sys/include/sys/sysctl.h
index d13b0f8..d258860 100644
--- a/sys/include/sys/sysctl.h
+++ b/sys/include/sys/sysctl.h
@@ -64,6 +64,7 @@ struct sysctl_entry {
};
scret_t sys_sysctl(struct syscall_args *scargs);
+int sysctl_clearstr(int name);
#endif /* _KERNEL */
/*
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)
{