+/*
+ * create_lttng_rundir
+ *
+ * Create the lttng run directory needed for all
+ * global sockets and pipe.
+ */
+static int create_lttng_rundir(void)
+{
+ int ret;
+
+ ret = mkdir(LTTNG_RUNDIR, S_IRWXU | S_IRWXG );
+ if (ret < 0) {
+ ERR("Unable to create " LTTNG_RUNDIR);
+ goto error;
+ }
+
+error:
+ return ret;
+}
+
+/*
+ * init_kernel_tracer
+ *
+ * Setup necessary data for kernel tracer action.
+ */
+static void init_kernel_tracer(void)
+{
+ /* Set the global kernel tracer fd */
+ kernel_tracer_fd = open(DEFAULT_KERNEL_TRACER_PATH, O_RDWR);
+ if (kernel_tracer_fd < 0) {
+ WARN("No kernel tracer available");
+ kernel_tracer_fd = 0;
+ }
+}
+
+/*
+ * set_kconsumerd_sockets
+ *
+ * Setup sockets and directory needed by the kconsumerd
+ * communication with the session daemon.
+ */
+static int set_kconsumerd_sockets(void)
+{
+ int ret;
+
+ if (strlen(kconsumerd_err_unix_sock_path) == 0) {
+ snprintf(kconsumerd_err_unix_sock_path, PATH_MAX, KCONSUMERD_ERR_SOCK_PATH);
+ }
+
+ if (strlen(kconsumerd_cmd_unix_sock_path) == 0) {
+ snprintf(kconsumerd_cmd_unix_sock_path, PATH_MAX, KCONSUMERD_CMD_SOCK_PATH);
+ }
+
+ ret = mkdir(KCONSUMERD_PATH, S_IRWXU | S_IRWXG);
+ if (ret < 0) {
+ ERR("Failed to create " KCONSUMERD_PATH);
+ goto error;
+ }
+
+ /* Create the kconsumerd error unix socket */
+ kconsumerd_err_sock = lttcomm_create_unix_sock(kconsumerd_err_unix_sock_path);
+ if (kconsumerd_err_sock < 0) {
+ ERR("Create unix sock failed: %s", kconsumerd_err_unix_sock_path);
+ ret = -1;
+ goto error;
+ }
+
+ /* File permission MUST be 660 */
+ ret = chmod(kconsumerd_err_unix_sock_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+ if (ret < 0) {
+ ERR("Set file permissions failed: %s", kconsumerd_err_unix_sock_path);
+ perror("chmod");
+ goto error;
+ }
+
+error:
+ return ret;
+}
+