mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-29 14:50:59 +01:00
MEDIUM: logs: pass the trailing "\n" as an iovec
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.
This commit is contained in:
parent
c8cfa7b4f3
commit
5b78d9b437
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#define NB_LOG_FACILITIES 24
|
#define NB_LOG_FACILITIES 24
|
||||||
#define NB_LOG_LEVELS 8
|
#define NB_LOG_LEVELS 8
|
||||||
#define NB_MSG_IOVEC_ELEMENTS 4
|
#define NB_MSG_IOVEC_ELEMENTS 5
|
||||||
#define SYSLOG_PORT 514
|
#define SYSLOG_PORT 514
|
||||||
#define UNIQUEID_LEN 128
|
#define UNIQUEID_LEN 128
|
||||||
|
|
||||||
|
|||||||
20
src/log.c
20
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 list *logsrvs = NULL;
|
||||||
struct logsrv *tmp = NULL;
|
struct logsrv *tmp = NULL;
|
||||||
int nblogger;
|
int nblogger;
|
||||||
char *log_ptr;
|
|
||||||
char *hdr, *hdr_ptr;
|
char *hdr, *hdr_ptr;
|
||||||
size_t hdr_size;
|
size_t hdr_size;
|
||||||
struct chunk *htp;
|
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 hdr_max = 0;
|
||||||
int htp_max = 0;
|
int htp_max = 0;
|
||||||
int sd_max = 0;
|
int sd_max = 0;
|
||||||
int max = 1;
|
int max = 0;
|
||||||
char backup;
|
|
||||||
|
|
||||||
nblogger++;
|
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);
|
} while (fac_level && hdr_ptr > hdr);
|
||||||
*hdr_ptr = '<';
|
*hdr_ptr = '<';
|
||||||
|
|
||||||
log_ptr = dataptr;
|
|
||||||
|
|
||||||
hdr_max = hdr_size - (hdr_ptr - hdr);
|
hdr_max = hdr_size - (hdr_ptr - hdr);
|
||||||
|
|
||||||
if (unlikely(hdr_size >= logsrv->maxlen)) {
|
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;
|
goto send;
|
||||||
}
|
}
|
||||||
|
|
||||||
max = MIN(size, maxlen - sd_max);
|
max = MIN(size, maxlen - sd_max) - 1;
|
||||||
log_ptr += max - 1;
|
|
||||||
send:
|
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_base = hdr_ptr;
|
||||||
iovec[0].iov_len = hdr_max;
|
iovec[0].iov_len = hdr_max;
|
||||||
iovec[1].iov_base = htp->str;
|
iovec[1].iov_base = htp->str;
|
||||||
@ -1058,14 +1046,14 @@ send:
|
|||||||
iovec[2].iov_len = sd_max;
|
iovec[2].iov_len = sd_max;
|
||||||
iovec[3].iov_base = dataptr;
|
iovec[3].iov_base = dataptr;
|
||||||
iovec[3].iov_len = max;
|
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_name = (struct sockaddr *)&logsrv->addr;
|
||||||
msghdr.msg_namelen = get_addr_len(&logsrv->addr);
|
msghdr.msg_namelen = get_addr_len(&logsrv->addr);
|
||||||
|
|
||||||
sent = sendmsg(*plogfd, &msghdr, MSG_DONTWAIT | MSG_NOSIGNAL);
|
sent = sendmsg(*plogfd, &msghdr, MSG_DONTWAIT | MSG_NOSIGNAL);
|
||||||
|
|
||||||
*log_ptr = backup;
|
|
||||||
|
|
||||||
if (sent < 0) {
|
if (sent < 0) {
|
||||||
Alert("sendmsg logger #%d failed: %s (errno=%d)\n",
|
Alert("sendmsg logger #%d failed: %s (errno=%d)\n",
|
||||||
nblogger, strerror(errno), errno);
|
nblogger, strerror(errno), errno);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user