Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Apr 2015 20:07:39 +0000 (UTC)
From:      Eric van Gyzen <vangyzen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r281787 - head/sbin/dmesg
Message-ID:  <201504202007.t3KK7dtj000379@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: vangyzen
Date: Mon Apr 20 20:07:39 2015
New Revision: 281787
URL: https://svnweb.freebsd.org/changeset/base/281787

Log:
  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

Modified:
  head/sbin/dmesg/dmesg.c

Modified: head/sbin/dmesg/dmesg.c
==============================================================================
--- head/sbin/dmesg/dmesg.c	Mon Apr 20 20:06:25 2015	(r281786)
+++ head/sbin/dmesg/dmesg.c	Mon Apr 20 20:07:39 2015	(r281787)
@@ -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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504202007.t3KK7dtj000379>