]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: logs: pass the trailing "\n" as an iovec
authorDragan Dosen <ddosen@haproxy.com>
Mon, 28 Sep 2015 14:01:03 +0000 (16:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Sep 2015 16:31:09 +0000 (18:31 +0200)
This patch passes the trailing "\n" as an iovec in the function
__send_log(), so that we don't need to modify the original log message.

include/types/log.h
src/log.c

index 6a68b5dbeb55d57c986ec1f0197e154f9a5282f0..411ba8ffa9f68f0034d437d6d845c213cd693c53 100644 (file)
@@ -30,7 +30,7 @@
 
 #define NB_LOG_FACILITIES       24
 #define NB_LOG_LEVELS           8
-#define NB_MSG_IOVEC_ELEMENTS   4
+#define NB_MSG_IOVEC_ELEMENTS   5
 #define SYSLOG_PORT             514
 #define UNIQUEID_LEN            128
 
index 18a2006f97900a60a33d74fbde2ccbab1439e617..19aac114b447c6e77dbcde75ded0013da89ee366 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -922,7 +922,6 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd
        struct list *logsrvs = NULL;
        struct logsrv *tmp = NULL;
        int nblogger;
-       char *log_ptr;
        char *hdr, *hdr_ptr;
        size_t hdr_size;
        struct chunk *htp;
@@ -954,8 +953,7 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd
                int hdr_max = 0;
                int htp_max = 0;
                int sd_max = 0;
-               int max = 1;
-               char backup;
+               int max = 0;
 
                nblogger++;
 
@@ -1014,8 +1012,6 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd
                } while (fac_level && hdr_ptr > hdr);
                *hdr_ptr = '<';
 
-               log_ptr = dataptr;
-
                hdr_max = hdr_size - (hdr_ptr - hdr);
 
                if (unlikely(hdr_size >= logsrv->maxlen)) {
@@ -1040,16 +1036,8 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd
                        goto send;
                }
 
-               max = MIN(size, maxlen - sd_max);
-               log_ptr += max - 1;
+               max = MIN(size, maxlen - sd_max) - 1;
 send:
-               /* insert a \n at the end of the message, but save what was
-                * there first because we could have different max lengths
-                * for different log targets.
-                */
-               backup = *log_ptr;
-               *log_ptr = '\n';
-
                iovec[0].iov_base = hdr_ptr;
                iovec[0].iov_len = hdr_max;
                iovec[1].iov_base = htp->str;
@@ -1058,14 +1046,14 @@ send:
                iovec[2].iov_len = sd_max;
                iovec[3].iov_base = dataptr;
                iovec[3].iov_len = max;
+               iovec[4].iov_base = "\n"; /* insert a \n at the end of the message */
+               iovec[4].iov_len = 1;
 
                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 = backup;
-
                if (sent < 0) {
                        Alert("sendmsg logger #%d failed: %s (errno=%d)\n",
                                nblogger, strerror(errno), errno);