From: Aurelien DARRAGON Date: Thu, 2 Nov 2023 17:34:51 +0000 (+0100) Subject: MINOR: stktable: stktable_init() sets err_msg on error X-Git-Tag: v2.9-dev9~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8c19f877a74ef46ebaaf75f2bc08ea65d353520;p=thirdparty%2Fhaproxy.git MINOR: stktable: stktable_init() sets err_msg on error stktable_init() now sets err_msg when error occurs so that caller is able to precisely report the cause of the failure. --- diff --git a/include/haproxy/stick_table.h b/include/haproxy/stick_table.h index c8e66bab4a..e5ebecd7a7 100644 --- a/include/haproxy/stick_table.h +++ b/include/haproxy/stick_table.h @@ -46,7 +46,7 @@ void stksess_free(struct stktable *t, struct stksess *ts); int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcount); int stktable_get_key_shard(struct stktable *t, const void *key, size_t len); -int stktable_init(struct stktable *t); +int stktable_init(struct stktable *t, char **err_msg); int stktable_parse_type(char **args, int *idx, unsigned long *type, size_t *key_size, const char *file, int linenum); int parse_stick_table(const char *file, int linenum, char **args, struct stktable *t, char *id, char *nid, struct peers *peers); diff --git a/src/cfgparse.c b/src/cfgparse.c index d18d7ab0ab..2d5b78369f 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -4398,8 +4398,10 @@ init_proxies_list_stage2: for (t = stktables_list; t; t = t->next) { if (t->proxy) continue; - if (!stktable_init(t)) { - ha_alert("Parsing [%s:%d]: failed to initialize '%s' stick-table.\n", t->conf.file, t->conf.line, t->id); + err = NULL; + if (!stktable_init(t, &err)) { + ha_alert("Parsing [%s:%d]: failed to initialize '%s' stick-table: %s.\n", t->conf.file, t->conf.line, t->id, err); + ha_free(&err); cfgerr++; } } @@ -4412,8 +4414,10 @@ init_proxies_list_stage2: if ((curproxy->flags & PR_FL_DISABLED) || !curproxy->table) continue; - if (!stktable_init(curproxy->table)) { - ha_alert("Proxy '%s': failed to initialize stick-table.\n", curproxy->id); + err = NULL; + if (!stktable_init(curproxy->table, &err)) { + ha_alert("Proxy '%s': failed to initialize stick-table: %s.\n", curproxy->id, err); + ha_free(&err); cfgerr++; } } diff --git a/src/stick_table.c b/src/stick_table.c index bee91130a7..91d697b9ef 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -794,8 +794,13 @@ out_unlock: return task; } -/* Perform minimal stick table intializations, report 0 in case of error, 1 if OK. */ -int stktable_init(struct stktable *t) +/* Perform minimal stick table initialization. In case of error, the + * function will return 0 and will contain hints about the + * error and it is up to the caller to free it. + * + * Returns 1 on success + */ +int stktable_init(struct stktable *t, char **err_msg) { int peers_retval = 0; @@ -812,7 +817,7 @@ int stktable_init(struct stktable *t) if ( t->expire ) { t->exp_task = task_new_anywhere(); if (!t->exp_task) - return 0; + goto mem_error; t->exp_task->process = process_table_expire; t->exp_task->context = (void *)t; } @@ -820,9 +825,14 @@ int stktable_init(struct stktable *t) peers_retval = peers_register_table(t->peers.p, t); } - return (t->pool != NULL) && !peers_retval; + if (t->pool == NULL || peers_retval) + goto mem_error; } return 1; + + mem_error: + memprintf(err_msg, "memory allocation error"); + return 0; } /*