}
static
-int create_snapshot_session(const char *session_name, xmlNodePtr output_node)
+int create_snapshot_session(const char *session_name, xmlNodePtr output_node,
+ const struct config_load_session_override_attr *overrides)
{
int ret;
xmlNodePtr node = NULL;
uint64_t max_size = UINT64_MAX;
struct consumer_output output = { 0 };
struct lttng_snapshot_output *snapshot_output = NULL;
+ const char *control_uri = NULL;
+ const char *data_uri = NULL;
+ const char *path = NULL;
for (node = xmlFirstElementChild(snapshot_output_node); node;
node = xmlNextElementSibling(node)) {
}
}
+ if (overrides) {
+ if (overrides->path_url) {
+ /* Control/data_uri are null */
+ path = overrides->path_url;
+ } else {
+ if (overrides->ctrl_url) {
+ /* path is null */
+ control_uri = overrides->ctrl_url;
+ }
+ if (overrides->data_url) {
+ /* path is null */
+ data_uri = overrides->data_url;
+ }
+ }
+ } else {
+ control_uri = output.control_uri;
+ data_uri = output.data_uri;
+ path = output.path;
+ }
+
snapshot_output = lttng_snapshot_output_create();
if (!snapshot_output) {
ret = -LTTNG_ERR_NOMEM;
goto error_snapshot_output;
}
- if (output.path) {
- ret = lttng_snapshot_output_set_ctrl_url(output.path,
+ if (path) {
+ ret = lttng_snapshot_output_set_ctrl_url(path,
snapshot_output);
if (ret) {
goto error_snapshot_output;
}
} else {
- if (output.control_uri) {
- ret = lttng_snapshot_output_set_ctrl_url(output.control_uri,
+ if (control_uri) {
+ ret = lttng_snapshot_output_set_ctrl_url(control_uri,
snapshot_output);
if (ret) {
goto error_snapshot_output;
}
}
- if (output.data_uri) {
- ret = lttng_snapshot_output_set_data_url(output.data_uri,
+ if (data_uri) {
+ ret = lttng_snapshot_output_set_data_url(data_uri,
snapshot_output);
if (ret) {
goto error_snapshot_output;
struct lttng_domain *jul_domain,
struct lttng_domain *log4j_domain,
xmlNodePtr output_node,
- uint64_t live_timer_interval)
+ uint64_t live_timer_interval,
+ const struct config_load_session_override_attr *overrides)
{
int ret;
struct consumer_output output = { 0 };
xmlNodePtr consumer_output_node;
+ const char *control_uri = NULL;
+ const char *data_uri = NULL;
+ const char *path = NULL;
assert(name);
}
}
- if (live_timer_interval != UINT64_MAX &&
- !output.control_uri && !output.data_uri) {
+ /* Check for override and apply them */
+ if (overrides) {
+ if (overrides->path_url) {
+ /* control/data_uri are null */;
+ path = overrides->path_url;
+ } else {
+ if (overrides->ctrl_url) {
+ /* path is null */
+ control_uri = overrides->ctrl_url;
+ }
+ if (overrides->data_url) {
+ /* path is null */
+ data_uri = overrides->data_url;
+ }
+ }
+ } else {
+ control_uri = output.control_uri;
+ data_uri = output.data_uri;
+ path = output.path;
+ }
+
+ if (live_timer_interval != UINT64_MAX && !control_uri && !data_uri) {
ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
goto end;
}
- if (output.control_uri || output.data_uri) {
+ if (control_uri || data_uri) {
/* network destination */
if (live_timer_interval && live_timer_interval != UINT64_MAX) {
/*
goto end;
}
- ret = create_session_net_output(name, output.control_uri,
- output.data_uri);
+ ret = create_session_net_output(name, control_uri, data_uri);
if (ret) {
goto end;
}
} else {
/* either local output or no output */
- ret = lttng_create_session(name, output.path);
+ ret = lttng_create_session(name, path);
if (ret) {
goto end;
}
static
int process_session_node(xmlNodePtr session_node, const char *session_name,
- int overwrite)
+ int overwrite,
+ const struct config_load_session_override_attr *overrides)
{
int ret, started = -1, snapshot_mode = -1;
uint64_t live_timer_interval = UINT64_MAX;
/* Create session type depending on output type */
if (snapshot_mode && snapshot_mode != -1) {
- ret = create_snapshot_session((const char *) name, output_node);
+ ret = create_snapshot_session((const char *) name, output_node,
+ overrides);
} else if (live_timer_interval &&
live_timer_interval != UINT64_MAX) {
ret = create_session((const char *) name, kernel_domain,
ust_domain, jul_domain, log4j_domain,
- output_node, live_timer_interval);
+ output_node, live_timer_interval, overrides);
} else {
/* regular session */
ret = create_session((const char *) name, kernel_domain,
ust_domain, jul_domain, log4j_domain,
- output_node, UINT64_MAX);
+ output_node, UINT64_MAX, overrides);
}
if (ret) {
goto error;
static
int load_session_from_file(const char *path, const char *session_name,
- struct session_config_validation_ctx *validation_ctx, int overwrite)
+ struct session_config_validation_ctx *validation_ctx, int overwrite,
+ const struct config_load_session_override_attr *overrides)
{
int ret, session_found = !session_name;
xmlDocPtr doc = NULL;
session_node; session_node =
xmlNextElementSibling(session_node)) {
ret = process_session_node(session_node,
- session_name, overwrite);
+ session_name, overwrite, overrides);
if (session_name && ret == 0) {
/* Target session found and loaded */
session_found = 1;
static
int load_session_from_path(const char *path, const char *session_name,
- struct session_config_validation_ctx *validation_ctx, int overwrite)
+ struct session_config_validation_ctx *validation_ctx, int overwrite,
+ const struct config_load_session_override_attr *overrides)
{
int ret, session_found = !session_name;
DIR *directory = NULL;
file_path[path_len + file_name_len] = '\0';
ret = load_session_from_file(file_path, session_name,
- validation_ctx, overwrite);
+ validation_ctx, overwrite, overrides);
if (session_name && !ret) {
session_found = 1;
break;
free(file_path);
} else {
ret = load_session_from_file(path, session_name,
- validation_ctx, overwrite);
+ validation_ctx, overwrite, overrides);
if (ret) {
goto end;
} else {
LTTNG_HIDDEN
int config_load_session(const char *path, const char *session_name,
- int overwrite, unsigned int autoload)
+ int overwrite, unsigned int autoload,
+ const struct config_load_session_override_attr *overrides)
{
int ret;
bool session_loaded = false;
}
if (path_ptr) {
ret = load_session_from_path(path_ptr, session_name,
- &validation_ctx, overwrite);
+ &validation_ctx, overwrite, overrides);
if (ret && ret != -LTTNG_ERR_LOAD_SESSION_NOENT) {
goto end;
}
if (path_ptr) {
ret = load_session_from_path(path_ptr, session_name,
- &validation_ctx, overwrite);
+ &validation_ctx, overwrite, overrides);
if (!ret) {
session_loaded = true;
}
}
ret = load_session_from_path(path, session_name,
- &validation_ctx, overwrite);
+ &validation_ctx, overwrite, overrides);
}
end:
fini_session_config_validation_ctx(&validation_ctx);
free(attr->raw_override_path_url);
free(attr->raw_override_ctrl_url);
free(attr->raw_override_data_url);
- free(attr->override_attr.path_url);
- free(attr->override_attr.ctrl_url);
- free(attr->override_attr.data_url);
+ if (attr->override_attr) {
+ free(attr->override_attr->path_url);
+ free(attr->override_attr->ctrl_url);
+ free(attr->override_attr->data_url);
+ }
}
void lttng_load_session_attr_destroy(struct lttng_load_session_attr *attr)
{
if (attr) {
reset_load_session_attr_urls(attr);
+ free(attr->override_attr);
free(attr);
}
}
{
const char *ret = NULL;
- if (attr && attr->override_attr.path_url) {
+ if (attr && attr->override_attr->path_url) {
ret = attr->raw_override_path_url;
}
{
const char *ret = NULL;
- if (attr && attr->override_attr.ctrl_url) {
+ if (attr && attr->override_attr->ctrl_url) {
ret = attr->raw_override_ctrl_url;
}
{
const char *ret = NULL;
- if (attr && attr->override_attr.data_url) {
+ if (attr && attr->override_attr->data_url) {
ret = attr->raw_override_data_url;
}
{
const char *ret = NULL;
- if (attr && (attr->override_attr.path_url ||
- (attr->override_attr.ctrl_url &&
- attr->override_attr.data_url))) {
+ if (attr && (attr->override_attr->path_url ||
+ (attr->override_attr->ctrl_url &&
+ attr->override_attr->data_url))) {
ret = attr->raw_override_url;
}
goto end;
}
- if (attr->override_attr.path_url) {
+ if (!attr->override_attr) {
+ attr->override_attr = zmalloc(
+ sizeof(struct config_load_session_override_attr));
+ if (!attr->override_attr) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
+ }
+
+ if (attr->override_attr->path_url) {
/*
- * FIXME: return a more meaningful error.
- * Setting a ctrl override after a path override make no
- * sense.
- * */
+ * Setting a ctrl override after a path override makes no sense.
+ */
ret = -LTTNG_ERR_INVALID;
goto end;
}
}
/* Squash old value if any */
- free(attr->override_attr.ctrl_url);
+ free(attr->override_attr->ctrl_url);
free(attr->raw_override_ctrl_url);
/* Populate the object */
- attr->override_attr.ctrl_url = url_str;
+ attr->override_attr->ctrl_url = url_str;
attr->raw_override_ctrl_url = raw_str;
/* Ownership passed to attr. */
goto end;
}
- if (attr->override_attr.path_url) {
+ if (!attr->override_attr) {
+ attr->override_attr = zmalloc(
+ sizeof(struct config_load_session_override_attr));
+ if (!attr->override_attr) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
+ }
+
+ if (attr->override_attr->path_url) {
+ /*
+ * Setting a data override after a path override makes no sense.
+ */
ret = -LTTNG_ERR_INVALID;
goto end;
}
}
/* Squash old value if any */
- free(attr->override_attr.data_url);
+ free(attr->override_attr->data_url);
free(attr->raw_override_data_url);
/* Populate the object */
- attr->override_attr.data_url = url_str;
+ attr->override_attr->data_url = url_str;
attr->raw_override_data_url = raw_str;
/* Ownership passed to attr. */
goto end;
}
+ if (!attr->override_attr) {
+ attr->override_attr = zmalloc(
+ sizeof(struct config_load_session_override_attr));
+ if (!attr->override_attr) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
+ }
+
/*
* FIXME: uri_parse should be able to take as parameter the protocol
* type to validate "url". For now only check the parsing goes through;
reset_load_session_attr_urls(attr);
- attr->override_attr.path_url = path_str;
- attr->override_attr.ctrl_url = ctrl_str;
- attr->override_attr.data_url = data_str;
+ attr->override_attr->path_url = path_str;
+ attr->override_attr->ctrl_url = ctrl_str;
+ attr->override_attr->data_url = data_str;
attr->raw_override_url = raw_url_str;
attr->raw_override_path_url = raw_path_str;
session_name = attr->session_name[0] != '\0' ?
attr->session_name : NULL;
- ret = config_load_session(url, session_name, attr->overwrite, 0);
+ ret = config_load_session(url, session_name, attr->overwrite, 0,
+ attr->override_attr);
end:
return ret;