From 4ed1c9585d854e0deb8a234e8103d81e1f47228c Mon Sep 17 00:00:00 2001 From: "Thierry FOURNIER / OZON.IO" Date: Thu, 24 Nov 2016 23:57:54 +0100 Subject: [PATCH] MINOR: http/conf: store the use_backend configuration file and line for logs The error log of the directive use_backend doesn't provide the file and line containing the declaration. This patch stores theses informations. --- include/types/arg.h | 1 + include/types/proxy.h | 2 ++ src/cfgparse.c | 9 +++++++++ src/haproxy.c | 1 + src/log.c | 2 ++ 5 files changed, 15 insertions(+) diff --git a/include/types/arg.h b/include/types/arg.h index 7576f8ac3f..651164b2db 100644 --- a/include/types/arg.h +++ b/include/types/arg.h @@ -77,6 +77,7 @@ enum { ARGC_CAP, /* capture rule */ ARGC_SRV, /* server line */ ARGC_SPOE, /* spoe message args */ + ARGC_UBK, /* use_backend message */ }; /* flags used when compiling and executing regex */ diff --git a/include/types/proxy.h b/include/types/proxy.h index 27aa157406..0b194cb731 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -446,6 +446,8 @@ struct switching_rule { char *name; /* target backend name during config parsing */ struct list expr; /* logformat expression to use for dynamic rules */ } be; + char *file; + int line; }; struct server_rule { diff --git a/src/cfgparse.c b/src/cfgparse.c index 40fd7da76f..db1641e98c 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -4018,6 +4018,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) } rule->cond = cond; rule->be.name = strdup(args[1]); + rule->line = linenum; + rule->file = strdup(file); + if (!rule->file) { + Alert("Out of memory error.\n"); + goto out; + } LIST_INIT(&rule->list); LIST_ADDQ(&curproxy->switching_rules, &rule->list); } @@ -7792,6 +7798,9 @@ int check_config_validity() */ pxname = rule->be.name; LIST_INIT(&rule->be.expr); + curproxy->conf.args.ctx = ARGC_UBK; + curproxy->conf.args.file = rule->file; + curproxy->conf.args.line = rule->line; if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR)) { cfgerr++; continue; diff --git a/src/haproxy.c b/src/haproxy.c index 728c8e5b4d..5d7d410bc1 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1482,6 +1482,7 @@ void deinit(void) if (rule->cond) { prune_acl_cond(rule->cond); free(rule->cond); + free(rule->file); } free(rule); } diff --git a/src/log.c b/src/log.c index 5fc68cef95..9ec89b2b35 100644 --- a/src/log.c +++ b/src/log.c @@ -269,6 +269,8 @@ static inline const char *fmt_directive(const struct proxy *curproxy) return "server"; case ARGC_SPOE: return "spoe-message"; + case ARGC_UBK: + return "use_backend"; default: return "undefined(please report this bug)"; /* must never happen */ } -- 2.39.5