Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Oct 2004 16:43:39 +0400
From:      Gleb Smirnoff <glebius@freebsd.org>
To:        current@freebsd.org
Subject:   syslog overflow fix
Message-ID:  <20041006124339.GA84583@cell.sick.ru>

next in thread | raw e-mail | index | archive | help
  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



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