From: bluhm Date: Thu, 23 Jun 2016 13:15:21 +0000 (+0000) Subject: It is annoying that the dmesg buffer can overflow and loose messages X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bdd0b010f760764bcd11184af241dfada2a448d5;p=openbsd It is annoying that the dmesg buffer can overflow and loose messages undetected during debugging. To make clear what happens, count the dropped bytes and write message buffer full to syslogd. This also helps to have a reliable log system. OK deraadt@ millert@ tedu@ --- diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c index 4c948e0fa83..dc0d90c1613 100644 --- a/sys/kern/subr_log.c +++ b/sys/kern/subr_log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_log.c,v 1.46 2016/06/08 11:11:47 bluhm Exp $ */ +/* $OpenBSD: subr_log.c,v 1.47 2016/06/23 13:15:21 bluhm Exp $ */ /* $NetBSD: subr_log.c,v 1.11 1996/03/30 22:24:44 christos Exp $ */ /* @@ -155,6 +155,7 @@ msgbuf_putchar(struct msgbuf *mbp, const char c) if (mbp->msg_bufr == mbp->msg_bufx) { if (++mbp->msg_bufr >= mbp->msg_bufs) mbp->msg_bufr = 0; + mbp->msg_bufd++; } splx(s); } @@ -201,6 +202,19 @@ logread(dev_t dev, struct uio *uio, int flag) } logsoftc.sc_state &= ~LOG_RDWAIT; + if (mbp->msg_bufd > 0) { + char buf[64]; + + l = snprintf(buf, sizeof(buf), + "<%d>klog: dropped %ld byte%s, message buffer full\n", + LOG_KERN|LOG_WARNING, mbp->msg_bufd, + mbp->msg_bufd == 1 ? "" : "s"); + error = uiomove(buf, ulmin(l, sizeof(buf) - 1), uio); + if (error) + goto out; + mbp->msg_bufd = 0; + } + while (uio->uio_resid > 0) { if (mbp->msg_bufx >= mbp->msg_bufr) l = mbp->msg_bufx - mbp->msg_bufr; diff --git a/sys/sys/msgbuf.h b/sys/sys/msgbuf.h index de4e5be2390..3a53a5a8d8e 100644 --- a/sys/sys/msgbuf.h +++ b/sys/sys/msgbuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: msgbuf.h,v 1.10 2015/01/13 18:51:27 kettenis Exp $ */ +/* $OpenBSD: msgbuf.h,v 1.11 2016/06/23 13:15:21 bluhm Exp $ */ /* $NetBSD: msgbuf.h,v 1.8 1995/03/26 20:24:27 jtc Exp $ */ /* @@ -39,6 +39,7 @@ struct msgbuf { long msg_bufr; /* read pointer */ long msg_bufs; /* real msg_bufc size (bytes) */ long msg_bufl; /* # chars, <= msg_bufs */ + long msg_bufd; /* number of dropped bytes */ char msg_bufc[1]; /* buffer */ }; #ifdef _KERNEL