group msgbuf sysctls with the msgbuf code
(init_sysctl.c -> subr_log.c)
This commit is contained in:
parent
e63dc818ef
commit
f67bb039d4
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: init_sysctl.c,v 1.206 2015/05/13 01:00:16 pgoyette Exp $ */
|
||||
/* $NetBSD: init_sysctl.c,v 1.207 2015/05/20 11:17:24 pooka Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
|
||||
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.206 2015/05/13 01:00:16 pgoyette Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.207 2015/05/20 11:17:24 pooka Exp $");
|
||||
|
||||
#include "opt_sysv.h"
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
@ -50,7 +50,6 @@ __KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.206 2015/05/13 01:00:16 pgoyette E
|
|||
#include <sys/vnode.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/namei.h>
|
||||
#include <sys/msgbuf.h>
|
||||
#include <dev/cons.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/file.h>
|
||||
|
@ -115,7 +114,6 @@ static int sysctl_kern_maxvnodes(SYSCTLFN_PROTO);
|
|||
static int sysctl_kern_rtc_offset(SYSCTLFN_PROTO);
|
||||
static int sysctl_kern_maxproc(SYSCTLFN_PROTO);
|
||||
static int sysctl_kern_hostid(SYSCTLFN_PROTO);
|
||||
static int sysctl_msgbuf(SYSCTLFN_PROTO);
|
||||
static int sysctl_kern_defcorename(SYSCTLFN_PROTO);
|
||||
static int sysctl_kern_cptime(SYSCTLFN_PROTO);
|
||||
#if NPTY > 0
|
||||
|
@ -265,12 +263,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
|
|||
SYSCTL_DESCR("Name of the root device"),
|
||||
sysctl_root_device, 0, NULL, 0,
|
||||
CTL_KERN, KERN_ROOT_DEVICE, CTL_EOL);
|
||||
sysctl_createv(clog, 0, NULL, NULL,
|
||||
CTLFLAG_PERMANENT,
|
||||
CTLTYPE_INT, "msgbufsize",
|
||||
SYSCTL_DESCR("Size of the kernel message buffer"),
|
||||
sysctl_msgbuf, 0, NULL, 0,
|
||||
CTL_KERN, KERN_MSGBUFSIZE, CTL_EOL);
|
||||
sysctl_createv(clog, 0, NULL, NULL,
|
||||
CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
|
||||
CTLTYPE_INT, "fsync",
|
||||
|
@ -386,12 +378,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl kern subtree setup")
|
|||
SYSCTL_DESCR("Clock ticks spent in different CPU states"),
|
||||
sysctl_kern_cptime, 0, NULL, 0,
|
||||
CTL_KERN, KERN_CP_TIME, CTL_EOL);
|
||||
sysctl_createv(clog, 0, NULL, NULL,
|
||||
CTLFLAG_PERMANENT,
|
||||
CTLTYPE_INT, "msgbuf",
|
||||
SYSCTL_DESCR("Kernel message buffer"),
|
||||
sysctl_msgbuf, 0, NULL, 0,
|
||||
CTL_KERN, KERN_MSGBUF, CTL_EOL);
|
||||
sysctl_createv(clog, 0, NULL, NULL,
|
||||
CTLFLAG_PERMANENT,
|
||||
CTLTYPE_STRUCT, "consdev",
|
||||
|
@ -938,83 +924,6 @@ sysctl_kern_hostid(SYSCTLFN_ARGS)
|
|||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* sysctl helper routine for kern.msgbufsize and kern.msgbuf. For the
|
||||
* former it merely checks the message buffer is set up. For the latter,
|
||||
* it also copies out the data if necessary.
|
||||
*/
|
||||
static int
|
||||
sysctl_msgbuf(SYSCTLFN_ARGS)
|
||||
{
|
||||
char *where = oldp;
|
||||
size_t len, maxlen;
|
||||
long beg, end;
|
||||
extern kmutex_t log_lock;
|
||||
int error;
|
||||
|
||||
if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
|
||||
msgbufenabled = 0;
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
switch (rnode->sysctl_num) {
|
||||
case KERN_MSGBUFSIZE: {
|
||||
struct sysctlnode node = *rnode;
|
||||
int msg_bufs = (int)msgbufp->msg_bufs;
|
||||
node.sysctl_data = &msg_bufs;
|
||||
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
|
||||
}
|
||||
case KERN_MSGBUF:
|
||||
break;
|
||||
default:
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
|
||||
if (newp != NULL)
|
||||
return (EPERM);
|
||||
|
||||
if (oldp == NULL) {
|
||||
/* always return full buffer size */
|
||||
*oldlenp = msgbufp->msg_bufs;
|
||||
return (0);
|
||||
}
|
||||
|
||||
sysctl_unlock();
|
||||
|
||||
/*
|
||||
* First, copy from the write pointer to the end of
|
||||
* message buffer.
|
||||
*/
|
||||
error = 0;
|
||||
mutex_spin_enter(&log_lock);
|
||||
maxlen = MIN(msgbufp->msg_bufs, *oldlenp);
|
||||
beg = msgbufp->msg_bufx;
|
||||
end = msgbufp->msg_bufs;
|
||||
mutex_spin_exit(&log_lock);
|
||||
|
||||
while (maxlen > 0) {
|
||||
len = MIN(end - beg, maxlen);
|
||||
if (len == 0)
|
||||
break;
|
||||
/* XXX unlocked, but hardly matters. */
|
||||
error = dcopyout(l, &msgbufp->msg_bufc[beg], where, len);
|
||||
if (error)
|
||||
break;
|
||||
where += len;
|
||||
maxlen -= len;
|
||||
|
||||
/*
|
||||
* ... then, copy from the beginning of message buffer to
|
||||
* the write pointer.
|
||||
*/
|
||||
beg = 0;
|
||||
end = msgbufp->msg_bufx;
|
||||
}
|
||||
|
||||
sysctl_relock();
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* sysctl helper routine for kern.defcorename. In the case of a new
|
||||
* string being assigned, check that it's not a zero-length string.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: subr_log.c,v 1.53 2014/07/25 08:10:40 dholland Exp $ */
|
||||
/* $NetBSD: subr_log.c,v 1.54 2015/05/20 11:17:24 pooka Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -65,7 +65,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_log.c,v 1.53 2014/07/25 08:10:40 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_log.c,v 1.54 2015/05/20 11:17:24 pooka Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -80,6 +80,10 @@ __KERNEL_RCSID(0, "$NetBSD: subr_log.c,v 1.53 2014/07/25 08:10:40 dholland Exp $
|
|||
#include <sys/select.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/intr.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/ktrace.h>
|
||||
|
||||
static int sysctl_msgbuf(SYSCTLFN_PROTO);
|
||||
|
||||
static void logsoftintr(void *);
|
||||
|
||||
|
@ -129,12 +133,26 @@ initmsgbuf(void *bf, size_t bufsize)
|
|||
void
|
||||
loginit(void)
|
||||
{
|
||||
struct sysctllog *log = NULL;
|
||||
|
||||
mutex_init(&log_lock, MUTEX_DEFAULT, IPL_VM);
|
||||
selinit(&log_selp);
|
||||
cv_init(&log_cv, "klog");
|
||||
log_sih = softint_establish(SOFTINT_CLOCK | SOFTINT_MPSAFE,
|
||||
logsoftintr, NULL);
|
||||
|
||||
sysctl_createv(&log, 0, NULL, NULL,
|
||||
CTLFLAG_PERMANENT,
|
||||
CTLTYPE_INT, "msgbufsize",
|
||||
SYSCTL_DESCR("Size of the kernel message buffer"),
|
||||
sysctl_msgbuf, 0, NULL, 0,
|
||||
CTL_KERN, KERN_MSGBUFSIZE, CTL_EOL);
|
||||
sysctl_createv(&log, 0, NULL, NULL,
|
||||
CTLFLAG_PERMANENT,
|
||||
CTLTYPE_INT, "msgbuf",
|
||||
SYSCTL_DESCR("Kernel message buffer"),
|
||||
sysctl_msgbuf, 0, NULL, 0,
|
||||
CTL_KERN, KERN_MSGBUF, CTL_EOL);
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
|
@ -414,6 +432,84 @@ logputchar(int c)
|
|||
mutex_spin_exit(&log_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* sysctl helper routine for kern.msgbufsize and kern.msgbuf. For the
|
||||
* former it merely checks the message buffer is set up. For the latter,
|
||||
* it also copies out the data if necessary.
|
||||
*/
|
||||
static int
|
||||
sysctl_msgbuf(SYSCTLFN_ARGS)
|
||||
{
|
||||
char *where = oldp;
|
||||
size_t len, maxlen;
|
||||
long beg, end;
|
||||
extern kmutex_t log_lock;
|
||||
int error;
|
||||
|
||||
if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
|
||||
msgbufenabled = 0;
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
switch (rnode->sysctl_num) {
|
||||
case KERN_MSGBUFSIZE: {
|
||||
struct sysctlnode node = *rnode;
|
||||
int msg_bufs = (int)msgbufp->msg_bufs;
|
||||
node.sysctl_data = &msg_bufs;
|
||||
return (sysctl_lookup(SYSCTLFN_CALL(&node)));
|
||||
}
|
||||
case KERN_MSGBUF:
|
||||
break;
|
||||
default:
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
|
||||
if (newp != NULL)
|
||||
return (EPERM);
|
||||
|
||||
if (oldp == NULL) {
|
||||
/* always return full buffer size */
|
||||
*oldlenp = msgbufp->msg_bufs;
|
||||
return (0);
|
||||
}
|
||||
|
||||
sysctl_unlock();
|
||||
|
||||
/*
|
||||
* First, copy from the write pointer to the end of
|
||||
* message buffer.
|
||||
*/
|
||||
error = 0;
|
||||
mutex_spin_enter(&log_lock);
|
||||
maxlen = MIN(msgbufp->msg_bufs, *oldlenp);
|
||||
beg = msgbufp->msg_bufx;
|
||||
end = msgbufp->msg_bufs;
|
||||
mutex_spin_exit(&log_lock);
|
||||
|
||||
while (maxlen > 0) {
|
||||
len = MIN(end - beg, maxlen);
|
||||
if (len == 0)
|
||||
break;
|
||||
/* XXX unlocked, but hardly matters. */
|
||||
error = copyout(&msgbufp->msg_bufc[beg], where, len);
|
||||
ktrmibio(-1, UIO_READ, where, len, error);
|
||||
if (error)
|
||||
break;
|
||||
where += len;
|
||||
maxlen -= len;
|
||||
|
||||
/*
|
||||
* ... then, copy from the beginning of message buffer to
|
||||
* the write pointer.
|
||||
*/
|
||||
beg = 0;
|
||||
end = msgbufp->msg_bufx;
|
||||
}
|
||||
|
||||
sysctl_relock();
|
||||
return (error);
|
||||
}
|
||||
|
||||
const struct cdevsw log_cdevsw = {
|
||||
.d_open = logopen,
|
||||
.d_close = logclose,
|
||||
|
|
Loading…
Reference in New Issue