From owner-svn-src-head@FreeBSD.ORG Wed Nov 13 01:01:15 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CEBF6496; Wed, 13 Nov 2013 01:01:15 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BE42F25F0; Wed, 13 Nov 2013 01:01:15 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rAD11Fbs085875; Wed, 13 Nov 2013 01:01:15 GMT (envelope-from ian@svn.freebsd.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id rAD11Fle085874; Wed, 13 Nov 2013 01:01:15 GMT (envelope-from ian@svn.freebsd.org) Message-Id: <201311130101.rAD11Fle085874@svn.freebsd.org> From: Ian Lepore Date: Wed, 13 Nov 2013 01:01:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r258076 - head/usr.sbin/syslogd X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Nov 2013 01:01:16 -0000 Author: ian Date: Wed Nov 13 01:01:15 2013 New Revision: 258076 URL: http://svnweb.freebsd.org/changeset/base/258076 Log: This fixes 3 problems in syslogd related to sizing receive buffers... - A call was misplaced at the wrong level of nested if blocks, so that the buffers for unix domain sockets (/dev/log, /dev/klog) were never increased at all; they remained at a way-too-small default size of 4096. - The function that was supposed to double the size of the buffer sometimes did nothing, and sometimes installed a wildly-wrong buffer size (either too large or too small) due to an unitialized 'slen' variable passed to getsockopt(). Most often it doubled the UDP buffers from 40k to 80k because accidentally there would be harmless stack garbage in the unitialized variables. - The whole concept of blindly doubling a socket's buffer size without knowing what size it started at is a design flaw that has to be called a bug. If the double_rbuf() function had worked at all (I.E., if the other two bugs didn't exist) this would lead to UDP sockets having an 80k buffer while unix dgram sockets get an 8k buffer. There's nothing about the problem being solved that requires larger buffers for UDP than for unix dgram sockets -- the buffering requirements are the same regardless of socket type. This change renames the double_rbuf() function to increase_rbuf() and increases the buffer size on all types of sockets to 80k. 80k was chosen only because it appears to be the size the original change was shooting for, and it certainly seems to be reasonably large (I might have picked 64k in the absence of any historical guidance). PR: 160433 Submitted by: me, in 2011. Modified: head/usr.sbin/syslogd/syslogd.c Modified: head/usr.sbin/syslogd/syslogd.c ============================================================================== --- head/usr.sbin/syslogd/syslogd.c Tue Nov 12 22:51:03 2013 (r258075) +++ head/usr.sbin/syslogd/syslogd.c Wed Nov 13 01:01:15 2013 (r258076) @@ -74,6 +74,7 @@ __FBSDID("$FreeBSD$"); #define DEFSPRI (LOG_KERN|LOG_CRIT) #define TIMERINTVL 30 /* interval for checking flush, mark */ #define TTYMSGTIME 1 /* timeout passed to ttymsg */ +#define RCVBUF_MINSIZE (80 * 1024) /* minimum size of dgram rcv buffer */ #include #include @@ -336,7 +337,7 @@ static void unmapped(struct sockaddr *); static void wallmsg(struct filed *, struct iovec *, const int iovlen); static int waitdaemon(int, int, int); static void timedout(int); -static void double_rbuf(int); +static void increase_rcvbuf(int); int main(int argc, char *argv[]) @@ -547,8 +548,8 @@ main(int argc, char *argv[]) STAILQ_REMOVE(&funixes, fx, funix, next); continue; } - double_rbuf(fx->s); } + increase_rcvbuf(fx->s); } if (SecureMode <= 1) finet = socksetup(family, bindhostname); @@ -2720,7 +2721,7 @@ socksetup(int af, char *bindhostname) } if (!SecureMode) - double_rbuf(*s); + increase_rcvbuf(*s); } (*socks)++; @@ -2741,12 +2742,16 @@ socksetup(int af, char *bindhostname) } static void -double_rbuf(int fd) +increase_rcvbuf(int fd) { - socklen_t slen, len; + socklen_t len, slen; + + slen = sizeof(len); if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &len, &slen) == 0) { - len *= 2; - setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &len, slen); + if (len < RCVBUF_MINSIZE) { + len = RCVBUF_MINSIZE; + setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &len, sizeof(len)); + } } }