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.
This commit is contained in:
Dragan Dosen 2015-09-16 18:25:42 +02:00 committed by Willy Tarreau
parent 834cb2e445
commit 609ac2ab6c
3 changed files with 15 additions and 5 deletions

View 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

View File

@ -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);
}
}

View 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