-static
-int relay_add_connection(int fd, struct lttng_poll_event *events,
- struct lttng_ht *relay_connections_ht)
-{
- struct relay_command *relay_connection;
- ssize_t ret;
-
- relay_connection = zmalloc(sizeof(struct relay_command));
- if (relay_connection == NULL) {
- PERROR("Relay command zmalloc");
- goto error;
- }
- ret = lttng_read(fd, relay_connection, sizeof(struct relay_command));
- if (ret < sizeof(struct relay_command)) {
- PERROR("read relay cmd pipe");
- goto error_read;
- }
-
- /*
- * Only used by the control side and the reference is copied inside each
- * stream from that connection. Thus a destroy HT must be done after every
- * stream has been destroyed.
- */
- if (relay_connection->type == RELAY_CONTROL) {
- relay_connection->ctf_traces_ht = lttng_ht_new(0,
- LTTNG_HT_TYPE_STRING);
- if (!relay_connection->ctf_traces_ht) {
- goto error_read;
- }
- }
-
- lttng_ht_node_init_ulong(&relay_connection->sock_n,
- (unsigned long) relay_connection->sock->fd);
- rcu_read_lock();
- lttng_ht_add_unique_ulong(relay_connections_ht,
- &relay_connection->sock_n);
- rcu_read_unlock();
- return lttng_poll_add(events,
- relay_connection->sock->fd,
- LPOLLIN | LPOLLRDHUP);
-
-error_read:
- free(relay_connection);
-error:
- return -1;
-}
-
-static
-void deferred_free_connection(struct rcu_head *head)
-{
- struct relay_command *relay_connection =
- caa_container_of(head, struct relay_command, rcu_node);
-
- lttcomm_destroy_sock(relay_connection->sock);
- free(relay_connection);
-}
-
-static
-void relay_del_connection(struct lttng_ht *relay_connections_ht,
- struct lttng_ht_iter *iter, struct relay_command *relay_connection,
- struct lttng_ht *sessions_ht)