relayd comm: add base path to create session
[lttng-tools.git] / src / bin / lttng-relayd / session.c
index 5eedffc94e657aa924fb90ab72bf24b6056c6080..605931d5bd82ed449143de9b6f9c6b870bb59a2b 100644 (file)
@@ -87,7 +87,7 @@ end:
  * Return allocated session or else NULL.
  */
 struct relay_session *session_create(const char *session_name,
-               const char *hostname,
+               const char *hostname, const char *base_path,
                uint32_t live_timer,
                bool snapshot,
                const lttng_uuid sessiond_uuid,
@@ -95,10 +95,27 @@ struct relay_session *session_create(const char *session_name,
                const uint64_t *current_chunk_id,
                const time_t *creation_time,
                uint32_t major,
-               uint32_t minor)
+               uint32_t minor,
+               bool session_name_contains_creation_time)
 {
        int ret;
-       struct relay_session *session;
+       struct relay_session *session = NULL;
+
+       if (session_name && strstr(session_name, ".")) {
+               ERR("Illegal character in session name: \"%s\"",
+                               session_name);
+               goto error;
+       }
+       if (base_path && strstr(base_path, "../")) {
+               ERR("Invalid session base path walks up the path hierarchy: \"%s\"",
+                               base_path);
+               goto error;
+       }
+       if (hostname && strstr(hostname, ".")) {
+               ERR("Invalid character in hostname: \"%s\"",
+                               hostname);
+               goto error;
+       }
 
        session = zmalloc(sizeof(*session));
        if (!session) {
@@ -115,6 +132,17 @@ struct relay_session *session_create(const char *session_name,
                WARN("Hostname exceeds maximal allowed length");
                goto error;
        }
+       if (lttng_strncpy(session->base_path, base_path,
+                       sizeof(session->base_path))) {
+               WARN("Base path exceeds maximal allowed length");
+               goto error;
+       }
+       if (creation_time) {
+               LTTNG_OPTIONAL_SET(&session->creation_time, *creation_time);
+       }
+       session->session_name_contains_creation_time =
+                       session_name_contains_creation_time;
+
        session->ctf_traces_ht = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
        if (!session->ctf_traces_ht) {
                goto error;
@@ -174,9 +202,6 @@ struct relay_session *session_create(const char *session_name,
        }
 
        lttng_ht_add_unique_u64(sessions_ht, &session->session_n);
-       if (creation_time) {
-               LTTNG_OPTIONAL_SET(&session->creation_time, *creation_time);
-       }
        return session;
 
 error:
This page took 0.026224 seconds and 5 git commands to generate.