lttng_ctl: add session_name to load override
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 3 Oct 2016 19:18:42 +0000 (15:18 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 7 Oct 2016 19:44:10 +0000 (15:44 -0400)
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 <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/load.h
src/common/config/session-config.c
src/common/config/session-config.h
src/lib/lttng-ctl/load.c

index 808b51331aab38399f0a779fd7b2ae2af2d77d64..a5a78dd312a038276ebdb448f008304cac814c80 100644 (file)
@@ -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).
  *
index adb49bd08ee94b68c9cea8ef46b93b9d93898a15..f8eb37393ff8e73510e401961ab0313c50fab922 100644 (file)
@@ -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);
index 55b8de3dc5fe0df2bc114b4f3ac709f0264b0eac..c6439f756fc431c636a4383c589d6d43c929dff0 100644 (file)
@@ -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. */
index f89effed04b8b69b23e186dfee6237e8b8cfe10d..e70a87d9228ae994a3da007b859a44ed11039be1 100644 (file)
@@ -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;
This page took 0.040381 seconds and 4 git commands to generate.