summaryrefslogtreecommitdiffstats
path: root/sbin/dmesg
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
committersjg <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
commit65145fa4c81da358fcbc3b650156dab705dfa34e (patch)
tree55c065b6730aaac2afb6c29933ee6ec5fa4c4249 /sbin/dmesg
parent60ff4eb0dff94a04d75d0d52a3957aaaf5f8c693 (diff)
parente6b664c390af88d4a87208bc042ce503da664c3b (diff)
downloadFreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.zip
FreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.tar.gz
Merge sync of head
Diffstat (limited to 'sbin/dmesg')
-rw-r--r--sbin/dmesg/Makefile3
-rw-r--r--sbin/dmesg/dmesg.c11
2 files changed, 10 insertions, 4 deletions
diff --git a/sbin/dmesg/Makefile b/sbin/dmesg/Makefile
index 266551b..64a0155 100644
--- a/sbin/dmesg/Makefile
+++ b/sbin/dmesg/Makefile
@@ -4,7 +4,6 @@
PROG= dmesg
MAN= dmesg.8
-LDADD= -lkvm
-DPADD= ${LIBKVM}
+LIBADD= kvm
.include <bsd.prog.mk>
diff --git a/sbin/dmesg/dmesg.c b/sbin/dmesg/dmesg.c
index f0fcb81..827ed8e 100644
--- a/sbin/dmesg/dmesg.c
+++ b/sbin/dmesg/dmesg.c
@@ -111,15 +111,22 @@ main(int argc, char *argv[])
if (memf == NULL) {
/*
- * Running kernel. Use sysctl. This gives an unwrapped
- * buffer as a side effect.
+ * Running kernel. Use sysctl. This gives an unwrapped buffer
+ * as a side effect. Remove nulterm (if present) so the value
+ * returned by sysctl is formatted as the rest of the code
+ * expects (the same as the value read from a core file below).
*/
if (sysctlbyname("kern.msgbuf", NULL, &buflen, NULL, 0) == -1)
err(1, "sysctl kern.msgbuf");
+ /* Allocate extra room for growth between the sysctl calls. */
+ buflen += buflen/8;
+ /* Allocate more than sysctl sees, for room to append \n\0. */
if ((bp = malloc(buflen + 2)) == NULL)
errx(1, "malloc failed");
if (sysctlbyname("kern.msgbuf", bp, &buflen, NULL, 0) == -1)
err(1, "sysctl kern.msgbuf");
+ if (buflen > 0 && bp[buflen - 1] == '\0')
+ buflen--;
if (clear)
if (sysctlbyname("kern.msgbuf_clear", NULL, NULL, &clear, sizeof(int)))
err(1, "sysctl kern.msgbuf_clear");
OpenPOWER on IntegriCloud