summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2000-02-22 19:28:07 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2000-02-22 19:28:07 +0000
commit5c30cd4260474e303da4723e994e5d93cdcd0483 (patch)
tree61d9e1faf865b66dc174709d28f179d33902c927 /sys/kern
parentf19a9cdec2be86dd535b2a0effa37f4a51e6f4f1 (diff)
enlarge msgbuf, somewhat line netbsd did
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_sysctl.c11
-rw-r--r--sys/kern/subr_log.c61
-rw-r--r--sys/kern/subr_prf.c12
3 files changed, 60 insertions, 24 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 14f3da7c1ff..6afca527cb8 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.29 1999/06/29 23:51:59 provos Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.30 2000/02/22 19:28:03 deraadt Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -58,6 +58,7 @@
#include <sys/disklabel.h>
#include <vm/vm.h>
#include <sys/sysctl.h>
+#include <sys/msgbuf.h>
#if defined(UVM)
#include <uvm/uvm_extern.h>
@@ -349,6 +350,14 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
#else
return (sysctl_rdint(oldp, oldlenp, newp, 0));
#endif
+ case KERN_MSGBUFSIZE:
+ /*
+ * deal with cases where the message buffer has
+ * become corrupted.
+ */
+ if (!msgbufp || msgbufp->msg_magic != MSG_MAGIC)
+ return (ENXIO);
+ return (sysctl_rdint(oldp, oldlenp, newp, msgbufp->msg_bufs));
default:
return (EOPNOTSUPP);
}
diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c
index 5d247ead19f..00eb5a93bc9 100644
--- a/sys/kern/subr_log.c
+++ b/sys/kern/subr_log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_log.c,v 1.5 1997/09/18 13:23:26 deraadt Exp $ */
+/* $OpenBSD: subr_log.c,v 1.6 2000/02/22 19:28:03 deraadt Exp $ */
/* $NetBSD: subr_log.c,v 1.11 1996/03/30 22:24:44 christos Exp $ */
/*
@@ -65,6 +65,44 @@ struct logsoftc {
} logsoftc;
int log_open; /* also used in log() */
+int msgbufmapped; /* is the message buffer mapped */
+int msgbufenabled; /* is logging to the buffer enabled */
+struct msgbuf *msgbufp; /* the mapped buffer, itself. */
+
+#define offsetof(type, member) ((size_t)(&((type *)0)->member))
+
+void
+initmsgbuf(buf, bufsize)
+ caddr_t buf;
+ size_t bufsize;
+{
+ register struct msgbuf *mbp;
+ long new_bufs;
+
+ /* Sanity-check the given size. */
+ if (bufsize < sizeof(struct msgbuf))
+ return;
+
+ mbp = msgbufp = (struct msgbuf *)buf;
+
+ new_bufs = bufsize - offsetof(struct msgbuf, msg_bufc);
+ if ((mbp->msg_magic != MSG_MAGIC) || (mbp->msg_bufs != new_bufs) ||
+ (mbp->msg_bufr < 0) || (mbp->msg_bufr >= mbp->msg_bufs) ||
+ (mbp->msg_bufx < 0) || (mbp->msg_bufx >= mbp->msg_bufs)) {
+ /*
+ * If the buffer magic number is wrong, has changed
+ * size (which shouldn't happen often), or is
+ * internally inconsistent, initialize it.
+ */
+
+ bzero(buf, bufsize);
+ mbp->msg_magic = MSG_MAGIC;
+ mbp->msg_bufs = new_bufs;
+ }
+
+ /* mark it as ready for use. */
+ msgbufmapped = msgbufenabled = 1;
+}
/*ARGSUSED*/
int
@@ -73,24 +111,9 @@ logopen(dev, flags, mode, p)
int flags, mode;
struct proc *p;
{
- register struct msgbuf *mbp = msgbufp;
-
if (log_open)
return (EBUSY);
log_open = 1;
- /*
- * Potential race here with putchar() but since putchar should be
- * called by autoconf, msg_magic should be initialized by the time
- * we get here.
- */
- if (mbp->msg_magic != MSG_MAGIC) {
- register int i;
-
- mbp->msg_magic = MSG_MAGIC;
- mbp->msg_bufx = mbp->msg_bufr = 0;
- for (i=0; i < MSG_BSIZE; i++)
- mbp->msg_bufc[i] = 0;
- }
return (0);
}
@@ -139,7 +162,7 @@ logread(dev, uio, flag)
while (uio->uio_resid > 0) {
l = mbp->msg_bufx - mbp->msg_bufr;
if (l < 0)
- l = MSG_BSIZE - mbp->msg_bufr;
+ l = mbp->msg_bufs - mbp->msg_bufr;
l = min(l, uio->uio_resid);
if (l == 0)
break;
@@ -148,7 +171,7 @@ logread(dev, uio, flag)
if (error)
break;
mbp->msg_bufr += l;
- if (mbp->msg_bufr < 0 || mbp->msg_bufr >= MSG_BSIZE)
+ if (mbp->msg_bufr < 0 || mbp->msg_bufr >= mbp->msg_bufs)
mbp->msg_bufr = 0;
}
return (error);
@@ -212,7 +235,7 @@ logioctl(dev, com, data, flag, p)
l = msgbufp->msg_bufx - msgbufp->msg_bufr;
splx(s);
if (l < 0)
- l += MSG_BSIZE;
+ l += msgbufp->msg_bufs;
*(int *)data = l;
break;
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index 5b6eb3fd762..0ec990f67a9 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_prf.c,v 1.26 1999/12/02 00:23:35 deraadt Exp $ */
+/* $OpenBSD: subr_prf.c,v 1.27 2000/02/22 19:28:04 deraadt Exp $ */
/* $NetBSD: subr_prf.c,v 1.45 1997/10/24 18:14:25 chuck Exp $ */
/*-
@@ -317,12 +317,16 @@ putchar(c, flags, tp)
c != '\0' && c != '\r' && c != 0177 && msgbufmapped) {
mbp = msgbufp;
if (mbp->msg_magic != MSG_MAGIC) {
- bzero((caddr_t) mbp, sizeof(*mbp));
- mbp->msg_magic = MSG_MAGIC;
+ /* Nothing we can do */
}
mbp->msg_bufc[mbp->msg_bufx++] = c;
- if (mbp->msg_bufx < 0 || mbp->msg_bufx >= MSG_BSIZE)
+ if (mbp->msg_bufx < 0 || mbp->msg_bufx >= mbp->msg_bufs)
mbp->msg_bufx = 0;
+ /* If the buffer is full, keep the most recent data. */
+ if (mbp->msg_bufr == mbp->msg_bufx) {
+ if (++mbp->msg_bufr >= mbp->msg_bufs)
+ mbp->msg_bufr = 0;
+ }
}
if ((flags & TOCONS) && constty == NULL && c != '\0')
(*v_putc)(c);