]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: stop emitting alerts when it's not possible to write on the socket
authorWilly Tarreau <w@1wt.eu>
Tue, 20 Mar 2018 10:17:29 +0000 (11:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 20 Mar 2018 15:44:25 +0000 (16:44 +0100)
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

index de775af45b4502c4278b8a85c94a837ff646c045..e2dde84f08f87393bd83d1c72cc606a9ec70410d 100644 (file)
--- 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 @@ send:
                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);
+                       }
                }
        }
 }