diff --git a/include/proto/sink.h b/include/proto/sink.h index bab9681407..d30f30a742 100644 --- a/include/proto/sink.h +++ b/include/proto/sink.h @@ -39,8 +39,10 @@ int sink_announce_dropped(struct sink *sink, int facility, struct ist *pid); * array to sink . Formatting according to the sink's preference is * done here. Lost messages are accounted for in the sink's counter. If there * were lost messages, an attempt is first made to indicate it. + * The function returns the number of Bytes effectively sent or announced. + * or <= 0 in other cases. */ -static inline void sink_write(struct sink *sink, const struct ist msg[], size_t nmsg, +static inline ssize_t sink_write(struct sink *sink, const struct ist msg[], size_t nmsg, int level, int facility, struct ist * tag, struct ist *pid, struct ist *sd) { @@ -72,6 +74,8 @@ static inline void sink_write(struct sink *sink, const struct ist msg[], size_t fail: if (unlikely(sent <= 0)) HA_ATOMIC_ADD(&sink->ctx.dropped, 1); + + return sent; } #endif /* _PROTO_SINK_H */ diff --git a/include/types/log.h b/include/types/log.h index 868c08f01d..88c3a8c462 100644 --- a/include/types/log.h +++ b/include/types/log.h @@ -211,7 +211,7 @@ struct logsrv { struct list list; struct sockaddr_storage addr; struct smp_info lb; - struct ring *ring; + struct sink *sink; enum log_tgt type; int format; int facility; diff --git a/src/log.c b/src/log.c index 482ce4dac5..0aa043f255 100644 --- a/src/log.c +++ b/src/log.c @@ -1048,7 +1048,7 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err) logsrv->addr.ss_family = AF_UNSPEC; logsrv->type = LOG_TARGET_BUFFER; - logsrv->ring = sink->ctx.ring; + logsrv->sink = sink; goto done; } @@ -1563,7 +1563,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_ static THREAD_LOCAL int logfdinet = -1; /* syslog to AF_INET socket */ static THREAD_LOCAL char *dataptr = NULL; time_t time = date.tv_sec; - char *hdr, *hdr_ptr; + char *hdr, *hdr_ptr = NULL; size_t hdr_size; int fac_level; int *plogfd; @@ -1593,6 +1593,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_ } else if (logsrv->type == LOG_TARGET_BUFFER) { plogfd = NULL; + goto send; } else if (logsrv->addr.ss_family == AF_UNIX) plogfd = &logfdunix; @@ -1739,18 +1740,23 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_ /* the target is a file descriptor or a ring buffer */ struct ist msg[7]; - msg[0].ptr = hdr_ptr; msg[0].len = hdr_max; - msg[1].ptr = tag_str; msg[1].len = tag_max; - msg[2].ptr = pid_sep1; msg[2].len = pid_sep1_max; - msg[3].ptr = pid_str; msg[3].len = pid_max; - msg[4].ptr = pid_sep2; msg[4].len = pid_sep2_max; - msg[5].ptr = sd; msg[5].len = sd_max; - msg[6].ptr = dataptr; msg[6].len = max; - - if (logsrv->type == LOG_TARGET_BUFFER) - sent = ring_write(logsrv->ring, ~0, NULL, 0, msg, 7); - else /* LOG_TARGET_FD */ + if (logsrv->type == LOG_TARGET_BUFFER) { + msg[0] = ist2(message, MIN(size, logsrv->maxlen)); + msg[1] = ist2(tag_str, tag_size); + msg[2] = ist2(pid_str, pid_size); + msg[3] = ist2(sd, sd_size); + sent = sink_write(logsrv->sink, msg, 1, level, logsrv->facility, &msg[1], &msg[2], &msg[3]); + } + else /* LOG_TARGET_FD */ { + msg[0] = ist2(hdr_ptr, hdr_max); + msg[1] = ist2(tag_str, tag_max); + msg[2] = ist2(pid_sep1, pid_sep1_max); + msg[3] = ist2(pid_str, pid_max); + msg[4] = ist2(pid_sep2, pid_sep2_max); + msg[5] = ist2(sd, sd_max); + msg[6] = ist2(dataptr, max); sent = fd_write_frag_line(*plogfd, ~0, NULL, 0, msg, 7, 1); + } } else { iovec[0].iov_base = hdr_ptr;