Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
authormillert <millert@openbsd.org>
Mon, 13 Mar 2000 04:05:13 +0000 (04:05 +0000)
committermillert <millert@openbsd.org>
Mon, 13 Mar 2000 04:05:13 +0000 (04:05 +0000)
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare.  Joint effort with Theo.

sys/kern/subr_prf.c
sys/miscfs/kernfs/kernfs_vnops.c
sys/sys/msgbuf.h

index 5ab131d..5bd4b69 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: subr_prf.c,v 1.28 2000/03/02 10:50:29 art Exp $       */
+/*     $OpenBSD: subr_prf.c,v 1.29 2000/03/13 04:05:15 millert Exp $   */
 /*     $NetBSD: subr_prf.c,v 1.45 1997/10/24 18:14:25 chuck Exp $      */
 
 /*-
@@ -335,6 +335,7 @@ putchar(c, flags, tp)
                        /* Nothing we can do */
                }
                mbp->msg_bufc[mbp->msg_bufx++] = c;
+               mbp->msg_bufl = min(mbp->msg_bufl+1, mbp->msg_bufs);
                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. */
index 23922ae..160e437 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kernfs_vnops.c,v 1.18 2000/02/22 19:28:06 deraadt Exp $       */
+/*     $OpenBSD: kernfs_vnops.c,v 1.19 2000/03/13 04:05:15 millert Exp $       */
 /*     $NetBSD: kernfs_vnops.c,v 1.43 1996/03/16 23:52:47 christos Exp $       */
 
 /*
@@ -269,12 +269,19 @@ kernfs_xread(kt, off, bufp, len)
                 * message buffer header are corrupted, but that'll cause
                 * the system to die anyway.
                 */
-               if (off >= msgbufp->msg_bufs)
-                       return (0);
-               n = msgbufp->msg_bufx + off;
-               if (n >= msgbufp->msg_bufs)
-                       n -= msgbufp->msg_bufs;
-               len = min(msgbufp->msg_bufs - n, msgbufp->msg_bufs - off);
+               if (msgbufp->msg_bufl < msgbufp->msg_bufs) {
+                       if (off >= msgbufp->msg_bufx)
+                               return (0);
+                       n = off;
+                       len = msgbufp->msg_bufx - n;
+               } else {
+                       if (off >= msgbufp->msg_bufs)
+                               return (0);
+                       n = msgbufp->msg_bufx + off;
+                       if (n >= msgbufp->msg_bufs)
+                               n -= msgbufp->msg_bufs;
+                       len = min(msgbufp->msg_bufs - n, msgbufp->msg_bufs - off);
+               }
                *bufp = msgbufp->msg_bufc + n;
                return (len);
        }
index 1214c4c..a09cc13 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: msgbuf.h,v 1.3 2000/02/22 19:28:05 deraadt Exp $      */
+/*     $OpenBSD: msgbuf.h,v 1.4 2000/03/13 04:05:13 millert Exp $      */
 /*     $NetBSD: msgbuf.h,v 1.8 1995/03/26 20:24:27 jtc Exp $   */
 
 /*
@@ -42,6 +42,7 @@ struct        msgbuf {
        long    msg_bufx;               /* write pointer */
        long    msg_bufr;               /* read pointer */
        long    msg_bufs;               /* real msg_bufc size (bytes) */
+       long    msg_bufl;               /* # chars, <= msg_bufs */
        char    msg_bufc[1];            /* buffer */
 };
 #ifdef _KERNEL