From 609ac2ab6cfbe42303c0db0721f6287021173f21 Mon Sep 17 00:00:00 2001 From: Dragan Dosen Date: Wed, 16 Sep 2015 18:25:42 +0200 Subject: [PATCH] MEDIUM: log: replace sendto() with sendmsg() in __send_log() This patch replaces sendto() with sendmsg() in __send_log() and makes use of an iovec to send the log message. --- include/types/log.h | 1 + src/log.c | 17 +++++++++++++---- tests/test-log.cfg | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/types/log.h b/include/types/log.h index d0fb966828..f6f6e99a62 100644 --- a/include/types/log.h +++ b/include/types/log.h @@ -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 diff --git a/src/log.c b/src/log.c index ef7005aede..8a7e5f4823 100644 --- 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); } } diff --git a/tests/test-log.cfg b/tests/test-log.cfg index a8d971c078..ce916037b1 100644 --- a/tests/test-log.cfg +++ b/tests/test-log.cfg @@ -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 -- 2.39.5