Fix: honor base path for network URIs
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 14 Aug 2019 17:30:28 +0000 (13:30 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 3 Sep 2019 20:10:03 +0000 (16:10 -0400)
Starting from 2.11, the following use-case stopped working as expected:

lttng create --set-url=net://localhost/my/path/custom
lttng enable-event -u -a
lttng start
[ run app ]

The output trace is expected in the following directory on the relayd
(no timestamp suffix):

$LTTNG_HOME/lttng-traces/[hostname]/my/path/custom

Add the base_path information to the session object in the session
daemon, extracted from the network URI, and pass that information to the
relay daemon through the create session (2.11) command.

It also fixes the use-case:

lttng create --snapshot --set-url=net://localhost/my/path/custom
lttng enable-event -u -a
lttng start
[ run app ]
lttng snapshot record

which is expected to record the snapshot under:
$LTTNG_HOME/lttng-traces/[hostname]/my/path/custom/snapshot-[N]-[timestamp]

Similar situation for:

lttng create --snapshot
lttng enable-event -u -a
lttng start
[ run app ]
lttng snapshot record net://localhost/my/path/custom

which is expected to record the snapshot under:
$LTTNG_HOME/lttng-traces/[hostname]/my/path/custom/snapshot-[N]-[timestamp]

Note that specifying the base_path on the snapshot record command
overrides the base path specified at create.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
16 files changed:
include/lttng/session-descriptor-internal.h
src/bin/lttng-relayd/cmd-2-11.c
src/bin/lttng-relayd/cmd-2-11.h
src/bin/lttng-relayd/main.c
src/bin/lttng-relayd/session.c
src/bin/lttng-relayd/session.h
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/consumer.c
src/bin/lttng-sessiond/consumer.h
src/bin/lttng-sessiond/session.c
src/bin/lttng-sessiond/session.h
src/common/relayd/relayd.c
src/common/relayd/relayd.h
src/common/session-descriptor.c
src/common/sessiond-comm/relayd.h
tests/unit/test_session.c

index 09d493393f1a4ee310a69994bf73b0dec21ba0d8..18a70bad42af5b8b62271a2ba78a4014f7a96f75 100644 (file)
@@ -109,4 +109,8 @@ int lttng_session_descriptor_assign(
                struct lttng_session_descriptor *dst_descriptor,
                const struct lttng_session_descriptor *src_descriptor);
 
+LTTNG_HIDDEN
+int lttng_session_descriptor_get_base_path(struct lttng_session_descriptor *dst,
+               const char **base_path);
+
 #endif /* LTTNG_SESSION_DESCRIPTOR_INTERNAL_H */
index 79f439c4652ead386f140bc00a1287e668159927..c513130ab6fa40709a95151c885a9479cac80d87 100644 (file)
@@ -30,7 +30,7 @@
 #include "utils.h"
 
 int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
-               char *session_name, char *hostname,
+               char *session_name, char *hostname, char *base_path,
                uint32_t *live_timer, bool *snapshot,
                uint64_t *id_sessiond, lttng_uuid sessiond_uuid,
                bool *has_current_chunk, uint64_t *current_chunk_id,
@@ -38,9 +38,10 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
 {
        int ret;
        struct lttcomm_relayd_create_session_2_11 header;
-       size_t header_len, received_names_size;
+       size_t header_len, received_names_size, offset;
        struct lttng_buffer_view session_name_view;
        struct lttng_buffer_view hostname_view;
+       struct lttng_buffer_view base_path_view;
 
        header_len = sizeof(header);
 
@@ -54,6 +55,7 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
 
        header.session_name_len = be32toh(header.session_name_len);
        header.hostname_len = be32toh(header.hostname_len);
+       header.base_path_len = be32toh(header.base_path_len);
        header.live_timer = be32toh(header.live_timer);
        header.current_chunk_id.value = be64toh(header.current_chunk_id.value);
        header.current_chunk_id.is_set = !!header.current_chunk_id.is_set;
@@ -61,7 +63,8 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
 
        lttng_uuid_copy(sessiond_uuid, header.sessiond_uuid);
 
-       received_names_size = header.session_name_len + header.hostname_len;
+       received_names_size = header.session_name_len + header.hostname_len +
+                               header.base_path_len;
        if (payload->size < header_len + received_names_size) {
                ERR("Unexpected payload size in \"cmd_create_session_2_11\": expected >= %zu bytes, got %zu bytes",
                                header_len + received_names_size, payload->size);
@@ -80,11 +83,21 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
                ERR("Length of hostname (%" PRIu32 " bytes) received in create_session command exceeds maximum length (%d bytes)", header.hostname_len, LTTNG_HOST_NAME_MAX);
                goto error;
        }
+       if (header.base_path_len > LTTNG_PATH_MAX) {
+               ret = -ENAMETOOLONG;
+               ERR("Length of base_path (%" PRIu32 " bytes) received in create_session command exceeds maximum length (%d bytes)", header.base_path_len, PATH_MAX);
+               goto error;
+       }
 
-       session_name_view = lttng_buffer_view_from_view(payload, header_len,
+       offset = header_len;
+       session_name_view = lttng_buffer_view_from_view(payload, offset,
                        header.session_name_len);
+       offset += header.session_name_len;
        hostname_view = lttng_buffer_view_from_view(payload,
-                       header_len + header.session_name_len, header.hostname_len);
+                       offset, header.hostname_len);
+       offset += header.hostname_len;
+       base_path_view = lttng_buffer_view_from_view(payload,
+                       offset, header.base_path_len);
 
        /* Validate that names are NULL terminated. */
        if (session_name_view.data[session_name_view.size - 1] != '\0') {
@@ -99,12 +112,20 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
                goto error;
        }
 
+       if (base_path_view.size != 0 &&
+                       base_path_view.data[base_path_view.size - 1] != '\0') {
+               ERR("cmd_create_session_2_11 base_path is invalid (not NULL terminated)");
+               ret = -1;
+               goto error;
+       }
+
        /*
         * Length and null-termination check are already performed.
-        * LTTNG_NAME_MAX and LTTNG_HOST_NAME_MAX max size are expected.
+        * LTTNG_NAME_MAX, LTTNG_HOST_NAME_MAX, and LTTNG_PATH_MAX max sizes are expected.
         */
        strcpy(session_name, session_name_view.data);
        strcpy(hostname, hostname_view.data);
+       strcpy(base_path, base_path_view.size ? base_path_view.data : "");
 
        *live_timer = header.live_timer;
        *snapshot = !!header.snapshot;
index d2af458177a97498434f74c89ffa1ad83dbaddef..48841d26b53393be7c78b95725e90931a3cab8be 100644 (file)
@@ -22,7 +22,7 @@
 #include <common/compat/uuid.h>
 
 int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
-               char *session_name, char *hostname,
+               char *session_name, char *hostname, char *base_path,
                uint32_t *live_timer, bool *snapshot,
                uint64_t *id_sessiond, lttng_uuid sessiond_uuid,
                bool *has_current_chunk, uint64_t *current_chunk_id,
index 9589b6f52bdeed68ea62111ad7e7d2f88d7c2b77..d164bbd8cde4c5c176859bb6728433eef455d479 100644 (file)
@@ -1074,6 +1074,7 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr,
        uint32_t live_timer = 0;
        bool snapshot = false;
        /* Left nil for peers < 2.11. */
+       char base_path[LTTNG_PATH_MAX] = {};
        lttng_uuid sessiond_uuid = {};
        LTTNG_OPTIONAL(uint64_t) id_sessiond = {};
        LTTNG_OPTIONAL(uint64_t) current_chunk_id = {};
@@ -1094,7 +1095,7 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr,
 
                /* From 2.11 to ... */
                ret = cmd_create_session_2_11(payload, session_name, hostname,
-                               &live_timer, &snapshot, &id_sessiond_value,
+                               base_path, &live_timer, &snapshot, &id_sessiond_value,
                                sessiond_uuid, &has_current_chunk,
                                &current_chunk_id_value, &creation_time_value);
                if (lttng_uuid_is_nil(sessiond_uuid)) {
@@ -1115,7 +1116,7 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr,
                goto send_reply;
        }
 
-       session = session_create(session_name, hostname, live_timer,
+       session = session_create(session_name, hostname, base_path, live_timer,
                        snapshot, sessiond_uuid,
                        id_sessiond.is_set ? &id_sessiond.value : NULL,
                        current_chunk_id.is_set ? &current_chunk_id.value : NULL,
@@ -2262,29 +2263,49 @@ static int init_session_output_directory_handle(struct relay_session *session,
                struct lttng_directory_handle *handle)
 {
        int ret;
-       /* hostname/session_name */
+       /*
+        * session_directory:
+        *
+        * if base_path is NULL
+        *   hostname/session_name
+        * else
+        *   hostname/base_path
+        */
        char *session_directory = NULL;
        /*
         * base path + session_directory
         * e.g. /home/user/lttng-traces/hostname/session_name
         */
        char *full_session_path = NULL;
-       char creation_time_str[16];
-       struct tm *timeinfo;
 
-       assert(session->creation_time.is_set);
-       timeinfo = localtime(&session->creation_time.value);
-       if (!timeinfo) {
-               ret = -1;
-               goto end;
-       }
-       strftime(creation_time_str, sizeof(creation_time_str), "%Y%m%d-%H%M%S",
-                       timeinfo);
+       /*
+        * If base path is set, it overrides the session name for the
+        * session relative base path. No timestamp is appended if the
+        * base path is overridden.
+        */
+       if (session->base_path[0] == '\0') {
+               char creation_time_str[16];
+               struct tm *timeinfo;
 
-       pthread_mutex_lock(&session->lock);
-       ret = asprintf(&session_directory, "%s/%s-%s", session->hostname,
-                       session->session_name, creation_time_str);
-       pthread_mutex_unlock(&session->lock);
+               assert(session->creation_time.is_set);
+               timeinfo = localtime(&session->creation_time.value);
+               if (!timeinfo) {
+                       ret = -1;
+                       goto end;
+               }
+               strftime(creation_time_str, sizeof(creation_time_str), "%Y%m%d-%H%M%S",
+                               timeinfo);
+
+               pthread_mutex_lock(&session->lock);
+               ret = asprintf(&session_directory, "%s/%s-%s", session->hostname,
+                               session->session_name, creation_time_str);
+               pthread_mutex_unlock(&session->lock);
+       } else {
+               pthread_mutex_lock(&session->lock);
+               ret = asprintf(&session_directory, "%s/%s", session->hostname,
+                               session->base_path);
+               pthread_mutex_unlock(&session->lock);
+       }
        if (ret < 0) {
                PERROR("Failed to format session directory name");
                goto end;
index 5eedffc94e657aa924fb90ab72bf24b6056c6080..603a80978701f000d2aa0284d52dcbb83824c125 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,
@@ -115,6 +115,12 @@ 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;
+       }
+
        session->ctf_traces_ht = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
        if (!session->ctf_traces_ht) {
                goto error;
index 6442c17ee4522f92a08d82d31aaa820b8cc5ff52..228873300cab6f134465d8a6fa208b36dfc94d5d 100644 (file)
@@ -55,6 +55,7 @@ struct relay_session {
        LTTNG_OPTIONAL(time_t) creation_time;
        char session_name[LTTNG_NAME_MAX];
        char hostname[LTTNG_HOST_NAME_MAX];
+       char base_path[LTTNG_PATH_MAX];
        uint32_t live_timer;
 
        /* Session in snapshot mode. */
@@ -125,7 +126,7 @@ struct relay_session {
 };
 
 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,
index e8dfbadbf72fbc8a9edee2da53abe0f0f1990c31..0596033b1441fda9aaa3ca20e613be5923d4b714 100644 (file)
@@ -1038,7 +1038,7 @@ static enum lttng_error_code send_consumer_relayd_socket(
                struct consumer_output *consumer,
                struct consumer_socket *consumer_sock,
                const char *session_name, const char *hostname,
-               int session_live_timer,
+               const char *base_path, int session_live_timer,
                const uint64_t *current_chunk_id,
                time_t session_creation_time)
 {
@@ -1068,8 +1068,9 @@ static enum lttng_error_code send_consumer_relayd_socket(
        /* Send relayd socket to consumer. */
        ret = consumer_send_relayd_socket(consumer_sock, rsock, consumer,
                        relayd_uri->stype, session_id,
-                       session_name, hostname, session_live_timer,
-                       current_chunk_id, session_creation_time);
+                       session_name, hostname, base_path,
+                       session_live_timer, current_chunk_id,
+                       session_creation_time);
        if (ret < 0) {
                status = LTTNG_ERR_ENABLE_CONSUMER_FAIL;
                goto close_sock;
@@ -1116,7 +1117,7 @@ static enum lttng_error_code send_consumer_relayd_sockets(
                enum lttng_domain_type domain,
                unsigned int session_id, struct consumer_output *consumer,
                struct consumer_socket *sock, const char *session_name,
-               const char *hostname, int session_live_timer,
+               const char *hostname, const char *base_path, int session_live_timer,
                const uint64_t *current_chunk_id, time_t session_creation_time)
 {
        enum lttng_error_code status = LTTNG_OK;
@@ -1128,7 +1129,7 @@ static enum lttng_error_code send_consumer_relayd_sockets(
        if (!sock->control_sock_sent) {
                status = send_consumer_relayd_socket(session_id,
                                &consumer->dst.net.control, consumer, sock,
-                               session_name, hostname, session_live_timer,
+                               session_name, hostname, base_path, session_live_timer,
                                current_chunk_id, session_creation_time);
                if (status != LTTNG_OK) {
                        goto error;
@@ -1139,7 +1140,7 @@ static enum lttng_error_code send_consumer_relayd_sockets(
        if (!sock->data_sock_sent) {
                status = send_consumer_relayd_socket(session_id,
                                &consumer->dst.net.data, consumer, sock,
-                               session_name, hostname, session_live_timer,
+                               session_name, hostname, base_path, session_live_timer,
                                current_chunk_id, session_creation_time);
                if (status != LTTNG_OK) {
                        goto error;
@@ -1195,6 +1196,7 @@ int cmd_setup_relayd(struct ltt_session *session)
                        ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session->id,
                                        usess->consumer, socket,
                                        session->name, session->hostname,
+                                       session->base_path,
                                        session->live_timer,
                                        current_chunk_id.is_set ? &current_chunk_id.value : NULL,
                                        session->creation_time);
@@ -1219,6 +1221,7 @@ int cmd_setup_relayd(struct ltt_session *session)
                        ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session->id,
                                        ksess->consumer, socket,
                                        session->name, session->hostname,
+                                       session->base_path,
                                        session->live_timer,
                                        current_chunk_id.is_set ? &current_chunk_id.value : NULL,
                                        session->creation_time);
@@ -2872,6 +2875,7 @@ enum lttng_error_code cmd_create_session_from_descriptor(
        const char *session_name;
        struct ltt_session *new_session = NULL;
        enum lttng_session_descriptor_status descriptor_status;
+       const char *base_path;
 
        session_lock_list();
        if (home_path) {
@@ -2894,8 +2898,13 @@ enum lttng_error_code cmd_create_session_from_descriptor(
                ret_code = LTTNG_ERR_INVALID;
                goto end;
        }
+       ret = lttng_session_descriptor_get_base_path(descriptor, &base_path);
+       if (ret) {
+               ret_code = LTTNG_ERR_INVALID;
+               goto end;
+       }
        ret_code = session_create(session_name, creds->uid, creds->gid,
-                       &new_session);
+                       base_path, &new_session);
        if (ret_code != LTTNG_OK) {
                goto end;
        }
@@ -4229,6 +4238,7 @@ static enum lttng_error_code set_relayd_for_snapshot(
        struct lttng_ht_iter iter;
        struct consumer_socket *socket;
        LTTNG_OPTIONAL(uint64_t) current_chunk_id = {};
+       const char *base_path;
 
        assert(output);
        assert(session);
@@ -4255,6 +4265,16 @@ static enum lttng_error_code set_relayd_for_snapshot(
                goto error;
        }
 
+       /*
+        * The snapshot record URI base path overrides the session
+        * base path.
+        */
+       if (output->dst.net.control.subdir[0] != '\0') {
+               base_path = output->dst.net.control.subdir;
+       } else {
+               base_path = session->base_path;
+       }
+
        /*
         * For each consumer socket, create and send the relayd object of the
         * snapshot output.
@@ -4266,6 +4286,7 @@ static enum lttng_error_code set_relayd_for_snapshot(
                status = send_consumer_relayd_sockets(0, session->id,
                                output, socket,
                                session->name, session->hostname,
+                               base_path,
                                session->live_timer,
                                current_chunk_id.is_set ? &current_chunk_id.value : NULL,
                                session->creation_time);
index c90436c574270e2716372853b4a4c86dbbc80578..3e23d3255b3fa3334b51d789c1d7bf8a516ecd3d 100644 (file)
@@ -1075,8 +1075,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
                struct lttcomm_relayd_sock *rsock, struct consumer_output *consumer,
                enum lttng_stream_type type, uint64_t session_id,
                const char *session_name, const char *hostname,
-               int session_live_timer, const uint64_t *current_chunk_id,
-               time_t session_creation_time)
+               const char *base_path, int session_live_timer,
+               const uint64_t *current_chunk_id, time_t session_creation_time)
 {
        int ret;
        struct lttcomm_consumer_msg msg;
@@ -1096,7 +1096,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
        if (type == LTTNG_STREAM_CONTROL) {
                ret = relayd_create_session(rsock,
                                &msg.u.relayd_sock.relayd_session_id,
-                               session_name, hostname, session_live_timer,
+                               session_name, hostname, base_path,
+                               session_live_timer,
                                consumer->snapshot, session_id,
                                sessiond_uuid, current_chunk_id,
                                session_creation_time);
index 6fc17ad53737706f3edca3f49bd267d7c7cbe826..37b522a91c153487708c1f1b6afeb45b29f268d4 100644 (file)
@@ -219,8 +219,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
                struct lttcomm_relayd_sock *rsock, struct consumer_output *consumer,
                enum lttng_stream_type type, uint64_t session_id,
                const char *session_name, const char *hostname,
-               int session_live_timer, const uint64_t *current_chunk_id,
-               time_t session_creation_time);
+               const char *base_path, int session_live_timer,
+               const uint64_t *current_chunk_id, time_t session_creation_time);
 int consumer_send_channel_monitor_pipe(struct consumer_socket *consumer_sock,
                int pipe);
 int consumer_send_destroy_relayd(struct consumer_socket *sock,
index 514b11e9919da0c2814aa99096c4bcd99862d892..2a7b8b83bb8d643ecdfcfdbd3c1364e69b562b10 100644 (file)
@@ -851,6 +851,7 @@ void session_release(struct urcu_ref *ref)
        }
        lttng_dynamic_array_reset(&session->destroy_notifiers);
        free(session->last_archived_chunk_name);
+       free(session->base_path);
        free(session);
        if (session_published) {
                /*
@@ -981,7 +982,7 @@ end:
  * Session list lock must be held by the caller.
  */
 enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid,
-               struct ltt_session **out_session)
+               const char *base_path, struct ltt_session **out_session)
 {
        int ret;
        enum lttng_error_code ret_code;
@@ -1104,6 +1105,16 @@ enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid,
                }
        }
 
+       if (base_path) {
+               new_session->base_path = strdup(base_path);
+               if (!new_session->base_path) {
+                       ERR("Failed to allocate base path of session \"%s\"",
+                                       name);
+                       ret_code = LTTNG_ERR_SESSION_FAIL;
+                       goto error;
+               }
+       }
+
        new_session->uid = uid;
        new_session->gid = gid;
 
index 6b7d63c3cba5084d9425f37732cc78277826d19c..cd0f99968a897df40c059669d8200a303003e52a 100644 (file)
@@ -184,11 +184,13 @@ struct ltt_session {
        char *last_archived_chunk_name;
        LTTNG_OPTIONAL(uint64_t) last_archived_chunk_id;
        struct lttng_dynamic_array destroy_notifiers;
+       /* Session base path override. Set non-null. */
+       char *base_path;
 };
 
 /* Prototypes */
 enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid,
-               struct ltt_session **out_session);
+               const char *base_path, struct ltt_session **out_session);
 void session_lock(struct ltt_session *session);
 void session_lock_list(void);
 int session_trylock_list(void);
index 1b0a8e42a19d0094793aad10aecfdcb9b467cd8e..51de7b82f4a2216f780b15e13c2c9ec899a1b73e 100644 (file)
@@ -122,29 +122,32 @@ error:
 }
 
 /*
- * Starting from 2.11, RELAYD_CREATE_SESSION payload (session_name & hostname)
- * have no length restriction on the sender side.
+ * Starting from 2.11, RELAYD_CREATE_SESSION payload (session_name,
+ * hostname, and base_path) have no length restriction on the sender side.
  * Length for both payloads is stored in the msg struct. A new dynamic size
  * payload size is introduced.
  */
 static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock,
                const char *session_name, const char *hostname,
-               int session_live_timer, unsigned int snapshot,
-               uint64_t sessiond_session_id, const lttng_uuid sessiond_uuid,
-               const uint64_t *current_chunk_id,
+               const char *base_path, int session_live_timer,
+               unsigned int snapshot, uint64_t sessiond_session_id,
+               const lttng_uuid sessiond_uuid, const uint64_t *current_chunk_id,
                time_t creation_time)
 {
        int ret;
        struct lttcomm_relayd_create_session_2_11 *msg = NULL;
        size_t session_name_len;
        size_t hostname_len;
+       size_t base_path_len;
        size_t msg_length;
+       char *dst;
 
        /* The two names are sent with a '\0' delimiter between them. */
        session_name_len = strlen(session_name) + 1;
        hostname_len = strlen(hostname) + 1;
+       base_path_len = base_path ? strlen(base_path) + 1 : 0;
 
-       msg_length = sizeof(*msg) + session_name_len + hostname_len;
+       msg_length = sizeof(*msg) + session_name_len + hostname_len + base_path_len;
        msg = zmalloc(msg_length);
        if (!msg) {
                PERROR("zmalloc create_session_2_11 command message");
@@ -158,11 +161,21 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock,
        assert(hostname_len <= UINT32_MAX);
        msg->hostname_len = htobe32(hostname_len);
 
-       if (lttng_strncpy(msg->names, session_name, session_name_len)) {
+       assert(base_path_len <= UINT32_MAX);
+       msg->base_path_len = htobe32(base_path_len);
+
+       dst = msg->names;
+       if (lttng_strncpy(dst, session_name, session_name_len)) {
+               ret = -1;
+               goto error;
+       }
+       dst += session_name_len;
+       if (lttng_strncpy(dst, hostname, hostname_len)) {
                ret = -1;
                goto error;
        }
-       if (lttng_strncpy(msg->names + session_name_len, hostname, hostname_len)) {
+       dst += hostname_len;
+       if (base_path && lttng_strncpy(dst, base_path, base_path_len)) {
                ret = -1;
                goto error;
        }
@@ -249,7 +262,7 @@ error:
 int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                uint64_t *relayd_session_id,
                const char *session_name, const char *hostname,
-               int session_live_timer,
+               const char *base_path, int session_live_timer,
                unsigned int snapshot, uint64_t sessiond_session_id,
                const lttng_uuid sessiond_uuid,
                const uint64_t *current_chunk_id,
@@ -273,7 +286,7 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock,
        } else {
                /* From 2.11 to ... */
                ret = relayd_create_session_2_11(rsock, session_name,
-                               hostname, session_live_timer, snapshot,
+                               hostname, base_path, session_live_timer, snapshot,
                                sessiond_session_id, sessiond_uuid,
                                current_chunk_id, creation_time);
        }
index 9aa7abb7b28fb59d23ee48ad3390d15f5cec147a..6dc5d0044aa35f38de03cd9caa112db19f013825 100644 (file)
@@ -42,7 +42,7 @@ int relayd_close(struct lttcomm_relayd_sock *sock);
 int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                uint64_t *relayd_session_id,
                const char *session_name, const char *hostname,
-               int session_live_timer,
+               const char *base_path, int session_live_timer,
                unsigned int snapshot, uint64_t sessiond_session_id,
                const lttng_uuid sessiond_uuid,
                const uint64_t *current_chunk_id,
index 6f0a357e3e04a25eee7173e08a31c5114e4eefa4..b5fdb0677f8153d00e1c8517f16816e9e02dbb69 100644 (file)
@@ -1178,3 +1178,22 @@ int lttng_session_descriptor_assign(
 end:
        return ret;
 }
+
+LTTNG_HIDDEN
+int lttng_session_descriptor_get_base_path(struct lttng_session_descriptor *dst,
+               const char **_base_path)
+{
+       switch (dst->output_type) {
+       case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK:
+       {
+               *_base_path = dst->output.network.control->subdir[0] ?
+                               dst->output.network.control->subdir : NULL;
+               break;
+       }
+       case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL:
+       case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE:
+               *_base_path = NULL;
+               break;
+       }
+       return 0;
+}
index b22cdf4c51881b5b06289e2decdfaa1f15e887dd..3bdff8705f88b4a6b0aafeaa13be64b7b16fe102 100644 (file)
@@ -206,6 +206,8 @@ struct lttcomm_relayd_create_session_2_4 {
 struct lttcomm_relayd_create_session_2_11 {
        uint32_t session_name_len;
        uint32_t hostname_len;
+       /* Optional, set to 0 to indicate it is not user-specified. */
+       uint32_t base_path_len;
        uint32_t live_timer;
        uint8_t snapshot;
        /* Sessiond instance UUID */
@@ -215,7 +217,7 @@ struct lttcomm_relayd_create_session_2_11 {
        /* Session creation time, in seconds since UNIX Epoch. */
        uint64_t creation_time;
        LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED current_chunk_id;
-       /* Contains the session_name and hostname */
+       /* Contains the session_name, hostname, base_path. */
        char names[];
 } LTTNG_PACKED;
 
index cdb1bb88d7046cbe46218324db8031deddde00d1..c7ad4ec71be3d70b87100be069bab9c328d1c445 100644 (file)
@@ -132,7 +132,7 @@ static int create_one_session(char *name)
        struct ltt_session *session = NULL;
 
        session_lock_list();
-       ret_code = session_create(name, geteuid(), getegid(), &session);
+       ret_code = session_create(name, geteuid(), getegid(), NULL, &session);
        session_put(session);
        if (ret_code == LTTNG_OK) {
                /* Validate */
@@ -292,7 +292,7 @@ void test_session_name_generation(void)
        const char *expected_session_name_prefix = DEFAULT_SESSION_NAME;
 
        session_lock_list();
-       ret_code = session_create(NULL, geteuid(), getegid(), &session);
+       ret_code = session_create(NULL, geteuid(), getegid(), NULL, &session);
        ok(ret_code == LTTNG_OK,
                "Create session with a NULL name (auto-generate a name)");
        if (!session) {
This page took 0.037966 seconds and 4 git commands to generate.