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
This commit is contained in:
Christopher Faulet 2018-03-26 16:09:19 +02:00 committed by Willy Tarreau
parent 4b0b79dd56
commit 28ac099907
3 changed files with 14 additions and 1 deletions

View File

@ -175,6 +175,7 @@ struct logsrv {
int level;
int minlvl;
int maxlen;
struct logsrv *ref;
};
#endif /* _TYPES_LOG_H */

View File

@ -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);
}

View File

@ -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;
}