From 0926c065c46643687991b626505f0bc11452a840 Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Fri, 2 Oct 2015 14:24:39 +0000 Subject: [PATCH] MFC r281787 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) Sponsored by: Dell Inc. --- sbin/dmesg/dmesg.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sbin/dmesg/dmesg.c b/sbin/dmesg/dmesg.c index f0fcb8125877..75b926c0f1f9 100644 --- a/sbin/dmesg/dmesg.c +++ b/sbin/dmesg/dmesg.c @@ -116,6 +116,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)