summaryrefslogtreecommitdiff
path: root/sys/kern/subr_log.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern/subr_log.c')
-rw-r--r--sys/kern/subr_log.c61
1 files changed, 42 insertions, 19 deletions
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;