dmesg - Don't fail when the kernel is adding to the dmesg quickly
authorMatthew Dillon <dillon@apollo.backplane.com>
Tue, 29 Nov 2011 21:41:54 +0000 (13:41 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 29 Nov 2011 21:41:54 +0000 (13:41 -0800)
* If the kernel is quickly adding to the dmesg buffer and has not started
  recycling the FIFO the increasing size of the buffer will exceed the
  probed size.

* Add another 4K to the probed size to try to deal with this case.

sbin/dmesg/dmesg.c

index 09da87f..93e7cf5 100644 (file)
@@ -98,6 +98,7 @@ main(int argc, char **argv)
                /* Running kernel. Use sysctl. */
                if (sysctlbyname("kern.msgbuf", NULL, &buflen, NULL, 0) == -1)
                        err(1, "sysctl kern.msgbuf");
+               buflen += 4096;         /* add some slop */
                if ((bp = malloc(buflen)) == NULL)
                        errx(1, "malloc failed");
                if (sysctlbyname("kern.msgbuf", bp, &buflen, NULL, 0) == -1)