Module Name:    src
Committed By:   msaitoh
Date:           Tue May 27 05:14:02 UTC 2014

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

Log Message:
 Move forward read pointer to the next line in the buffer
to prevent corrupting the most old line.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 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/subr_log.c
diff -u src/sys/kern/subr_log.c:1.51 src/sys/kern/subr_log.c:1.52
--- src/sys/kern/subr_log.c:1.51	Sun Mar 16 05:20:30 2014
+++ src/sys/kern/subr_log.c	Tue May 27 05:14:02 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_log.c,v 1.51 2014/03/16 05:20:30 dholland Exp $	*/
+/*	$NetBSD: subr_log.c,v 1.52 2014/05/27 05:14:02 msaitoh 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.51 2014/03/16 05:20:30 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_log.c,v 1.52 2014/05/27 05:14:02 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -387,8 +387,26 @@ logputchar(int c)
 				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;
+				char c0;
+				int i;
+
+				/*
+				 * Move forward read pointer to the next line
+				 * in the buffer.  Note that the buffer is
+				 * a ring buffer so we should reset msg_bufr
+				 * to 0 when msg_bufr exceeds msg_bufs.
+				 *
+				 * To prevent to loop forever, give up if we
+				 * cannot find a newline in mbp->msg_bufs
+				 * characters (the max size of the buffer).
+				 */
+				for (i = 0; i < mbp->msg_bufs; i++) {
+					c0 = mbp->msg_bufc[mbp->msg_bufr];
+					if (++mbp->msg_bufr >= mbp->msg_bufs)
+						mbp->msg_bufr = 0;
+					if (c0 == '\n')
+						break;
+				}
 			}
 		}
 	}

Reply via email to