Author: vangyzen
Date: Fri Oct  2 15:07:02 2015
New Revision: 288500
URL: https://svnweb.freebsd.org/changeset/base/288500

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_w...@dell.com> (and tested)
  Approved by:    kib (mentor until recently)
  Obtained from:  Dell Inc.

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

Modified: stable/9/sbin/dmesg/dmesg.c
==============================================================================
--- stable/9/sbin/dmesg/dmesg.c Fri Oct  2 14:36:41 2015        (r288499)
+++ stable/9/sbin/dmesg/dmesg.c Fri Oct  2 15:07:02 2015        (r288500)
@@ -112,6 +112,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)
_______________________________________________
svn-src-stable-9@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "svn-src-stable-9-unsubscr...@freebsd.org"

Reply via email to