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.
This commit is contained in:
Eric van Gyzen 2015-10-02 14:24:39 +00:00
parent f417c00d9e
commit 0926c065c4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/stable/10/; revision=288498

View File

@ -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)