]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: log: replace sendto() with sendmsg() in __send_log()
authorDragan Dosen <ddosen@haproxy.com>
Wed, 16 Sep 2015 16:25:42 +0000 (18:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Sep 2015 12:01:27 +0000 (14:01 +0200)
This patch replaces sendto() with sendmsg() in __send_log() and makes use
of an iovec to send the log message.

include/types/log.h
src/log.c
tests/test-log.cfg

index d0fb966828ccc31743e1bac9c2cdeeecfdb22b1c..f6f6e99a62a656a3e0d84877cfc494fcf8ce7437 100644 (file)
@@ -30,6 +30,7 @@
 
 #define NB_LOG_FACILITIES       24
 #define NB_LOG_LEVELS           8
+#define NB_MSG_IOVEC_ELEMENTS   1
 #define SYSLOG_PORT             514
 #define UNIQUEID_LEN            128
 
index ef7005aedeb08176c69674b0c45c24111cf8c492..8a7e5f4823b031e27daf184a40ded6124776cda2 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -807,6 +807,11 @@ void send_log(struct proxy *p, int level, const char *format, ...)
  */
 void __send_log(struct proxy *p, int level, char *message, size_t size)
 {
+       static struct iovec iovec[NB_MSG_IOVEC_ELEMENTS] = { };
+       static struct msghdr msghdr = {
+               .msg_iov = iovec,
+               .msg_iovlen = NB_MSG_IOVEC_ELEMENTS
+       };
        static int logfdunix = -1;      /* syslog to AF_UNIX socket */
        static int logfdinet = -1;      /* syslog to AF_INET socket */
        static char *dataptr = NULL;
@@ -889,14 +894,18 @@ void __send_log(struct proxy *p, int level, char *message, size_t size)
                backup = log_ptr[max - 1];
                log_ptr[max - 1] = '\n';
 
-               sent = sendto(*plogfd, log_ptr, max,
-                             MSG_DONTWAIT | MSG_NOSIGNAL,
-                             (struct sockaddr *)&logsrv->addr, get_addr_len(&logsrv->addr));
+               iovec[0].iov_base = log_ptr;
+               iovec[0].iov_len = max;
+
+               msghdr.msg_name = (struct sockaddr *)&logsrv->addr;
+               msghdr.msg_namelen = get_addr_len(&logsrv->addr);
+
+               sent = sendmsg(*plogfd, &msghdr, MSG_DONTWAIT | MSG_NOSIGNAL);
 
                log_ptr[max - 1] = backup;
 
                if (sent < 0) {
-                       Alert("sendto logger #%d failed: %s (errno=%d)\n",
+                       Alert("sendmsg logger #%d failed: %s (errno=%d)\n",
                                nblogger, strerror(errno), errno);
                }
        }
index a8d971c07818e167f35edd3b06b51dd6b90e43b0..ce916037b1e4db551b0f601be8cf61f14d278f2e 100644 (file)
@@ -1,7 +1,7 @@
 # This is a test configuration.
 # Its purpose is simply to emit logs on the loopback in order to verify
 # that the time is correct. To be used with tcpdump on lo, or with
-# "strace -s100 -esendto".
+# "strace -s100 -esendmsg".
 
 global
        log 127.0.0.1:514 local0