From 3102c89dde4c49d4f65840f2fd8298da1455f751 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Tue, 14 May 2024 17:05:30 +0200 Subject: [PATCH] MINOR: log: provide proxy context to resolve_logger() Prerequisite work for log-profiles, we need to know under which proxy context the logger is being used. When the info is not available, (ie: global section or log-forward section, is set to NULL) --- include/haproxy/log.h | 2 +- src/fcgi-app.c | 2 +- src/flt_spoe.c | 2 +- src/log.c | 15 +++++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/haproxy/log.h b/include/haproxy/log.h index 48b363dd4..c08a11c31 100644 --- a/include/haproxy/log.h +++ b/include/haproxy/log.h @@ -129,7 +129,7 @@ ssize_t syslog_applet_append_event(void *ctx, struct ist v1, struct ist v2, size */ int parse_logformat_string(const char *str, struct proxy *curproxy, struct lf_expr *lf_expr, int options, int cap, char **err); -int postresolve_logger_list(struct list *loggers, const char *section, const char *section_name); +int postresolve_logger_list(struct proxy *px, struct list *loggers, const char *section, const char *section_name); struct logger *dup_logger(struct logger *def); void free_logger(struct logger *logger); diff --git a/src/fcgi-app.c b/src/fcgi-app.c index e8117a332..5790cebcf 100644 --- a/src/fcgi-app.c +++ b/src/fcgi-app.c @@ -691,7 +691,7 @@ static int cfg_fcgi_apps_postparser() curapp->maxreqs = 1; } - err_code |= postresolve_logger_list(&curapp->loggers, "fcgi-app", curapp->name); + err_code |= postresolve_logger_list(NULL, &curapp->loggers, "fcgi-app", curapp->name); } end: diff --git a/src/flt_spoe.c b/src/flt_spoe.c index 95930f13f..f565e962d 100644 --- a/src/flt_spoe.c +++ b/src/flt_spoe.c @@ -3110,7 +3110,7 @@ spoe_check(struct proxy *px, struct flt_conf *fconf) HA_SPIN_INIT(&conf->agent->rt[i].lock); } - if (postresolve_logger_list(&conf->agent_fe.loggers, "SPOE agent", conf->agent->id) & ERR_CODE) + if (postresolve_logger_list(NULL, &conf->agent_fe.loggers, "SPOE agent", conf->agent->id) & ERR_CODE) return 1; ha_free(&conf->agent->b.name); diff --git a/src/log.c b/src/log.c index d4e493271..974795319 100644 --- a/src/log.c +++ b/src/log.c @@ -1406,13 +1406,15 @@ static int postcheck_log_backend(struct proxy *be) /* resolves a single logger entry (it is expected to be called * at postparsing stage) * + * is parent proxy, used for context (may be NULL) + * * Returns err_code which defaults to ERR_NONE and can be set to a combination * of ERR_WARN, ERR_ALERT, ERR_FATAL and ERR_ABORT in case of errors. * could be set at any time (it will usually be set on error, but * could also be set when no error occurred to report a diag warning), thus is * up to the caller to check it and to free it. */ -static int resolve_logger(struct logger *logger, char **msg) +static int resolve_logger(struct proxy *px, struct logger *logger, char **msg) { struct log_target *target = &logger->target; int err_code = ERR_NONE; @@ -5882,7 +5884,8 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) * Returns err_code which defaults to ERR_NONE and can be set to a combination * of ERR_WARN, ERR_ALERT, ERR_FATAL and ERR_ABORT in case of errors. */ -int postresolve_logger_list(struct list *loggers, const char *section, const char *section_name) +int postresolve_logger_list(struct proxy *px, struct list *loggers, + const char *section, const char *section_name) { int err_code = ERR_NONE; struct logger *logger; @@ -5891,7 +5894,7 @@ int postresolve_logger_list(struct list *loggers, const char *section, const cha int cur_code; char *msg = NULL; - cur_code = resolve_logger(logger, &msg); + cur_code = resolve_logger(px, logger, &msg); if (msg) { void (*e_func)(const char *fmt, ...) = NULL; @@ -5923,13 +5926,13 @@ static int postresolve_loggers() int err_code = ERR_NONE; /* global log directives */ - err_code |= postresolve_logger_list(&global.loggers, NULL, NULL); + err_code |= postresolve_logger_list(NULL, &global.loggers, NULL, NULL); /* proxy log directives */ for (px = proxies_list; px; px = px->next) - err_code |= postresolve_logger_list(&px->loggers, "proxy", px->id); + err_code |= postresolve_logger_list(px, &px->loggers, "proxy", px->id); /* log-forward log directives */ for (px = cfg_log_forward; px; px = px->next) - err_code |= postresolve_logger_list(&px->loggers, "log-forward", px->id); + err_code |= postresolve_logger_list(NULL, &px->loggers, "log-forward", px->id); return err_code; }