From c98aebcdb8f1d21a1a3501bab91e1d702171395e Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 20 Mar 2018 11:17:29 +0100 Subject: [PATCH] MINOR: log: stop emitting alerts when it's not possible to write on the socket This is a recurring pain when using certain unix domain sockets or when sending to temporarily unroutable addresses, if the process remains in the foreground, the console is full of error which it's impossible to do anything about. It's even worse when the process is remote, or when run from a serial console which will slow the whole process down. Let's send them only once now to warn about a possible config issue, and not pollute the system nor slow everything down. --- src/log.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/log.c b/src/log.c index de775af45b..e2dde84f08 100644 --- a/src/log.c +++ b/src/log.c @@ -1168,8 +1168,13 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd int proto = logsrv->addr.ss_family == AF_UNIX ? 0 : IPPROTO_UDP; if ((*plogfd = socket(logsrv->addr.ss_family, SOCK_DGRAM, proto)) < 0) { - ha_alert("socket for logger #%d failed: %s (errno=%d)\n", - nblogger, strerror(errno), errno); + static char once; + + if (!once) { + once = 1; /* note: no need for atomic ops here */ + ha_alert("socket for logger #%d failed: %s (errno=%d)\n", + nblogger, strerror(errno), errno); + } continue; } /* we don't want to receive anything on this socket */ @@ -1297,8 +1302,13 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd sent = sendmsg(*plogfd, &msghdr, MSG_DONTWAIT | MSG_NOSIGNAL); if (sent < 0) { - ha_alert("sendmsg logger #%d failed: %s (errno=%d)\n", - nblogger, strerror(errno), errno); + static char once; + + if (!once) { + once = 1; /* note: no need for atomic ops here */ + ha_alert("sendmsg logger #%d failed: %s (errno=%d)\n", + nblogger, strerror(errno), errno); + } } } }