From 948d3d9484a81cc919ec1e0edee3cd4239c19f05 Mon Sep 17 00:00:00 2001 From: Thomas Moestl Date: Tue, 3 Jul 2001 19:44:07 +0000 Subject: [PATCH] Make the code to read the kernel message buffer via sysctl machine- independent and rename the corresponding sysctls from machdep.msgbuf and machdep.msgbuf_clear (i386 only) to kern.msgbuf and kern.msgbuf_clear. --- sys/amd64/amd64/machdep.c | 42 ------------------------------------ sys/i386/i386/machdep.c | 42 ------------------------------------ sys/kern/subr_prf.c | 45 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 84 deletions(-) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index e5eb21e7850..73b80524b3d 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -184,48 +184,6 @@ sysctl_hw_availpages(SYSCTL_HANDLER_ARGS) SYSCTL_PROC(_hw, OID_AUTO, availpages, CTLTYPE_INT|CTLFLAG_RD, 0, 0, sysctl_hw_availpages, "I", ""); -static int -sysctl_machdep_msgbuf(SYSCTL_HANDLER_ARGS) -{ - int error; - - /* Unwind the buffer, so that it's linear (possibly starting with - * some initial nulls). - */ - error=sysctl_handle_opaque(oidp,msgbufp->msg_ptr+msgbufp->msg_bufr, - msgbufp->msg_size-msgbufp->msg_bufr,req); - if(error) return(error); - if(msgbufp->msg_bufr>0) { - error=sysctl_handle_opaque(oidp,msgbufp->msg_ptr, - msgbufp->msg_bufr,req); - } - return(error); -} - -SYSCTL_PROC(_machdep, OID_AUTO, msgbuf, CTLTYPE_STRING|CTLFLAG_RD, - 0, 0, sysctl_machdep_msgbuf, "A","Contents of kernel message buffer"); - -static int msgbuf_clear; - -static int -sysctl_machdep_msgbuf_clear(SYSCTL_HANDLER_ARGS) -{ - int error; - error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, - req); - if (!error && req->newptr) { - /* Clear the buffer and reset write pointer */ - bzero(msgbufp->msg_ptr,msgbufp->msg_size); - msgbufp->msg_bufr=msgbufp->msg_bufx=0; - msgbuf_clear=0; - } - return (error); -} - -SYSCTL_PROC(_machdep, OID_AUTO, msgbuf_clear, CTLTYPE_INT|CTLFLAG_RW, - &msgbuf_clear, 0, sysctl_machdep_msgbuf_clear, "I", - "Clear kernel message buffer"); - int Maxmem = 0; long dumplo; diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index e5eb21e7850..73b80524b3d 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -184,48 +184,6 @@ sysctl_hw_availpages(SYSCTL_HANDLER_ARGS) SYSCTL_PROC(_hw, OID_AUTO, availpages, CTLTYPE_INT|CTLFLAG_RD, 0, 0, sysctl_hw_availpages, "I", ""); -static int -sysctl_machdep_msgbuf(SYSCTL_HANDLER_ARGS) -{ - int error; - - /* Unwind the buffer, so that it's linear (possibly starting with - * some initial nulls). - */ - error=sysctl_handle_opaque(oidp,msgbufp->msg_ptr+msgbufp->msg_bufr, - msgbufp->msg_size-msgbufp->msg_bufr,req); - if(error) return(error); - if(msgbufp->msg_bufr>0) { - error=sysctl_handle_opaque(oidp,msgbufp->msg_ptr, - msgbufp->msg_bufr,req); - } - return(error); -} - -SYSCTL_PROC(_machdep, OID_AUTO, msgbuf, CTLTYPE_STRING|CTLFLAG_RD, - 0, 0, sysctl_machdep_msgbuf, "A","Contents of kernel message buffer"); - -static int msgbuf_clear; - -static int -sysctl_machdep_msgbuf_clear(SYSCTL_HANDLER_ARGS) -{ - int error; - error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, - req); - if (!error && req->newptr) { - /* Clear the buffer and reset write pointer */ - bzero(msgbufp->msg_ptr,msgbufp->msg_size); - msgbufp->msg_bufr=msgbufp->msg_bufx=0; - msgbuf_clear=0; - } - return (error); -} - -SYSCTL_PROC(_machdep, OID_AUTO, msgbuf_clear, CTLTYPE_INT|CTLFLAG_RW, - &msgbuf_clear, 0, sysctl_machdep_msgbuf_clear, "I", - "Clear kernel message buffer"); - int Maxmem = 0; long dumplo; diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 86a5376631d..3ce2d7d9110 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -49,6 +49,7 @@ #include #include #include +#include /* * Note that stdarg.h and the ANSI style va_start macro is used for both @@ -814,6 +815,50 @@ msgbufinit(void *ptr, size_t size) oldp = msgbufp; } +/* Sysctls for accessing/clearing the msgbuf */ +static int +sysctl_kern_msgbuf(SYSCTL_HANDLER_ARGS) +{ + int error; + + /* + * Unwind the buffer, so that it's linear (possibly starting with + * some initial nulls). + */ + error = sysctl_handle_opaque(oidp, msgbufp->msg_ptr + msgbufp->msg_bufx, + msgbufp->msg_size - msgbufp->msg_bufx, req); + if (error) + return (error); + if (msgbufp->msg_bufx > 0) { + error = sysctl_handle_opaque(oidp, msgbufp->msg_ptr, + msgbufp->msg_bufx, req); + } + return (error); +} + +SYSCTL_PROC(_kern, OID_AUTO, msgbuf, CTLTYPE_STRING | CTLFLAG_RD, + 0, 0, sysctl_kern_msgbuf, "A", "Contents of kernel message buffer"); + +static int msgbuf_clear; + +static int +sysctl_kern_msgbuf_clear(SYSCTL_HANDLER_ARGS) +{ + int error; + error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, req); + if (!error && req->newptr) { + /* Clear the buffer and reset write pointer */ + bzero(msgbufp->msg_ptr, msgbufp->msg_size); + msgbufp->msg_bufr = msgbufp->msg_bufx = 0; + msgbuf_clear = 0; + } + return (error); +} + +SYSCTL_PROC(_kern, OID_AUTO, msgbuf_clear, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE, &msgbuf_clear, 0, + sysctl_kern_msgbuf_clear, "I", "Clear kernel message buffer"); + #include "opt_ddb.h" #ifdef DDB #include