|
Date: Tue, 7 Jul 2015 08:14:52 +0300 From: Timo Teras <timo.teras@....fi> To: Rich Felker <dalias@...c.org> Cc: musl@...ts.openwall.com Subject: Re: [PATCH] close syslog socket on error to recreate it later On Mon, 6 Jul 2015 19:21:38 -0400 Rich Felker <dalias@...c.org> wrote: > On Sat, Jul 04, 2015 at 07:58:04PM +0300, Timo Teräs wrote: > > if syslogd is restarted, the socket is left in unconnected state > > and all logging will cease > > Here's a simple version with reopening, IMO simpler than the one you > gave on IRC. Adding checks for errno value would be easy if we want to > retry only on certain error(s). Nice. > @@ -107,7 +115,9 @@ static void _vsyslog(int priority, const char *message, va_list ap) > if (l2 >= sizeof buf - l) l = sizeof buf - 1; > else l += l2; > if (buf[l-1] != '\n') buf[l++] = '\n'; > - if (send(log_fd, buf, l, 0) < 0 && (log_opt & LOG_CONS)) { > + if (send(log_fd, buf, l, 0) < 0 > + && (__reopenlog() < 0 || send(log_fd, buf, l, 0) < 0) > + && (log_opt & LOG_CONS)) { > fd = open("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC); > if (fd >= 0) { > dprintf(fd, "%.*s", l-hlen, buf+hlen); The only minor functional difference is that log_fd is left open in case the second send() attempt fails. This probably is not significant, as a retry is done always. /Timo
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.