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 And then reboot. Index: lib/libc/gen/syslog.c =================================================================== RCS file: /cvs/src/lib/libc/gen/syslog.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- lib/libc/gen/syslog.c 1998/03/19 00:30:03 1.8 +++ lib/libc/gen/syslog.c 2000/01/02 23:35:58 1.9 @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: syslog.c,v 1.8 1998/03/19 00:30:03 millert Exp $"; +static char rcsid[] = "$OpenBSD: syslog.c,v 1.9 2000/01/02 23:35:58 hugh Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -58,12 +58,15 @@ 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 */ +} -void -openlog(ident, logstat, logfac) - const char *ident; - int logstat, logfac; +static void +connectlog() { - if (ident != NULL) - LogTag = ident; - LogStat = logstat; - if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) - LogFacility = logfac; + struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */ if (LogFile == -1) { + if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) + return; + (void)fcntl(LogFile, F_SETFD, 1); + } + if (LogFile != -1 && !connected) { memset(&SyslogAddr, '\0', sizeof(SyslogAddr)); SyslogAddr.sun_len = sizeof(SyslogAddr); SyslogAddr.sun_family = AF_UNIX; (void)strncpy(SyslogAddr.sun_path, _PATH_LOG, sizeof(SyslogAddr.sun_path) - 1); SyslogAddr.sun_path[sizeof(SyslogAddr.sun_path) - 1] = '\0'; - if (LogStat & LOG_NDELAY) { - if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) - return; - (void)fcntl(LogFile, F_SETFD, 1); - } - } - if (LogFile != -1 && !connected) { if (connect(LogFile, (struct sockaddr *)&SyslogAddr, - sizeof(SyslogAddr)) == -1) { + sizeof(SyslogAddr)) == -1) { (void)close(LogFile); LogFile = -1; } else connected = 1; } +} + +void +openlog(ident, logstat, logfac) + const char *ident; + int logstat, logfac; +{ + if (ident != NULL) + LogTag = ident; + LogStat = logstat; + if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) + LogFacility = logfac; + + if (LogStat & LOG_NDELAY) /* open immediately */ + connectlog(); + + opened = 1; /* ident and facility has been set */ } void