From 28ac0999076c249375d8ff46229cad40ac38b387 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 26 Mar 2018 16:09:19 +0200 Subject: [PATCH] MINOR: log: Keep the ref when a log server is copied to avoid duplicate entries With "log global" line, the global list of loggers are copied into the proxy's struct. The list coming from the default section is also copied when a frontend or a backend section is parsed. So it is possible to have duplicate entries in the proxy's list. For instance, with this following config, all messages will be logged twice: global log 127.0.0.1 local0 debug daemon defaults mode http log global option httplog frontend front-http log global bind *:8888 default_backend back-http backend back-http server www 127.0.0.1:8000 --- include/types/log.h | 1 + src/cfgparse.c | 1 + src/log.c | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/types/log.h b/include/types/log.h index 0fdb775771..c394d77345 100644 --- a/include/types/log.h +++ b/include/types/log.h @@ -175,6 +175,7 @@ struct logsrv { int level; int minlvl; int maxlen; + struct logsrv *ref; }; #endif /* _TYPES_LOG_H */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 6100f86ac3..37bbf45313 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2836,6 +2836,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) { struct logsrv *node = malloc(sizeof(*node)); memcpy(node, tmplogsrv, sizeof(struct logsrv)); + node->ref = tmplogsrv->ref; LIST_INIT(&node->list); LIST_ADDQ(&curproxy->logsrvs, &node->list); } diff --git a/src/log.c b/src/log.c index 1be6dccee3..b2d4367f4d 100644 --- a/src/log.c +++ b/src/log.c @@ -720,10 +720,21 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err) goto error; } list_for_each_entry(logsrv, &global.logsrvs, list) { - struct logsrv *node = malloc(sizeof(*node)); + struct logsrv *node; + + list_for_each_entry(node, logsrvs, list) { + if (node->ref == logsrv) + goto skip_logsrv; + } + + node = malloc(sizeof(*node)); memcpy(node, logsrv, sizeof(struct logsrv)); + node->ref = logsrv; LIST_INIT(&node->list); LIST_ADDQ(logsrvs, &node->list); + + skip_logsrv: + continue; } return 1; } -- 2.39.5