Document consumer socket locking assumptions
[lttng-tools.git] / src / bin / lttng-sessiond / consumer.c
index 8290b5faf05944fdae379a6b812f0a622020903e..960fe8e46439a6447c17198f0732c08b507bee4a 100644 (file)
@@ -731,6 +731,8 @@ error:
 
 /*
  * Send file descriptor to consumer via sock.
+ *
+ * The consumer socket lock must be held by the caller.
  */
 int consumer_send_fds(struct consumer_socket *sock, int *fds, size_t nb_fd)
 {
@@ -739,6 +741,7 @@ int consumer_send_fds(struct consumer_socket *sock, int *fds, size_t nb_fd)
        assert(fds);
        assert(sock);
        assert(nb_fd > 0);
+       assert(pthread_mutex_trylock(sock->lock) == EBUSY);
 
        ret = lttcomm_send_fds_unix_sock(*sock->fd_ptr, fds, nb_fd);
        if (ret < 0) {
@@ -755,6 +758,8 @@ error:
 
 /*
  * Consumer send communication message structure to consumer.
+ *
+ * The consumer socket lock must be held by the caller.
  */
 int consumer_send_msg(struct consumer_socket *sock,
                struct lttcomm_consumer_msg *msg)
@@ -778,6 +783,8 @@ error:
 
 /*
  * Consumer send channel communication message structure to consumer.
+ *
+ * The consumer socket lock must be held by the caller.
  */
 int consumer_send_channel(struct consumer_socket *sock,
                struct lttcomm_consumer_msg *msg)
@@ -986,6 +993,8 @@ error:
 /*
  * Send relayd socket to consumer associated with a session name.
  *
+ * The consumer socket lock must be held by the caller.
+ *
  * On success return positive value. On error, negative value.
  */
 int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
@@ -1403,7 +1412,9 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key,
        }
 
        health_code_update();
+       pthread_mutex_lock(socket->lock);
        ret = consumer_send_msg(socket, &msg);
+       pthread_mutex_unlock(socket->lock);
        if (ret < 0) {
                goto error;
        }
This page took 0.023565 seconds and 4 git commands to generate.