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);
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++;
}
}
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++;
}
}
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;
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;
}
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;
}
/*