aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_sysctl.c
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2016-05-26 08:41:55 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2016-05-26 08:41:55 +0000
commit84e717c4cf7a88a51024de6636620bd4410cc6e1 (patch)
treecb243db106b02f1b384df6e20ed80b2006ca12f1 /sys/kern/kern_sysctl.c
parent6c6f602b53a7cfcc5ec9faea2f7e95f7aef72d52 (diff)
downloadsrc-84e717c4cf7a88a51024de6636620bd4410cc6e1.tar.gz
src-84e717c4cf7a88a51024de6636620bd4410cc6e1.zip
Add support for boolean sysctl's.
Because the size of bool can be implementation defined, make a bool sysctl handler which handle bools. Userspace sees the bools like unsigned 8-bit integers. Values are filtered to either 1 or 0 upon read and write, similar to what a compiler would do. Requested by: kmacy @ Sponsored by: Mellanox Technologies
Notes
Notes: svn path=/head/; revision=300718
Diffstat (limited to 'sys/kern/kern_sysctl.c')
-rw-r--r--sys/kern/kern_sysctl.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 37dfff1419d8..5b8870f3b0f2 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1181,6 +1181,41 @@ static SYSCTL_NODE(_sysctl, 5, oiddescr, CTLFLAG_RD|CTLFLAG_MPSAFE|CTLFLAG_CAPRD
*/
/*
+ * Handle a bool.
+ * Two cases:
+ * a variable: point arg1 at it.
+ * a constant: pass it in arg2.
+ */
+
+int
+sysctl_handle_bool(SYSCTL_HANDLER_ARGS)
+{
+ uint8_t temp;
+ int error;
+
+ /*
+ * Attempt to get a coherent snapshot by making a copy of the data.
+ */
+ if (arg1)
+ temp = *(bool *)arg1 ? 1 : 0;
+ else
+ temp = arg2 ? 1 : 0;
+
+ error = SYSCTL_OUT(req, &temp, sizeof(temp));
+ if (error || !req->newptr)
+ return (error);
+
+ if (!arg1)
+ error = EPERM;
+ else {
+ error = SYSCTL_IN(req, &temp, sizeof(temp));
+ if (!error)
+ *(bool *)arg1 = temp ? 1 : 0;
+ }
+ return (error);
+}
+
+/*
* Handle an int8_t, signed or unsigned.
* Two cases:
* a variable: point arg1 at it.