+ /* Get correct path name destination */
+ if (consumer->type == CONSUMER_DST_LOCAL) {
+ /* Set application path to the destination path */
+ ret = snprintf(pathname, PATH_MAX, "%s%s%s",
+ consumer->dst.trace_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, PATH_MAX, "%s%s", 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;
+ }
+
+ if (ua_chan->attr.type == LTTNG_UST_CHAN_METADATA) {
+ chan_id = -1U;
+ /*
+ * Metadata channels shm_path (buffers) are handled within
+ * session daemon. Consumer daemon should not try to create
+ * those buffer files.
+ */
+ } else {
+ chan_reg = ust_registry_channel_find(registry, chan_reg_key);
+ assert(chan_reg);
+ chan_id = chan_reg->chan_id;
+ if (ua_sess->shm_path[0]) {
+ strncpy(shm_path, ua_sess->shm_path, sizeof(shm_path));
+ shm_path[sizeof(shm_path) - 1] = '\0';
+ strncat(shm_path, "/",
+ sizeof(shm_path) - strlen(shm_path) - 1);
+ strncat(shm_path, ua_chan->name,
+ sizeof(shm_path) - strlen(shm_path) - 1);
+ strncat(shm_path, "_",
+ sizeof(shm_path) - strlen(shm_path) - 1);
+ }
+ strncpy(root_shm_path, ua_sess->root_shm_path, sizeof(root_shm_path));
+ root_shm_path[sizeof(root_shm_path) - 1] = '\0';
+ }