Module Name:    src
Committed By:   pooka
Date:           Wed May 20 11:17:24 UTC 2015

Modified Files:
        src/sys/kern: init_sysctl.c subr_log.c

Log Message:
group msgbuf sysctls with the msgbuf code
(init_sysctl.c -> subr_log.c)


To generate a diff of this commit:
cvs rdiff -u -r1.206 -r1.207 src/sys/kern/init_sysctl.c
cvs rdiff -u -r1.53 -r1.54 src/sys/kern/subr_log.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/init_sysctl.c
diff -u src/sys/kern/init_sysctl.c:1.206 src/sys/kern/init_sysctl.c:1.207
--- src/sys/kern/init_sysctl.c:1.206	Wed May 13 01:00:16 2015
+++ src/sys/kern/init_sysctl.c	Wed May 20 11:17:24 2015
@@ -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.
 #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(SYSCTLF
 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
@@ -266,12 +264,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl 
 		       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",
 		       SYSCTL_DESCR("Whether the POSIX 1003.1b File "
@@ -388,12 +380,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl 
 		       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",
 		       SYSCTL_DESCR("Console device"),
 		       sysctl_consdev, 0, NULL, sizeof(dev_t),
@@ -939,83 +925,6 @@ sysctl_kern_hostid(SYSCTLFN_ARGS)
 }
 
 /*
- * 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.
  * (XXX the check in -current doesn't work, but do we really care?)

Index: src/sys/kern/subr_log.c
diff -u src/sys/kern/subr_log.c:1.53 src/sys/kern/subr_log.c:1.54
--- src/sys/kern/subr_log.c:1.53	Fri Jul 25 08:10:40 2014
+++ src/sys/kern/subr_log.c	Wed May 20 11:17:24 2015
@@ -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
 #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,

Reply via email to