diff options
author | mdf <mdf@FreeBSD.org> | 2010-09-16 16:13:12 +0000 |
---|---|---|
committer | mdf <mdf@FreeBSD.org> | 2010-09-16 16:13:12 +0000 |
commit | 5695ef46983ceb88b1862571c052f8da0fac0275 (patch) | |
tree | afd1abc4a36abd5ca015ead87a457fe7f1968ed9 /sys/kern/kern_sysctl.c | |
parent | 39642e55302d3d222f5a118fb3a4c6eb91d7e5a0 (diff) | |
download | FreeBSD-src-5695ef46983ceb88b1862571c052f8da0fac0275.zip FreeBSD-src-5695ef46983ceb88b1862571c052f8da0fac0275.tar.gz |
Re-add r212370 now that the LOR in powerpc64 has been resolved:
Add a drain function for struct sysctl_req, and use it for a variety
of handlers, some of which had to do awkward things to get a large
enough SBUF_FIXEDLEN buffer.
Note that some sysctl handlers were explicitly outputting a trailing
NUL byte. This behaviour was preserved, though it should not be
necessary.
Reviewed by: phk (original patch)
Diffstat (limited to 'sys/kern/kern_sysctl.c')
-rw-r--r-- | sys/kern/kern_sysctl.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index b83502c..49ccc50 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include <sys/jail.h> #include <sys/lock.h> #include <sys/mutex.h> +#include <sys/sbuf.h> #include <sys/sx.h> #include <sys/sysproto.h> #include <sys/uio.h> @@ -1544,3 +1545,30 @@ userland_sysctl(struct thread *td, int *name, u_int namelen, void *old, } return (error); } + +/* + * Drain into a sysctl struct. The user buffer must be wired. + */ +static int +sbuf_sysctl_drain(void *arg, const char *data, int len) +{ + struct sysctl_req *req = arg; + int error; + + error = SYSCTL_OUT(req, data, len); + KASSERT(error >= 0, ("Got unexpected negative value %d", error)); + return (error == 0 ? len : -error); +} + +struct sbuf * +sbuf_new_for_sysctl(struct sbuf *s, char *buf, int length, + struct sysctl_req *req) +{ + + /* Wire the user buffer, so we can write without blocking. */ + sysctl_wire_old_buffer(req, 0); + + s = sbuf_new(s, buf, length, SBUF_FIXEDLEN); + sbuf_set_drain(s, sbuf_sysctl_drain, req); + return (s); +} |