# # Description: reconnects to log socket if a write fails with # ECONNREFUSED or ENOTCONN -- similar to reopen # in syslog routines provided by glibc. # Happens if the log socket (provided by syslog # daemon) has been reopened. Can be triggered by # "rcsyslog reload" while syslog-ng is used. # See also Bugzilla Bug #27971. # # Author: mt@suse.de # --- syslog.c +++ syslog.c 2003/08/26 11:34:34 @@ -102,7 +102,7 @@ register int cnt; register char *p; time_t now; - int fd, saved_errno; + int fd, saved_errno, rc; char tbuf[2048], fmt_cpy[1024], *stdp = (char *) 0; saved_errno = errno; @@ -172,7 +172,16 @@ } /* output the message to the local logger */ - if (write(LogFile, tbuf, cnt + 1) >= 0 || !(LogStat&LOG_CONS)) + rc = write(LogFile, tbuf, cnt + 1); + if(rc == -1 && connected && (ECONNREFUSED == errno || + ENOTCONN == errno)) { + /* try to reopen and write again */ + closelog(); + openlog(LogTag, LogStat | LOG_NDELAY, LogFacility); + if(connected) + rc = write(LogFile, tbuf, cnt + 1); + } + if(rc >= 0 || !(LogStat&LOG_CONS)) return; /*