- /* Send metadata stream fd */
- lkm.cmd_type = LTTNG_CONSUMER_ADD_STREAM;
- lkm.u.stream.channel_key = session->metadata->fd;
- lkm.u.stream.stream_key = session->metadata_stream_fd;
- lkm.u.stream.state = LTTNG_CONSUMER_ACTIVE_STREAM;
- lkm.u.stream.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
- lkm.u.stream.mmap_len = 0; /* for kernel */
- lkm.u.stream.uid = session->uid;
- lkm.u.stream.gid = session->gid;
- strncpy(lkm.u.stream.path_name, session->metadata->pathname,
- PATH_MAX - 1);
- lkm.u.stream.path_name[PATH_MAX - 1] = '\0';
-
- DBG("Sending metadata stream %d to consumer", lkm.u.stream.stream_key);
- ret = lttcomm_send_unix_sock(sock, &lkm, sizeof(lkm));
+ /* Prep stream consumer message */
+ consumer_init_stream_comm_msg(&lkm, LTTNG_CONSUMER_ADD_STREAM,
+ channel->fd,
+ stream->fd,
+ stream->state,
+ channel->channel->attr.output,
+ 0, /* Kernel */
+ session->uid,
+ session->gid,
+ consumer->net_seq_index,
+ 0, /* Metadata flag unset */
+ stream->name,
+ pathname,
+ session->id);
+
+ health_code_update(&health_thread_kernel);
+
+ /* Send stream and file descriptor */
+ ret = consumer_send_stream(sock, consumer, &lkm, &stream->fd, 1);
+ if (ret < 0) {
+ goto error;
+ }
+
+ health_code_update(&health_thread_kernel);
+
+error:
+ return ret;
+}
+
+/*
+ * Send all stream fds of kernel channel to the consumer.
+ */
+int kernel_consumer_send_channel_stream(struct consumer_socket *sock,
+ struct ltt_kernel_channel *channel, struct ltt_kernel_session *session)
+{
+ int ret;
+ struct ltt_kernel_stream *stream;
+
+ /* Safety net */
+ assert(channel);
+ assert(session);
+ assert(session->consumer);
+ assert(sock);
+
+ /* Bail out if consumer is disabled */
+ if (!session->consumer->enabled) {
+ ret = LTTNG_OK;
+ goto error;
+ }
+
+ DBG("Sending streams of channel %s to kernel consumer",
+ channel->channel->name);
+
+ ret = kernel_consumer_add_channel(sock, channel);
+ if (ret < 0) {
+ goto error;
+ }
+
+ /* Send streams */
+ cds_list_for_each_entry(stream, &channel->stream_list.head, list) {
+ if (!stream->fd) {
+ continue;
+ }
+
+ /* Add stream on the kernel consumer side. */
+ ret = kernel_consumer_add_stream(sock, channel, stream, session);