diff options
author | bde <bde@FreeBSD.org> | 1996-09-21 08:11:22 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1996-09-21 08:11:22 +0000 |
commit | 2d23099e2834c53ac895341a401052bb28eccf72 (patch) | |
tree | 5dc562620edf39021f6fc2bf6abcc2f8eac9275a /sbin | |
parent | 52fe065ab87c1d0e777313a6b95ded2f14763119 (diff) | |
download | FreeBSD-src-2d23099e2834c53ac895341a401052bb28eccf72.zip FreeBSD-src-2d23099e2834c53ac895341a401052bb28eccf72.tar.gz |
Who would have though that dmesg didn't understand message buffers?
Fixed the following bugs:
- the buffer was reprinted endlessly when msg.bufx == 0 and (for a
different reason) when msg.bufx == 1.
- the last byte of the buffer wasn't printed except in the the infinite
loop cases.
- the comment about walking the buffer didn't match the (correct) code.
- minor -Wall and style bugs.
Not fixed:
- excessive newline processing which hid the non-printing of the last
byte of the buffer.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dmesg/dmesg.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/sbin/dmesg/dmesg.c b/sbin/dmesg/dmesg.c index 8cb4f69..b68a1d9 100644 --- a/sbin/dmesg/dmesg.c +++ b/sbin/dmesg/dmesg.c @@ -32,13 +32,17 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1991, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)dmesg.c 8.1 (Berkeley) 6/5/93"; +#if 0 +static const char sccsid[] = "@(#)dmesg.c 8.1 (Berkeley) 6/5/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include <sys/cdefs.h> @@ -48,13 +52,13 @@ static char sccsid[] = "@(#)dmesg.c 8.1 (Berkeley) 6/5/93"; #include <fcntl.h> #include <kvm.h> #include <limits.h> +#include <locale.h> #include <nlist.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> #include <vis.h> -#include <locale.h> struct nlist nl[] = { #define X_MSGBUF 0 @@ -119,12 +123,16 @@ main(argc, argv) cur.msg_bufx = 0; /* - * The message buffer is circular; start at the read pointer, and - * go to the write pointer - 1. + * The message buffer is circular. If the buffer has wrapped, the + * write pointer points to the oldest data. Otherwise, the write + * pointer points to \0's following the data. Read the entire + * buffer starting at the write pointer and ignore nulls so that + * we effectively start at the oldest data. */ p = cur.msg_bufc + cur.msg_bufx; - ep = cur.msg_bufc + cur.msg_bufx - 1; - for (newl = skip = 0; p != ep; ++p) { + ep = (cur.msg_bufx == 0 ? cur.msg_bufc + MSG_BSIZE : p); + newl = skip = 0; + do { if (p == cur.msg_bufc + MSG_BSIZE) p = cur.msg_bufc; ch = *p; @@ -146,7 +154,7 @@ main(argc, argv) (void)putchar(buf[0]); else (void)printf("%s", buf); - } + } while (++p != ep); if (!newl) (void)putchar('\n'); exit(0); |