+ return pathname;
+
+error:
+ free(pathname);
+ return NULL;
+}
+
+/*
+ * Send a single channel to the consumer using command ADD_CHANNEL.
+ *
+ * Consumer socket lock MUST be acquired before calling this.
+ */
+static int ask_channel_creation(struct ust_app_session *ua_sess,
+ struct ust_app_channel *ua_chan, struct consumer_output *consumer,
+ struct consumer_socket *socket, struct ust_registry_session *registry)
+{
+ int ret;
+ uint32_t chan_id;
+ uint64_t key, chan_reg_key;
+ char *pathname = NULL;
+ struct lttcomm_consumer_msg msg;
+ struct ust_registry_channel *chan_reg;
+
+ assert(ua_sess);
+ assert(ua_chan);
+ assert(socket);
+ assert(consumer);
+ assert(registry);
+
+ DBG2("Asking UST consumer for channel");
+
+ /* Get and create full trace path of session. */
+ pathname = setup_trace_path(consumer, ua_sess);
+ if (!pathname) {
+ ret = -1;
+ goto error;
+ }
+
+ /* Depending on the buffer type, a different channel key is used. */
+ if (ua_sess->buffer_type == LTTNG_BUFFER_PER_UID) {
+ chan_reg_key = ua_chan->tracing_channel_id;
+ } else {
+ chan_reg_key = ua_chan->key;
+ }
+
+ if (ua_chan->attr.type == LTTNG_UST_CHAN_METADATA) {
+ chan_id = -1U;
+ } else {
+ chan_reg = ust_registry_channel_find(registry, chan_reg_key);
+ assert(chan_reg);
+ chan_id = chan_reg->chan_id;
+ }
+
+ consumer_init_ask_channel_comm_msg(&msg,
+ ua_chan->attr.subbuf_size,
+ ua_chan->attr.num_subbuf,
+ ua_chan->attr.overwrite,
+ ua_chan->attr.switch_timer_interval,
+ ua_chan->attr.read_timer_interval,
+ (int) ua_chan->attr.output,
+ (int) ua_chan->attr.type,
+ ua_sess->tracing_id,
+ pathname,
+ ua_chan->name,
+ ua_sess->euid,
+ ua_sess->egid,
+ consumer->net_seq_index,
+ ua_chan->key,
+ registry->uuid,
+ chan_id,
+ ua_chan->tracefile_size,
+ ua_chan->tracefile_count);
+
+ health_code_update();
+
+ ret = lttcomm_send_unix_sock(socket->fd, &msg, sizeof(msg));
+ if (ret < 0) {
+ goto error;
+ }
+
+ ret = consumer_recv_status_channel(socket, &key,
+ &ua_chan->expected_stream_count);
+ if (ret < 0) {
+ goto error;
+ }
+ /* Communication protocol error. */
+ assert(key == ua_chan->key);
+ /* We need at least one where 1 stream for 1 cpu. */
+ assert(ua_chan->expected_stream_count > 0);
+
+ DBG2("UST ask channel %" PRIu64 " successfully done with %u stream(s)", key,
+ ua_chan->expected_stream_count);
+
+error:
+ free(pathname);
+ health_code_update();
+ return ret;
+}