summaryrefslogtreecommitdiffstats
path: root/sbin/dmesg
diff options
context:
space:
mode:
authorvangyzen <vangyzen@FreeBSD.org>2015-10-02 14:24:39 +0000
committervangyzen <vangyzen@FreeBSD.org>2015-10-02 14:24:39 +0000
commit7b3b15b30002adb4bfb1e6836e4a76225fff3d6f (patch)
tree06532d6f64f703c508bde76e80e395cce093ca89 /sbin/dmesg
parent65381bf93d359744f5273394ccc73cf9fe5b55d8 (diff)
downloadFreeBSD-src-7b3b15b30002adb4bfb1e6836e4a76225fff3d6f.zip
FreeBSD-src-7b3b15b30002adb4bfb1e6836e4a76225fff3d6f.tar.gz
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 <steve_wahl@dell.com> (and tested) Sponsored by: Dell Inc.
Diffstat (limited to 'sbin/dmesg')
-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 f0fcb81..75b926c 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)
OpenPOWER on IntegriCloud