summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorvangyzen <vangyzen@FreeBSD.org>2015-04-20 20:07:39 +0000
committervangyzen <vangyzen@FreeBSD.org>2015-04-20 20:07:39 +0000
commit4ab93ad1b7171b7bf6de5b317c332afd9c6a6e7d (patch)
tree9e3ae83415731baa9afba795b5a9aabd3c5a8543 /sbin
parent807ec5634253b1ad323addaa8913ac4a805c185e (diff)
downloadFreeBSD-src-4ab93ad1b7171b7bf6de5b317c332afd9c6a6e7d.zip
FreeBSD-src-4ab93ad1b7171b7bf6de5b317c332afd9c6a6e7d.tar.gz
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 <steve_wahl@dell.com> (and tested) Approved by: kib (mentor) Obtained from: Dell Inc. MFC after: 1 week
Diffstat (limited to 'sbin')
-rw-r--r--sbin/dmesg/dmesg.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/sbin/dmesg/dmesg.c b/sbin/dmesg/dmesg.c
index 9fee416..827ed8e 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)
OpenPOWER on IntegriCloud