svn commit: r288498 - stable/10/sbin/dmesg

Eric van Gyzen vangyzen at FreeBSD.org
Fri Oct 2 14:24:40 UTC 2015


Author: vangyzen
Date: Fri Oct  2 14:24:39 2015
New Revision: 288498
URL: https://svnweb.freebsd.org/changeset/base/288498

Log:
  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 at dell.com> (and tested)
  Sponsored by:   Dell Inc.

Modified:
  stable/10/sbin/dmesg/dmesg.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sbin/dmesg/dmesg.c
==============================================================================
--- stable/10/sbin/dmesg/dmesg.c	Fri Oct  2 14:21:07 2015	(r288497)
+++ stable/10/sbin/dmesg/dmesg.c	Fri Oct  2 14:24:39 2015	(r288498)
@@ -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)


More information about the svn-src-all mailing list