|
Message-ID: <20150705171817.GT1173@brightrain.aerifal.cx> Date: Sun, 5 Jul 2015 13:18:17 -0400 From: Rich Felker <dalias@...c.org> To: musl@...ts.openwall.com Subject: Re: [PATCH] close syslog socket on error to recreate it later 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 > --- > src/misc/syslog.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/src/misc/syslog.c b/src/misc/syslog.c > index e026f9b..c329956 100644 > --- a/src/misc/syslog.c > +++ b/src/misc/syslog.c > @@ -107,11 +107,15 @@ 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)) { > - fd = open("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC); > - if (fd >= 0) { > - dprintf(fd, "%.*s", l-hlen, buf+hlen); > - close(fd); > + if (send(log_fd, buf, l, 0) < 0) { > + close(log_fd); > + log_fd = -1; > + if (log_opt & LOG_CONS)) { > + fd = open("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC); > + if (fd >= 0) { > + dprintf(fd, "%.*s", l-hlen, buf+hlen); > + close(fd); > + } This may be okay, but are there possibly errors which are transient and do not indicate a broken connection? EINTR comes to mind. I wonder if the close logic should be default on any error but known-transient ones (EINTR only?) or if it should only be done on EPIPE or whatever error we get when the other end of the socket was closed. Rich
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.