*/
int parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap, char **err);
+struct logsrv *dup_logsrv(struct logsrv *def);
void free_logsrv(struct logsrv *logsrv);
/* Parse "log" keyword and update the linked list. */
/* copy logs from "global" log list */
list_for_each_entry(logsrv, &global.logsrvs, list) {
- struct logsrv *node = malloc(sizeof(*node));
+ struct logsrv *node = dup_logsrv(logsrv);
if (!node) {
memprintf(&errmsg, "out of memory.");
err_code |= ERR_ALERT | ERR_FATAL;
goto err;
}
-
- memcpy(node, logsrv, sizeof(*node));
- LIST_INIT(&node->list);
LIST_APPEND(&curproxy->logsrvs, &node->list);
- node->ring_name = logsrv->ring_name ? strdup(logsrv->ring_name) : NULL;
- node->conf.file = logsrv->conf.file ? strdup(logsrv->conf.file) : NULL;
}
if (curproxy->conf.logformat_string) {
curproxy->conf.args.ctx = ARGC_LOG;
return 0;
}
+/* tries to duplicate <def> logsrv
+ *
+ * Returns the newly allocated and duplicated logsrv or NULL
+ * in case of error.
+ */
+struct logsrv *dup_logsrv(struct logsrv *def)
+{
+ struct logsrv *cpy = malloc(sizeof(*cpy));
+
+ /* copy everything that can be easily copied */
+ memcpy(cpy, def, sizeof(*cpy));
+
+ /* default values */
+ cpy->ring_name = NULL;
+ cpy->conf.file = NULL;
+ LIST_INIT(&cpy->list);
+ HA_SPIN_INIT(&cpy->lock);
+
+ /* special members */
+ if (def->ring_name) {
+ cpy->ring_name = strdup(def->ring_name);
+ if (!cpy->ring_name)
+ goto error;
+ }
+ if (def->conf.file) {
+ cpy->conf.file = strdup(def->conf.file);
+ if (!cpy->conf.file)
+ goto error;
+ }
+ cpy->ref = def;
+ return cpy;
+
+ error:
+ free_logsrv(cpy);
+ return NULL;
+}
+
/* frees log server <logsrv> after freeing all of its allocated fields. The
* server must not belong to a list anymore. Logsrv may be NULL, which is
* silently ignored.
goto skip_logsrv;
}
- node = malloc(sizeof(*node));
+ /* duplicate logsrv from global */
+ node = dup_logsrv(logsrv);
if (!node) {
memprintf(err, "out of memory error");
goto error;
}
- memcpy(node, logsrv, sizeof(struct logsrv));
- node->ref = logsrv;
- LIST_INIT(&node->list);
- LIST_APPEND(logsrvs, &node->list);
- node->ring_name = logsrv->ring_name ? strdup(logsrv->ring_name) : NULL;
+
+ /* manually override some values */
+ ha_free(&node->conf.file);
node->conf.file = strdup(file);
node->conf.line = linenum;
+ /* add to list */
+ LIST_APPEND(logsrvs, &node->list);
+
skip_logsrv:
continue;
}
/* copy default logsrvs to curproxy */
list_for_each_entry(tmplogsrv, &defproxy->logsrvs, list) {
- struct logsrv *node = malloc(sizeof(*node));
+ struct logsrv *node = dup_logsrv(tmplogsrv);
if (!node) {
memprintf(errmsg, "proxy '%s': out of memory", curproxy->id);
return 1;
}
- memcpy(node, tmplogsrv, sizeof(struct logsrv));
- node->ref = tmplogsrv->ref;
- LIST_INIT(&node->list);
LIST_APPEND(&curproxy->logsrvs, &node->list);
- node->ring_name = tmplogsrv->ring_name ? strdup(tmplogsrv->ring_name) : NULL;
- node->conf.file = strdup(tmplogsrv->conf.file);
- node->conf.line = tmplogsrv->conf.line;
}
curproxy->conf.uniqueid_format_string = defproxy->conf.uniqueid_format_string;