]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: register config file and line number on log servers.
authorEmeric Brun <ebrun@haproxy.com>
Fri, 2 Apr 2021 08:13:43 +0000 (10:13 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Apr 2021 07:18:34 +0000 (09:18 +0200)
This patch registers the parsed file and the line where a log server
is declared to make those information available in configuration
post check.

Those new informations were added on error messages probed resolving
ring names on post configuration check.

include/haproxy/log-t.h
include/haproxy/log.h
src/cfgparse-global.c
src/cfgparse-listen.c
src/cfgparse.c
src/fcgi-app.c
src/flt_spoe.c
src/log.c
src/sink.c

index 9146b77ba2fcf20d99abb9b8fcb8fedb34e46fc9..039621a34e4ae346566aa373f8ea59eb65d23e41 100644 (file)
@@ -237,6 +237,10 @@ struct logsrv {
        int minlvl;
        int maxlen;
        struct logsrv *ref;
+       struct {
+                char *file;                     /* file where the logsrv appears */
+                int line;                       /* line where the logsrv appears */
+        } conf;
        __decl_thread(HA_SPINLOCK_T lock);
 };
 
index 837ae0ccc75cc85c883329591dd27152d3ab973c..8bd448697efd039b2283aee3b4474c199d9572ee 100644 (file)
@@ -86,7 +86,7 @@ int add_to_logformat_list(char *start, char *end, int type, struct list *list_fo
 int parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap, char **err);
 
 /* Parse "log" keyword and update the linked list. */
-int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err);
+int parse_logsrv(char **args, struct list *logsrvs, int do_del, const char *file, int linenum, char **err);
 
 /*
  * This function adds a header to the message and sends the syslog message
index e0762478bb2f89c4884b4c83bb1cdff56856b378..79058c65f082c1b6251ff03b7c62dd2fba237edf 100644 (file)
@@ -904,7 +904,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                 }
        }
        else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
-               if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), &errmsg)) {
+               if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
                        ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
index 739dc8326d0f99a0a70253c8b0f50572cddd297c..49a6d14d4c683488ffd4e52dd7f6fa6086fa37cc 100644 (file)
@@ -2690,7 +2690,7 @@ stats_error_parsing:
                }
        }
        else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
-               if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) {
+               if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
                        ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
index 8f612ee3c8b3851250c213a007479392711ed10c..47f04e5fc5e3c359bbb7eee42653ed129a6f124b 100644 (file)
@@ -730,7 +730,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        err_code |= ERR_ALERT | ERR_ABORT;
                        goto out;
                }
-               if (!parse_logsrv(args, &curpeers->peers_fe->logsrvs, (kwm == KWM_NO), &errmsg)) {
+               if (!parse_logsrv(args, &curpeers->peers_fe->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
                        ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
index 61f904dafc0af5e867f0b0bb701cd2c6b991c224..a1b6e68c5a06f70b059fdaa596313c2d27b7d381 100644 (file)
@@ -1056,7 +1056,7 @@ static int cfg_parse_fcgi_app(const char *file, int linenum, char **args, int kw
                }
        }
        else if (strcmp(args[0], "log-stderr") == 0) {
-               if (!parse_logsrv(args, &curapp->logsrvs, (kwm == KWM_NO), &errmsg)) {
+               if (!parse_logsrv(args, &curapp->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
                        ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
                }
index 5688ca99182c9917c40df7355d4af95bfbf3d2ba..83f6074f4def0b2ae00b5cab4b95a2bd0c7dbdd2 100644 (file)
@@ -3773,7 +3773,7 @@ cfg_parse_spoe_agent(const char *file, int linenum, char **args, int kwm)
        else if (strcmp(args[0], "log") == 0) {
                char *errmsg = NULL;
 
-               if (!parse_logsrv(args, &curlogsrvs, (kwm == 1), &errmsg)) {
+               if (!parse_logsrv(args, &curlogsrvs, (kwm == 1), file, linenum, &errmsg)) {
                        ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
index 292eb588a8d5b340d88b0aa3cd637d3b4a89880e..c8cdafab07603c7235189bf6bd2e32f2c7683061 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -808,7 +808,7 @@ int smp_log_range_cmp(const void *a, const void *b)
  * The function returns 1 in success case, otherwise, it returns 0 and err is
  * filled.
  */
