+error: /* fall through */
+ return ret;
+}
+
+/*
+ * process_kernel_create_trace
+ *
+ * Create a kernel trace.
+ */
+static int process_kernel_create_trace(void)
+{
+ int ret;
+
+ /* Setup kernel session */
+ ret = lttng_kernel_create_session();
+ if (ret < 0) {
+ goto error;
+ }
+
+ /* Create an empty channel (with no event) */
+ ret = lttng_kernel_create_channel();
+ if (ret < 0) {
+ goto error;
+ }
+
+ /* Opening metadata for session */
+ ret = lttng_kernel_open_metadata();
+ if (ret < 0) {
+ goto error;
+ }
+
+ return 0;
+
+error:
+ return ret;
+}
+
+/*
+ * process_kernel_event
+ *
+ * Enable kernel event from the command line list given.
+ */
+static int process_opt_kernel_event(void)
+{
+ int ret;
+ char *event_name;
+
+ event_name = strtok(opt_event_list, ",");
+ while (event_name != NULL) {
+ DBG("Enabling kernel event %s", event_name);
+ ret = lttng_kernel_enable_event(event_name);
+ if (ret < 0) {
+ ERR("%s %s", lttng_get_readable_code(ret), event_name);
+ } else {
+ MSG("Kernel event %s enabled.", event_name);
+ }
+ /* Next event */
+ event_name = strtok(NULL, ",");
+ }
+
+ return 0;
+}
+
+/*
+ * set_opt_session_info
+ *
+ * Setup session_name, current_uuid, short_str_uuid and
+ * long_str_uuid using the command line options.
+ */
+static void set_opt_session_info(void)
+{
+ if (opt_session_name != NULL) {
+ session_name = strndup(opt_session_name, NAME_MAX);
+ DBG("Session name set to %s", session_name);
+ }
+}
+
+/*
+ * set_session_uuid
+ *
+ * Set current session uuid to the current flow of command(s) using the
+ * session_name.
+ */
+static int set_session_uuid(void)
+{
+ int ret, count, i, found = 0;
+ struct lttng_session *sessions;
+
+ if (!uuid_is_null(current_uuid)) {
+ lttng_set_current_session_uuid(¤t_uuid);
+ goto end;
+ }
+
+ count = lttng_list_sessions(&sessions);
+ if (count < 0) {
+ ret = count;
+ goto error;
+ }
+
+ for (i = 0; i < count; i++) {
+ if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
+ lttng_set_current_session_uuid(&sessions[i].uuid);
+ uuid_copy(current_uuid, sessions[i].uuid);
+ found = 1;
+ break;
+ }
+ }
+
+ free(sessions);
+
+ if (!found) {
+ return -1;
+ }
+
+end:
+ DBG("Session UUID set");
+ return 0;
+
+error:
+ return ret;
+}
+
+/*
+ * process_opt_list_traces
+ *
+ * Get list of all traces for a specific session uuid.
+ */
+static int process_opt_list_traces(void)
+{
+ int ret, i;
+ struct lttng_trace *traces;
+
+ ret = lttng_list_traces(¤t_uuid, &traces);
+ DBG("Number of traces to list %d", ret);
+ if (ret < 0) {
+ goto error;
+ }
+
+ /* No traces */
+ if (ret == 0) {
+ MSG("No traces found.");
+ goto error;
+ }
+
+ MSG("Userspace traces:");
+ for (i = 0; i < ret; i++) {
+ if (traces[i].type == USERSPACE) {
+ MSG("\t%d) %s (pid: %d): %s",
+ i, traces[i].name, traces[i].pid,
+ get_cmdline_by_pid(traces[i].pid));
+ } else {
+ break;
+ }
+ }
+
+ MSG("Kernel traces:");
+ for (;i < ret; i++) {
+ if (traces[i].type == KERNEL) {
+ MSG("\t%d) %s", i, traces[i].name);
+ }
+ }
+
+ free(traces);
+
+error: