+/*
+ * Send a single stream to the consumer using ADD_STREAM command.
+ */
+static int send_channel_stream(int sock, struct ust_app_channel *uchan,
+ struct ust_app_session *usess, struct ltt_ust_stream *stream,
+ struct consumer_output *consumer, const char *pathname)
+{
+ int ret, fds[2];
+ struct lttcomm_consumer_msg msg;
+
+ /* Safety net */
+ assert(uchan);
+ assert(usess);
+ assert(stream);
+ assert(consumer);
+
+ DBG2("Sending stream %d of channel %s to kernel consumer",
+ stream->obj->shm_fd, uchan->name);
+
+ consumer_init_stream_comm_msg(&msg,
+ LTTNG_CONSUMER_ADD_STREAM,
+ uchan->obj->shm_fd,
+ stream->obj->shm_fd,
+ LTTNG_CONSUMER_ACTIVE_STREAM,
+ DEFAULT_UST_CHANNEL_OUTPUT,
+ stream->obj->memory_map_size,
+ usess->uid,
+ usess->gid,
+ consumer->net_seq_index,
+ 0, /* Metadata flag unset */
+ stream->name,
+ pathname);
+
+ /* Send stream and file descriptor */
+ fds[0] = stream->obj->shm_fd;
+ fds[1] = stream->obj->wait_fd;
+ ret = consumer_send_stream(sock, consumer, &msg, fds, 2);
+ if (ret < 0) {
+ goto error;
+ }
+
+error:
+ return ret;
+}
+
+/*
+ * Send all stream fds of UST channel to the consumer.
+ */
+int ust_consumer_send_channel_streams(int sock,
+ struct ust_app_channel *uchan, struct ust_app_session *usess,
+ struct consumer_output *consumer)
+{
+ int ret;
+ char tmp_path[PATH_MAX];
+ const char *pathname;
+ struct ltt_ust_stream *stream, *tmp;
+
+ DBG("Sending streams of channel %s to UST consumer", uchan->name);
+
+ ret = send_channel(sock, uchan);
+ if (ret < 0) {
+ goto error;
+ }
+
+ /* Get the right path name destination */
+ if (consumer->type == CONSUMER_DST_LOCAL) {
+ /* Set application path to the destination path */
+ ret = snprintf(tmp_path, sizeof(tmp_path), "%s/%s",
+ consumer->dst.trace_path, usess->path);
+ if (ret < 0) {
+ PERROR("snprintf stream path");
+ goto error;