Fix: wrong session id used on relayd lookup
[lttng-tools.git] / src / common / consumer.c
index 63c98350a4772435b50a84ae4b0ac25f4e4f3455..9df0c484c9bfe4c0a29371ed473b07e846f93e77 100644 (file)
@@ -1334,6 +1334,12 @@ static int write_relayd_metadata_id(int fd,
                        PERROR("write metadata stream id");
                }
                DBG3("Consumer failed to write relayd metadata id (errno: %d)", errno);
+               /*
+                * Set ret to a negative value because if ret != sizeof(hdr), we don't
+                * handle writting the missing part so report that as an error and
+                * don't lie to the caller.
+                */
+               ret = -1;
                goto end;
        }
        DBG("Metadata stream id %" PRIu64 " with padding %lu written before data",
@@ -2597,7 +2603,7 @@ void *consumer_thread_sessiond_poll(void *data)
 
        /* Blocking call, waiting for transmission */
        sock = lttcomm_accept_unix_sock(client_socket);
-       if (sock <= 0) {
+       if (sock < 0) {
                WARN("On accept");
                goto end;
        }
@@ -2935,30 +2941,24 @@ end:
 static struct consumer_relayd_sock_pair *find_relayd_by_session_id(uint64_t id)
 {
        struct lttng_ht_iter iter;
-       struct lttng_ht_node_ulong *node;
        struct consumer_relayd_sock_pair *relayd = NULL;
-       struct consumer_relayd_session_id *session_id_map;
-
-       /* Get the session id map. */
-       lttng_ht_lookup(relayd_session_id_ht, (void *)((unsigned long) id), &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
-       if (node == NULL) {
-               goto end;
-       }
-
-       session_id_map = caa_container_of(node, struct consumer_relayd_session_id,
-                       node);
 
        /* Iterate over all relayd since they are indexed by net_seq_idx. */
        cds_lfht_for_each_entry(consumer_data.relayd_ht->ht, &iter.iter, relayd,
                        node.node) {
-               if (relayd->relayd_session_id == session_id_map->relayd_id) {
+               /*
+                * Check by sessiond id which is unique here where the relayd session
+                * id might not be when having multiple relayd.
+                */
+               if (relayd->sessiond_session_id == id) {
                        /* Found the relayd. There can be only one per id. */
-                       break;
+                       goto found;
                }
        }
 
-end:
+       return NULL;
+
+found:
        return relayd;
 }
 
This page took 0.023802 seconds and 4 git commands to generate.