Fix: lttng list command with network path
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index d0b1e17e544ef21b110381ea266f5037172e80f0..495465b6f76ada3b870f3074ec4ee7106a4764b8 100644 (file)
@@ -2418,6 +2418,73 @@ static unsigned int lttng_sessions_count(uid_t uid, gid_t gid)
        return i;
 }
 
+/*
+ * Create a session path used by list_lttng_sessions for the case that the
+ * session consumer is on the network.
+ */
+static int build_network_session_path(char *dst, size_t size,
+               struct ltt_session *session)
+{
+       int ret, kdata_port, udata_port;
+       struct lttng_uri *kuri = NULL, *uuri = NULL, *uri = NULL;
+       char tmp_uurl[PATH_MAX], tmp_urls[PATH_MAX];
+
+       assert(session);
+       assert(dst);
+
+       memset(tmp_urls, 0, sizeof(tmp_urls));
+       memset(tmp_uurl, 0, sizeof(tmp_uurl));
+
+       kdata_port = udata_port = DEFAULT_NETWORK_DATA_PORT;
+
+       if (session->kernel_session && session->kernel_session->consumer) {
+               kuri = &session->kernel_session->consumer->dst.net.control;
+               kdata_port = session->kernel_session->consumer->dst.net.data.port;
+       }
+
+       if (session->ust_session && session->ust_session->consumer) {
+               uuri = &session->ust_session->consumer->dst.net.control;
+               udata_port = session->ust_session->consumer->dst.net.data.port;
+       }
+
+       if (uuri == NULL && kuri == NULL) {
+               uri = &session->consumer->dst.net.control;
+               kdata_port = session->consumer->dst.net.data.port;
+       } else if (kuri && uuri) {
+               ret = uri_compare(kuri, uuri);
+               if (ret) {
+                       /* Not Equal */
+                       uri = kuri;
+                       /* Build uuri URL string */
+                       ret = uri_to_str_url(uuri, tmp_uurl, sizeof(tmp_uurl));
+                       if (ret < 0) {
+                               goto error;
+                       }
+               } else {
+                       uri = kuri;
+               }
+       } else if (kuri && uuri == NULL) {
+               uri = kuri;
+       } else if (uuri && kuri == NULL) {
+               uri = uuri;
+       }
+
+       ret = uri_to_str_url(uri, tmp_urls, sizeof(tmp_urls));
+       if (ret < 0) {
+               goto error;
+       }
+
+       if (strlen(tmp_uurl) > 0) {
+               ret = snprintf(dst, size, "[K]: %s [data: %d] -- [U]: %s [data: %d]",
+                               tmp_urls, kdata_port, tmp_uurl, udata_port);
+       } else {
+               ret = snprintf(dst, size, "%s [data: %d]", tmp_urls, kdata_port);
+       }
+
+error:
+       return ret;
+}
+
 /*
  * Using the session list, filled a lttng_session array to send back to the
  * client for session listing.
@@ -2428,6 +2495,7 @@ static unsigned int lttng_sessions_count(uid_t uid, gid_t gid)
 static void list_lttng_sessions(struct lttng_session *sessions, uid_t uid,
                gid_t gid)
 {
+       int ret;
        unsigned int i = 0;
        struct ltt_session *session;
 
@@ -2444,8 +2512,20 @@ static void list_lttng_sessions(struct lttng_session *sessions, uid_t uid,
                if (!session_access_ok(session, uid, gid)) {
                        continue;
                }
-               strncpy(sessions[i].path, session->path, PATH_MAX);
-               sessions[i].path[PATH_MAX - 1] = '\0';
+
+               if (session->consumer->type == CONSUMER_DST_LOCAL &&
+                               (!session->kernel_session && !session->ust_session)) {
+                       ret = snprintf(sessions[i].path, sizeof(session[i].path), "%s",
+                                       session->consumer->dst.trace_path);
+               } else {
+                       ret = build_network_session_path(sessions[i].path,
+                                       sizeof(session[i].path), session);
+               }
+               if (ret < 0) {
+                       PERROR("snprintf session path");
+                       continue;
+               }
+
                strncpy(sessions[i].name, session->name, NAME_MAX);
                sessions[i].name[NAME_MAX - 1] = '\0';
                sessions[i].enabled = session->enabled;
@@ -2706,6 +2786,12 @@ static int add_uri_to_consumer(struct consumer_output *consumer,
                if (ret < 0) {
                        ret = LTTCOMM_FATAL;
                        goto error;
+               } else if (ret == 1) {
+                       /*
+                        * URI was the same in the consumer so we do not append the subdir
+                        * again so to not duplicate output dir.
+                        */
+                       goto error;
                }
 
                if (uri->stype == LTTNG_STREAM_CONTROL && strlen(uri->subdir) == 0) {
@@ -3687,8 +3773,6 @@ static int cmd_create_session_uri(char *name, struct lttng_uri *uris,
        int ret;
        char *path = NULL;
        struct ltt_session *session;
-       //struct consumer_output *consumer = NULL;
-       //struct lttng_uri *ctrl_uri, *data_uri = NULL;
 
        assert(name);
 
This page took 0.023862 seconds and 4 git commands to generate.