-int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
+int parse_logsrv(char **args, struct list *logsrvs, int do_del, const char *file, int linenum, char **err)
 {
        struct smp_log_range *smp_rgs = NULL;
        struct sockaddr_storage *sk;
@@ -858,6 +858,8 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
                        node->ref = logsrv;
                        LIST_INIT(&node->list);
                        LIST_ADDQ(logsrvs, &node->list);
+                       node->conf.file = strdup(file);
+                       node->conf.line = linenum;
 
                  skip_logsrv:
                        continue;
@@ -886,6 +888,9 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
                goto error;
        }
 
+       logsrv->conf.file = strdup(file);
+       logsrv->conf.line = linenum;
+
        /* skip address for now, it will be parsed at the end */
        cur_arg = 2;
 
@@ -1040,18 +1045,20 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
        logsrv->addr = *sk;
 
        if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) {
-               logsrv->addr = *sk;
                if (!port1)
                        set_host_port(&logsrv->addr, SYSLOG_PORT);
        }
+
  done:
        LIST_ADDQ(logsrvs, &logsrv->list);
        return 1;
 
   error:
        free(smp_rgs);
-       if (logsrv)
+       if (logsrv) {
+               free(logsrv->conf.file);
                free(logsrv->ring_name);
+       }
        free(logsrv);
        return 0;
 }
@@ -4062,7 +4069,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
                }
        }
        else if (strcmp(args[0], "log") == 0) {
-               if (!parse_logsrv(args, &cfg_log_forward->logsrvs, (kwm == KWM_NO), &errmsg)) {
+               if (!parse_logsrv(args, &cfg_log_forward->logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
                        ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
                                 err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
index f734b07c938392fcf7f0aaa1446aafeadff3497a..5d43525cf8e5a3953eb8230a2c9a31905b22849a 100644 (file)
@@ -993,7 +993,7 @@ int post_sink_resolve()
                if (logsrv->type == LOG_TARGET_BUFFER) {
                        sink = sink_find(logsrv->ring_name);
                        if (!sink || sink->type != SINK_TYPE_BUFFER) {
-                               ha_alert("global log server uses unknown ring named '%s'.\n", logsrv->ring_name);
+                               ha_alert("global log server declared in file '%s' at line %d uses unknown ring named '%s'.\n", logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
                                err_code |= ERR_ALERT | ERR_FATAL;
                        }
                        logsrv->sink = sink;
@@ -1005,7 +1005,7 @@ int post_sink_resolve()
                        if (logsrv->type == LOG_TARGET_BUFFER) {
                                sink = sink_find(logsrv->ring_name);
                                if (!sink || sink->type != SINK_TYPE_BUFFER) {
-                                       ha_alert("proxy '%s' log server uses unknown ring named '%s'.\n", px->id, logsrv->ring_name);
+                                       ha_alert("log server declared in proxy section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n", px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
                                        err_code |= ERR_ALERT | ERR_FATAL;
                                }
                                logsrv->sink = sink;
@@ -1018,7 +1018,7 @@ int post_sink_resolve()
                        if (logsrv->type == LOG_TARGET_BUFFER) {
                                sink = sink_find(logsrv->ring_name);
                                if (!sink || sink->type != SINK_TYPE_BUFFER) {
-                                       ha_alert("log-forward '%s' log server uses unknown ring named '%s'.\n", px->id, logsrv->ring_name);
+                                       ha_alert("log server declared in log-forward section '%s' in file '%s' at line %d uses unknown ring named '%s'.\n", px->id, logsrv->conf.file, logsrv->conf.line, logsrv->ring_name);
                                        err_code |= ERR_ALERT | ERR_FATAL;
                                }
                                logsrv->sink = sink;