From: Jonathan Rajotte Date: Mon, 3 Oct 2016 19:18:42 +0000 (-0400) Subject: lttng_ctl: add session_name to load override X-Git-Tag: v2.9.0-rc1~9 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2aaf5fc72b69cddad0144166edbdae424153eb82;p=lttng-tools.git lttng_ctl: add session_name to load override Introduce the override of the session name during the loading of a session. Can only be used when a session name to be loaded is provided. Renaming of multiple session is ambiguous. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau --- diff --git a/include/lttng/load.h b/include/lttng/load.h index 808b51331..a5a78dd31 100644 --- a/include/lttng/load.h +++ b/include/lttng/load.h @@ -94,6 +94,17 @@ const char *lttng_load_session_attr_get_override_ctrl_url( const char *lttng_load_session_attr_get_override_data_url( struct lttng_load_session_attr *attr); +/* + * Return the configuration override session name attribute. + * This attribute indicates a session name override to be applied during + * the loading of the configuration(s). + * + * NULL indicates no session name override will be applied on configuration + * load. + */ +const char *lttng_load_session_attr_get_override_session_name( + struct lttng_load_session_attr *attr); + /* * Load session attribute setter family of functions. * @@ -171,6 +182,15 @@ int lttng_load_session_attr_set_override_ctrl_url( int lttng_load_session_attr_set_override_data_url( struct lttng_load_session_attr *attr, const char *url); +/* + * Set the session name override attribute. + * + * Loading a configuration file defining multiple sessions will fail if a + * session name is provided. + */ +int lttng_load_session_attr_set_override_session_name( + struct lttng_load_session_attr *attr, const char *session_name); + /* * Load session configuration(s). * diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index adb49bd08..f8eb37393 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -2618,6 +2618,21 @@ domain_init_error: goto error; } + /* Apply overrides */ + if (overrides) { + if (overrides->session_name) { + xmlChar *name_override = xmlStrdup(BAD_CAST(overrides->session_name)); + if (!name_override) { + ret = -LTTNG_ERR_NOMEM; + goto error; + } + + /* Overrides the session name to the provided name */ + xmlFree(name); + name = name_override; + } + } + if (overwrite) { /* Destroy session if it exists */ ret = lttng_destroy_session((const char *) name); diff --git a/src/common/config/session-config.h b/src/common/config/session-config.h index 55b8de3dc..c6439f756 100644 --- a/src/common/config/session-config.h +++ b/src/common/config/session-config.h @@ -34,6 +34,7 @@ struct config_load_session_override_attr { char *path_url; char *ctrl_url; char *data_url; + char *session_name; }; /* Instance of a configuration writer. */ diff --git a/src/lib/lttng-ctl/load.c b/src/lib/lttng-ctl/load.c index f89effed0..e70a87d92 100644 --- a/src/lib/lttng-ctl/load.c +++ b/src/lib/lttng-ctl/load.c @@ -47,6 +47,7 @@ void reset_load_session_attr_urls(struct lttng_load_session_attr *attr) free(attr->override_attr->path_url); free(attr->override_attr->ctrl_url); free(attr->override_attr->data_url); + free(attr->override_attr->session_name); } } @@ -59,6 +60,32 @@ void lttng_load_session_attr_destroy(struct lttng_load_session_attr *attr) } } +static int validate_attr(const struct lttng_load_session_attr *attr) +{ + int ret = 0; + + if (!attr) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + if (!attr->override_attr) { + goto end; + } + + /* + * Refuse override name if the objective is to load multiple session + * since this operation is ambiguous while loading multiple session. + */ + if (attr->override_attr->session_name + && attr->session_name[0] == '\0') { + ret = -LTTNG_ERR_INVALID; + goto end; + } +end: + return ret; +} + const char *lttng_load_session_attr_get_session_name( struct lttng_load_session_attr *attr) { @@ -135,6 +162,20 @@ end: return ret; } +const char *lttng_load_session_attr_get_override_session_name( + struct lttng_load_session_attr *attr) +{ + const char *ret = NULL; + + if (!attr || !attr->override_attr) { + goto end; + } + + ret = attr->override_attr->session_name; +end: + return ret; +} + int lttng_load_session_attr_set_session_name( struct lttng_load_session_attr *attr, const char *session_name) { @@ -532,6 +573,42 @@ end: return ret; } +int lttng_load_session_attr_set_override_session_name( + struct lttng_load_session_attr *attr, const char *session_name) +{ + int ret = 0; + size_t len; + + if (!attr ||!session_name) { + ret = -LTTNG_ERR_INVALID; + 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; + } + } + + len = strlen(session_name); + if (len >= LTTNG_NAME_MAX) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + attr->override_attr->session_name = lttng_strndup(session_name, + len); + if (!attr->override_attr->session_name) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } +end: + return ret; +} + int lttng_load_session(struct lttng_load_session_attr *attr) { int ret; @@ -542,6 +619,11 @@ int lttng_load_session(struct lttng_load_session_attr *attr) goto end; } + ret = validate_attr(attr); + if (ret) { + goto end; + } + url = attr->input_url[0] != '\0' ? attr->input_url : NULL; session_name = attr->session_name[0] != '\0' ? attr->session_name : NULL;