From owner-freebsd-current@FreeBSD.ORG Wed Oct 6 12:43:43 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3E88416A4CE for ; Wed, 6 Oct 2004 12:43:43 +0000 (GMT) Received: from cell.sick.ru (cell.sick.ru [217.72.144.68]) by mx1.FreeBSD.org (Postfix) with ESMTP id 71C6843D1D for ; Wed, 6 Oct 2004 12:43:42 +0000 (GMT) (envelope-from glebius@freebsd.org) Received: from cell.sick.ru (glebius@localhost [127.0.0.1]) by cell.sick.ru (8.12.11/8.12.8) with ESMTP id i96Chd9Z084865 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 6 Oct 2004 16:43:40 +0400 (MSD) (envelope-from glebius@freebsd.org) Received: (from glebius@localhost) by cell.sick.ru (8.12.11/8.12.11/Submit) id i96Chdg4084864 for current@freebsd.org; Wed, 6 Oct 2004 16:43:39 +0400 (MSD) (envelope-from glebius@freebsd.org) X-Authentication-Warning: cell.sick.ru: glebius set sender to glebius@freebsd.org using -f Date: Wed, 6 Oct 2004 16:43:39 +0400 From: Gleb Smirnoff To: current@freebsd.org Message-ID: <20041006124339.GA84583@cell.sick.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline User-Agent: Mutt/1.5.6i Subject: syslog overflow fix X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Oct 2004 12:43:43 -0000 Dear collegues, do you have any objections for merging syslog overflow fix from OpenBSD? The patch I'm going to commit is at end of this message. Problem description and PoC can be found in bin/72366. Index: syslog.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/syslog.c,v retrieving revision 1.30 diff -u -r1.30 syslog.c --- syslog.c 10 May 2004 17:12:52 -0000 1.30 +++ syslog.c 6 Oct 2004 12:32:05 -0000 @@ -243,17 +243,27 @@ if (!opened) openlog(LogTag, LogStat | LOG_NDELAY, 0); connectlog(); - if (send(LogFile, tbuf, cnt, 0) >= 0) - return; /* - * If the send() failed, the odds are syslogd was restarted. - * Make one (only) attempt to reconnect to /dev/log. + * If the send() failed, there are two likely scenarios: + * 1) syslogd was restarted + * 2) /var/run/log is out of socket buffer space + * We attempt to reconnect to /var/run/log to take care of + * case #1 and keep send()ing data to cover case #2 + * to give syslogd a chance to empty its socket buffer. */ - disconnectlog(); - connectlog(); - if (send(LogFile, tbuf, cnt, 0) >= 0) - return; + + if (send(LogFile, tbuf, cnt, 0) < 0) { + if (errno != ENOBUFS) { + disconnectlog(); + connectlog(); + } + do { + usleep(1); + if (send(LogFile, tbuf, cnt, 0) >= 0) + break; + } while (errno == ENOBUFS); + } /* * Output the message to the console; try not to block -- Totus tuus, Glebius. GLEBIUS-RIPN GLEB-RIPE