Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Move forward read pointer to the next line in the b...
details: https://anonhg.NetBSD.org/src/rev/15d60069d4cf
branches: trunk
changeset: 329492:15d60069d4cf
user: msaitoh <msaitoh%NetBSD.org@localhost>
date: Tue May 27 05:14:02 2014 +0000
description:
Move forward read pointer to the next line in the buffer
to prevent corrupting the most old line.
diffstat:
sys/kern/subr_log.c | 26 ++++++++++++++++++++++----
1 files changed, 22 insertions(+), 4 deletions(-)
diffs (47 lines):
diff -r 2dc10d427171 -r 15d60069d4cf sys/kern/subr_log.c
--- a/sys/kern/subr_log.c Tue May 27 04:18:00 2014 +0000
+++ b/sys/kern/subr_log.c Tue May 27 05:14:02 2014 +0000
@@ -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 @@
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;
+ }
}
}
}
Home |
Main Index |
Thread Index |
Old Index