]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stktable: stktable_init() sets err_msg on error
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 2 Nov 2023 17:34:51 +0000 (18:34 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 3 Nov 2023 16:30:30 +0000 (17:30 +0100)
stktable_init() now sets err_msg when error occurs so that caller is able
to precisely report the cause of the failure.

include/haproxy/stick_table.h
src/cfgparse.c
src/stick_table.c

index c8e66bab4abfeca13437336e98620d275c5326c7..e5ebecd7a7faaeb1e08ed1b9025b6e3d17f1647d 100644 (file)
@@ -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);
index d18d7ab0ab8fe4883856b6b473b8298f255f04b5..2d5b78369fb191666bf4589af80652134e2590f2 100644 (file)
@@ -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++;
                }
        }
index bee91130a787f6ac0a227314db40c9924dd3a66f..91d697b9ef7a28abc292f8bb3ca686a9ef2bbae8 100644 (file)
@@ -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 <err_msg> 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;
 }
 
 /*