Apply by doing:
cd /usr/src
patch -p0 < 020_syslog.patch
cd lib/libc
make obj
make clean
make
cp /usr/lib/libc.so.23.1 /usr/lib/libc.so.23.1.save
make install
static int LogFile = -1; /* fd for log */
static int connected; /* have done connect */
+static int opened; /* have done openlog() */
static int LogStat = 0; /* status bits, set by openlog() */
static const char *LogTag = NULL; /* string to tag the entry with */
static int LogFacility = LOG_USER; /* default facility code */
static int LogMask = 0xff; /* mask of priorities to be logged */
extern char *__progname; /* Program name, from crt0. */
+static void disconnectlog __P((void)); /* disconnect from syslogd */
+static void connectlog __P((void)); /* (re)connect to syslogd */
/*
* syslog, vsyslog --
* print message on log file; output is intended for syslogd(8).
@@ -212,12 +215,22 @@
}
/* Get connected, output the message to the local logger. */
- if (!connected)
- openlog(LogTag, LogStat | LOG_NDELAY, 0);
+ if (!opened)
+ openlog(LogTag, LogStat, 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.
+ */
+ disconnectlog();
+ connectlog();
+ if (send(LogFile, tbuf, cnt, 0) >= 0)
+ return;
+
+ /*
* Output the message to the console; don't worry about blocking,
* if console blocks everything will. Make sure the error reported
* is the one from the syslogd failure.
@@ -236,40 +249,62 @@
}
}
-static struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */
+static void
+disconnectlog()
+{
+ /*
+ * If the user closed the FD and opened another in the same slot,
+ * that's their problem. They should close it before calling on
+ * system services.
+ */
+ if (LogFile != -1) {
+ close(LogFile);
+ LogFile = -1;
+ }
+ connected = 0; /* retry connect */
+}