Improved patch by Michael Pomraning <mjp@securepipe.com> to reconnect

klogd to the logger after it went away, so messages won't get lost if
the logger is already around by trying to reopen the socket in time.
This commit is contained in:
Joey Schulze 2003-08-27 15:56:01 +00:00
parent d672afd83d
commit 795245bfaa
2 changed files with 22 additions and 4 deletions

11
CHANGES
View File

@ -1,3 +1,8 @@
Version 1.4.2
. klogd will reconnect to the logger (mostly syslogd) after it went
away.
Version 1.4.1 Version 1.4.1
. klogd will set the console log level only if `-c' is given on the . klogd will set the console log level only if `-c' is given on the
@ -31,3 +36,9 @@ Version 1.4
- Remove Unix Domain Sockets and switch to Datagram Unix Sockets - Remove Unix Domain Sockets and switch to Datagram Unix Sockets
. Several bugfixes and improvements, please refer to the .c files . Several bugfixes and improvements, please refer to the .c files
Local variables:
mode: indented-text
mode: iso-accents
fill-column: 72
End:

View File

@ -47,6 +47,9 @@ static char sccsid[] = "@(#)syslog.c 5.28 (Berkeley) 6/27/90";
* Sun Mar 11 20:23:44 CET 2001: Martin Schulze <joey@infodrom.ffis.de> * Sun Mar 11 20:23:44 CET 2001: Martin Schulze <joey@infodrom.ffis.de>
* Use SOCK_DGRAM for loggin, renables it to work. * Use SOCK_DGRAM for loggin, renables it to work.
* *
* Wed Aug 27 17:48:16 CEST 2003: Martin Schulze <joey@Infodrom.org>
* Improved patch by Michael Pomraning <mjp@securepipe.com> to
* reconnect klogd to the logger after it went away.
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -97,7 +100,8 @@ vsyslog(pri, fmt, ap)
register int cnt; register int cnt;
register char *p; register char *p;
time_t now; time_t now;
int fd, r, saved_errno; int fd, saved_errno;
int result;
char tbuf[2048], fmt_cpy[1024], *stdp = (char *) 0; char tbuf[2048], fmt_cpy[1024], *stdp = (char *) 0;
saved_errno = errno; saved_errno = errno;
@ -167,13 +171,16 @@ vsyslog(pri, fmt, ap)
} }
/* output the message to the local logger */ /* output the message to the local logger */
r = write(LogFile, tbuf, cnt + 1); result = write(LogFile, tbuf, cnt + 1);
if (r == -1 && (errno == ECONNRESET || errno == ENOTCONN)) { if (result == -1
&& (errno == ECONNRESET || errno == ENOTCONN || errno == ECONNREFUSED)) {
closelog(); closelog();
openlog(LogTag, LogStat | LOG_NDELAY, LogFacility);
result = write(LogFile, tbuf, cnt + 1);
} }
if (r >= 0 || !(LogStat&LOG_CONS)) if (result >= 0 || !(LogStat&LOG_CONS))
return; return;
/* /*