From f8ee95484e53987c3413a376e53b2e0ee61d41f9 Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Mon, 20 Apr 2015 20:07:39 +0000 Subject: [PATCH] dmesg: accommodate message buffer growth between the sysctl calls Allocate 12.5% extra space to avoid ENOMEM when the message buffer is growing steadily. Reported by: Steve Wahl (and tested) Approved by: kib (mentor) Obtained from: Dell Inc. MFC after: 1 week --- sbin/dmesg/dmesg.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sbin/dmesg/dmesg.c b/sbin/dmesg/dmesg.c index 9fee41664b30..827ed8e28c2b 100644 --- a/sbin/dmesg/dmesg.c +++ b/sbin/dmesg/dmesg.c @@ -118,6 +118,9 @@ main(int argc, char *argv[]) */ 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)