From: Amaury Denoyelle Date: Wed, 15 Jul 2026 08:39:36 +0000 (+0200) Subject: MINOR: log: use curproxy during config parsing X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=339652dc60c4887f357c26a0ae670a8dc897c5cf;p=thirdparty%2Fhaproxy.git MINOR: log: use curproxy during config parsing Adjusts configuration parsing for log-forward sections : replace head pointer list usage in individual keywords parser by global variable. This parsing patterm is already implemetned in cfgparse-listen module. This is only a refactoring change without any visible effect. It is a preparatoy step before converting to a full doubly linked struct list. --- diff --git a/src/log.c b/src/log.c index 68826f49c..d84295b59 100644 --- a/src/log.c +++ b/src/log.c @@ -6125,7 +6125,6 @@ ssize_t syslog_applet_append_event(void *ctx, struct ist v1, struct ist v2, size int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) { int err_code = ERR_NONE; - struct proxy *px; char *errmsg = NULL; const char *err = NULL; @@ -6147,53 +6146,53 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) goto out; } - px = log_forward_by_name(args[1]); - if (px) { + curproxy = log_forward_by_name(args[1]); + if (curproxy) { ha_alert("Parsing [%s:%d]: log-forward section '%s' has the same name as another log-forward section declared at %s:%d.\n", - file, linenum, args[1], px->conf.file, px->conf.line); + file, linenum, args[1], curproxy->conf.file, curproxy->conf.line); err_code |= ERR_ALERT | ERR_FATAL; goto out; } - px = proxy_find_by_name(args[1], 0, 0); - if (px) { + curproxy = proxy_find_by_name(args[1], 0, 0); + if (curproxy) { ha_alert("Parsing [%s:%d]: log forward section '%s' has the same name as %s '%s' declared at %s:%d.\n", - file, linenum, args[1], proxy_type_str(px), - px->id, px->conf.file, px->conf.line); + file, linenum, args[1], proxy_type_str(curproxy), + curproxy->id, curproxy->conf.file, curproxy->conf.line); err_code |= ERR_ALERT | ERR_FATAL; goto out; } - px = proxy_find_by_name(args[1], PR_CAP_DEF, 0); - if (px) { + curproxy = proxy_find_by_name(args[1], PR_CAP_DEF, 0); + if (curproxy) { /* collision with a "defaults" section */ ha_warning("Parsing [%s:%d]: log-forward section '%s' has the same name as %s '%s' declared at %s:%d." " This is dangerous and will not be supported anymore in version 3.3.\n", - file, linenum, args[1], proxy_type_str(px), - px->id, px->conf.file, px->conf.line); + file, linenum, args[1], proxy_type_str(curproxy), + curproxy->id, curproxy->conf.file, curproxy->conf.line); err_code |= ERR_WARN; } - px = alloc_new_proxy(args[1], PR_CAP_FE, &errmsg); - if (!px) { + curproxy = alloc_new_proxy(args[1], PR_CAP_FE, &errmsg); + if (!curproxy) { ha_alert("Parsing [%s:%d]: %s\n", file, linenum, errmsg); err_code |= ERR_ALERT | ERR_FATAL; goto out; } - px->next = cfg_log_forward; - cfg_log_forward = px; - px->conf.file = copy_file_name(file); - px->conf.line = linenum; - px->mode = PR_MODE_SYSLOG; - px->maxconn = 10; - px->timeout.client = TICK_ETERNITY; - px->accept = frontend_accept; - px->default_target = &syslog_applet.obj_type; - px->options3 |= PR_O3_LOGF_HOST_FILL; + curproxy->next = cfg_log_forward; + cfg_log_forward = curproxy; + curproxy->conf.file = copy_file_name(file); + curproxy->conf.line = linenum; + curproxy->mode = PR_MODE_SYSLOG; + curproxy->maxconn = 10; + curproxy->timeout.client = TICK_ETERNITY; + curproxy->accept = frontend_accept; + curproxy->default_target = &syslog_applet.obj_type; + curproxy->options3 |= PR_O3_LOGF_HOST_FILL; } else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */ - if (warnifnotcap(cfg_log_forward, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?")) + if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?")) err_code |= ERR_WARN; if (*(args[1]) == 0) { @@ -6201,12 +6200,12 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) err_code |= ERR_ALERT | ERR_FATAL; goto out; } - cfg_log_forward->maxconn = atol(args[1]); + curproxy->maxconn = atol(args[1]); if (alertif_too_many_args(1, file, linenum, args, &err_code)) goto out; } else if (strcmp(args[0], "backlog") == 0) { /* backlog */ - if (warnifnotcap(cfg_log_forward, PR_CAP_FE, file, linenum, args[0], NULL)) + if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) err_code |= ERR_WARN; if (*(args[1]) == 0) { @@ -6214,7 +6213,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) err_code |= ERR_ALERT | ERR_FATAL; goto out; } - cfg_log_forward->backlog = atol(args[1]); + curproxy->backlog = atol(args[1]); if (alertif_too_many_args(1, file, linenum, args, &err_code)) goto out; } @@ -6226,8 +6225,8 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) cur_arg = 1; - bind_conf = bind_conf_alloc(cfg_log_forward, file, linenum, - NULL, xprt_get(XPRT_RAW)); + bind_conf = bind_conf_alloc(curproxy, file, linenum, + NULL, xprt_get(XPRT_RAW)); if (!bind_conf) { ha_alert("parsing [%s:%d] : out of memory error.", file, linenum); err_code |= ERR_ALERT | ERR_FATAL; @@ -6237,7 +6236,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) bind_conf->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : MAX_ACCEPT; bind_conf->accept = session_accept_fd; - if (!str2listener(args[1], cfg_log_forward, bind_conf, file, linenum, &errmsg)) { + if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { if (errmsg) { indent_msg(&errmsg, 2); ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); @@ -6269,7 +6268,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) cur_arg = 1; - bind_conf = bind_conf_alloc(cfg_log_forward, file, linenum, + bind_conf = bind_conf_alloc(curproxy, file, linenum, NULL, xprt_get(XPRT_RAW)); if (!bind_conf) { ha_alert("parsing [%s:%d] : out of memory error.", file, linenum); @@ -6279,7 +6278,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) bind_conf->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : MAX_ACCEPT; - if (!str2receiver(args[1], cfg_log_forward, bind_conf, file, linenum, &errmsg)) { + if (!str2receiver(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { if (errmsg) { indent_msg(&errmsg, 2); ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); @@ -6301,7 +6300,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) while (*args[cur_arg] && (kw = bind_find_kw(args[cur_arg]))) { int ret; - ret = kw->parse(args, cur_arg, cfg_log_forward, bind_conf, &errmsg); + ret = kw->parse(args, cur_arg, curproxy, bind_conf, &errmsg); err_code |= ret; if (ret) { if (errmsg) { @@ -6329,7 +6328,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) } } else if (strcmp(args[0], "log") == 0) { - if (!parse_logger(args, &cfg_log_forward->loggers, (kwm == KWM_NO), file, linenum, &errmsg)) { + if (!parse_logger(args, &curproxy->loggers, (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; @@ -6366,7 +6365,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) err_code |= ERR_ALERT | ERR_FATAL; goto out; } - cfg_log_forward->timeout.client = MS_TO_TICKS(timeout); + curproxy->timeout.client = MS_TO_TICKS(timeout); } else if (strcmp(args[0], "option") == 0) { if (*(args[1]) == '\0') { @@ -6384,7 +6383,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) curproxy = cfg_log_forward; if (cfg_parse_listen_match_option(file, linenum, kwm, cfg_opts3, &err_code, args, PR_MODE_SYSLOG, PR_CAP_FE, - &cfg_log_forward->options3, &cfg_log_forward->no_options3)) + &curproxy->options3, &curproxy->no_options3)) goto out; if (err_code & ERR_CODE) @@ -6409,15 +6408,15 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) goto out; } - cfg_log_forward->options3 &= ~PR_O3_LOGF_HOST; - cfg_log_forward->no_options3 &= ~PR_O3_LOGF_HOST; + curproxy->options3 &= ~PR_O3_LOGF_HOST; + curproxy->no_options3 &= ~PR_O3_LOGF_HOST; switch (kwm) { case KWM_STD: - cfg_log_forward->options3 |= value; + curproxy->options3 |= value; break; case KWM_NO: - cfg_log_forward->no_options3 |= value; + curproxy->no_options3 |= value; break; case KWM_DEF: /* already cleared */ break;