From: Amaury Denoyelle Date: Wed, 29 Jul 2026 08:39:54 +0000 (+0200) Subject: MINOR: server: improve parsing error for server-template X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=94024a60dc197b26a13751a6a0eaa3071f023cfa;p=thirdparty%2Fhaproxy.git MINOR: server: improve parsing error for server-template When parsing a server configuration line, a global context is set to the current server instance. This allows to automatically prefix any warning/error messages by the server name. This prefix is generated via generate_usermsgs_ctx_str(). The output was not useful for server-template lines as server is NULL for them. Thus, this patch improves generate_usermsgs_ctx_str() to identify a server-template. Now, a dedicated 'server-template' prefix is generated, with used instead of NULL field. * Example of a previous error message : [ALERT] (39934) : config : [./hap.cfg:54] : 'server-template be/(null)' : error detected while parsing [...] * Example of a new error message : [ALERT] (40205) : config : [./hap.cfg:54] : 'server-template be/local' : error detected while parsing [...] --- diff --git a/src/errors.c b/src/errors.c index 9f334dbe4..229218e32 100644 --- a/src/errors.c +++ b/src/errors.c @@ -193,6 +193,8 @@ void reset_usermsgs_ctx(void) static void generate_usermsgs_ctx_str(void) { struct usermsgs_ctx *ctx = &usermsgs_ctx; + struct server *srv; + const char *srv_id; void *area; int ret; @@ -219,10 +221,12 @@ static void generate_usermsgs_ctx_str(void) switch (obj_type(ctx->obj)) { case OBJ_TYPE_SERVER: + srv = __objt_server(ctx->obj); + srv_id = srv->id ? srv->id : srv->tmpl_info.prefix; ret = snprintf(b_tail(&ctx->str), b_room(&ctx->str), - "'server %s/%s' : ", - __objt_server(ctx->obj)->proxy->id, - __objt_server(ctx->obj)->id); + "'%s %s/%s' : ", + srv->id ? "server" : "server-template", + srv->proxy->id, srv_id); b_add(&ctx->str, MIN(ret, b_room(&ctx->str))); break;