+ /* Get correct path name destination */
+ if (consumer->type == CONSUMER_DST_LOCAL) {
+ /* Set application path to the destination path */
+ ret = snprintf(pathname, LTTNG_PATH_MAX, "%s%s%s%s",
+ consumer->dst.session_root_path,
+ consumer->chunk_path,
+ consumer->subdir, ua_sess->path);
+ if (ret < 0) {
+ PERROR("snprintf channel path");
+ goto error;
+ }
+
+ /* Create directory. Ignore if exist. */
+ ret = run_as_mkdir_recursive(pathname, S_IRWXU | S_IRWXG,
+ ua_sess->euid, ua_sess->egid);
+ if (ret < 0) {
+ if (errno != EEXIST) {
+ ERR("Trace directory creation error");
+ goto error;
+ }
+ }
+ } else {
+ ret = snprintf(pathname, LTTNG_PATH_MAX, "%s%s%s%s",
+ consumer->dst.net.base_dir,
+ consumer->chunk_path,
+ consumer->subdir,
+ ua_sess->path);
+ if (ret < 0) {
+ PERROR("snprintf channel path");
+ goto error;
+ }
+ }
+
+ return pathname;
+
+error:
+ free(pathname);
+ return NULL;
+}
+
+/*
+ * Send a single channel to the consumer using command ASK_CHANNEL_CREATION.
+ *
+ * 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, output;
+ uint32_t chan_id;
+ uint64_t key, chan_reg_key;
+ char *pathname = NULL;
+ struct lttcomm_consumer_msg msg;
+ struct ust_registry_channel *chan_reg;
+ char shm_path[PATH_MAX] = "";
+ char root_shm_path[PATH_MAX] = "";
+
+ 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. */
+ if (ua_sess->output_traces) {
+ 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;
+ }