mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-23 13:17:16 +00:00
MEDIUM: logs: buffer targets now rely on new sink_write
Before this path, they rely directly on ring_write bypassing a part of the sink API. Now the maxlen parameter of the log will apply only on the text message part (and not the header, for this you woud prefer to use the maxlen parameter on the sink/ring). sink_write prototype was also reviewed to return the number of Bytes written to be compliant with the other write functions.
This commit is contained in:
parent
bd163817ed
commit
e709e1e777
@ -39,8 +39,10 @@ int sink_announce_dropped(struct sink *sink, int facility, struct ist *pid);
|
|||||||
* array <msg> to sink <sink>. Formatting according to the sink's preference is
|
* array <msg> to sink <sink>. Formatting according to the sink's preference is
|
||||||
* done here. Lost messages are accounted for in the sink's counter. If there
|
* 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.
|
* 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,
|
int level, int facility, struct ist * tag,
|
||||||
struct ist *pid, struct ist *sd)
|
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:
|
fail:
|
||||||
if (unlikely(sent <= 0))
|
if (unlikely(sent <= 0))
|
||||||
HA_ATOMIC_ADD(&sink->ctx.dropped, 1);
|
HA_ATOMIC_ADD(&sink->ctx.dropped, 1);
|
||||||
|
|
||||||
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _PROTO_SINK_H */
|
#endif /* _PROTO_SINK_H */
|
||||||
|
@ -211,7 +211,7 @@ struct logsrv {
|
|||||||
struct list list;
|
struct list list;
|
||||||
struct sockaddr_storage addr;
|
struct sockaddr_storage addr;
|
||||||
struct smp_info lb;
|
struct smp_info lb;
|
||||||
struct ring *ring;
|
struct sink *sink;
|
||||||
enum log_tgt type;
|
enum log_tgt type;
|
||||||
int format;
|
int format;
|
||||||
int facility;
|
int facility;
|
||||||
|
32
src/log.c
32
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->addr.ss_family = AF_UNSPEC;
|
||||||
logsrv->type = LOG_TARGET_BUFFER;
|
logsrv->type = LOG_TARGET_BUFFER;
|
||||||
logsrv->ring = sink->ctx.ring;
|
logsrv->sink = sink;
|
||||||
goto done;
|
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 int logfdinet = -1; /* syslog to AF_INET socket */
|
||||||
static THREAD_LOCAL char *dataptr = NULL;
|
static THREAD_LOCAL char *dataptr = NULL;
|
||||||
time_t time = date.tv_sec;
|
time_t time = date.tv_sec;
|
||||||
char *hdr, *hdr_ptr;
|
char *hdr, *hdr_ptr = NULL;
|
||||||
size_t hdr_size;
|
size_t hdr_size;
|
||||||
int fac_level;
|
int fac_level;
|
||||||
int *plogfd;
|
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) {
|
else if (logsrv->type == LOG_TARGET_BUFFER) {
|
||||||
plogfd = NULL;
|
plogfd = NULL;
|
||||||
|
goto send;
|
||||||
}
|
}
|
||||||
else if (logsrv->addr.ss_family == AF_UNIX)
|
else if (logsrv->addr.ss_family == AF_UNIX)
|
||||||
plogfd = &logfdunix;
|
plogfd = &logfdunix;
|
||||||
@ -1739,19 +1740,24 @@ send:
|
|||||||
/* the target is a file descriptor or a ring buffer */
|
/* the target is a file descriptor or a ring buffer */
|
||||||
struct ist msg[7];
|
struct ist msg[7];
|
||||||
|
|
||||||
msg[0].ptr = hdr_ptr; msg[0].len = hdr_max;
|
if (logsrv->type == LOG_TARGET_BUFFER) {
|
||||||
msg[1].ptr = tag_str; msg[1].len = tag_max;
|
msg[0] = ist2(message, MIN(size, logsrv->maxlen));
|
||||||
msg[2].ptr = pid_sep1; msg[2].len = pid_sep1_max;
|
msg[1] = ist2(tag_str, tag_size);
|
||||||
msg[3].ptr = pid_str; msg[3].len = pid_max;
|
msg[2] = ist2(pid_str, pid_size);
|
||||||
msg[4].ptr = pid_sep2; msg[4].len = pid_sep2_max;
|
msg[3] = ist2(sd, sd_size);
|
||||||
msg[5].ptr = sd; msg[5].len = sd_max;
|
sent = sink_write(logsrv->sink, msg, 1, level, logsrv->facility, &msg[1], &msg[2], &msg[3]);
|
||||||
msg[6].ptr = dataptr; msg[6].len = max;
|
}
|
||||||
|
else /* LOG_TARGET_FD */ {
|
||||||
if (logsrv->type == LOG_TARGET_BUFFER)
|
msg[0] = ist2(hdr_ptr, hdr_max);
|
||||||
sent = ring_write(logsrv->ring, ~0, NULL, 0, msg, 7);
|
msg[1] = ist2(tag_str, tag_max);
|
||||||
else /* LOG_TARGET_FD */
|
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);
|
sent = fd_write_frag_line(*plogfd, ~0, NULL, 0, msg, 7, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
iovec[0].iov_base = hdr_ptr;
|
iovec[0].iov_base = hdr_ptr;
|
||||||
iovec[0].iov_len = hdr_max;
|
iovec[0].iov_len = hdr_max;
|
||||||
|
Loading…
Reference in New Issue
Block a user