+#include "notification-thread-commands.h"
+#include "session.h"
+#include "lttng-sessiond.h"
+
+static char *create_channel_path(struct consumer_output *consumer,
+ uid_t uid, gid_t gid)
+{
+ int ret;
+ char tmp_path[PATH_MAX];
+ char *pathname = NULL;
+
+ assert(consumer);
+
+ /* 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%s",
+ consumer->dst.session_root_path,
+ consumer->chunk_path,
+ consumer->domain_subdir);
+ if (ret < 0) {
+ PERROR("snprintf kernel channel path");
+ goto error;
+ } else if (ret >= sizeof(tmp_path)) {
+ ERR("Kernel channel path exceeds the maximal allowed length of of %zu bytes (%i bytes required) with path \"%s%s%s\"",
+ sizeof(tmp_path), ret,
+ consumer->dst.session_root_path,
+ consumer->chunk_path,
+ consumer->domain_subdir);
+ goto error;
+ }
+ pathname = lttng_strndup(tmp_path, sizeof(tmp_path));
+ if (!pathname) {
+ PERROR("lttng_strndup");
+ goto error;
+ }
+
+ /* Create directory */
+ ret = run_as_mkdir_recursive(pathname, S_IRWXU | S_IRWXG, uid, gid);
+ if (ret < 0) {
+ if (errno != EEXIST) {
+ ERR("Trace directory creation error");
+ goto error;
+ }
+ }
+ DBG3("Kernel local consumer tracefile path: %s", pathname);
+ } else {
+ /* Network output. */
+ ret = snprintf(tmp_path, sizeof(tmp_path), "%s%s",
+ consumer->dst.net.base_dir,
+ consumer->domain_subdir);
+ if (ret < 0) {
+ PERROR("snprintf kernel metadata path");
+ goto error;
+ } else if (ret >= sizeof(tmp_path)) {
+ ERR("Kernel channel path exceeds the maximal allowed length of of %zu bytes (%i bytes required) with path \"%s%s\"",
+ sizeof(tmp_path), ret,
+ consumer->dst.net.base_dir,
+ consumer->domain_subdir);
+ goto error;
+ }
+ pathname = lttng_strndup(tmp_path, sizeof(tmp_path));
+ if (!pathname) {
+ PERROR("lttng_strndup");
+ goto error;
+ }
+ DBG3("Kernel network consumer subdir path: %s", pathname);
+ }
+
+ return pathname;
+
+error:
+ free(pathname);
+ return NULL;
+}