+error: /* fall through */
+ return ret;
+}
+
+/*
+ * process_kernel_create_trace
+ *
+ * Create a kernel trace.
+ */
+static int process_kernel_create_trace(void)
+{
+ return 0;
+}
+
+/*
+ * 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:
+ return ret;
+}
+
+/*
+ * process_opt_create_session
+ *
+ * Create a new session using the name pass
+ * to the command line.
+ */
+static int process_opt_create_session(void)
+{
+ int ret;
+ char name[NAME_MAX];
+ time_t rawtime;
+ struct tm *timeinfo;
+
+ /* Auto session name creation */
+ if (opt_session_name == NULL) {
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
+ strftime(name, sizeof(name), "auto-%Y%m%d-%H%M%S", timeinfo);
+ session_name = strndup(name, sizeof(name));
+ DBG("Auto session name set to %s", session_name);
+ }
+
+ ret = lttng_create_session(session_name);
+ if (ret < 0) {
+ goto error;
+ }
+
+ MSG("Session created: %s", session_name);
+
+error:
+ return ret;
+}
+
+/*
+ * process_opt_list_sessions
+ *
+ * Get the list of available sessions from
+ * the session daemon and print it to user.
+ */
+static int process_opt_list_sessions(void)
+{
+ int ret, count, i;
+ struct lttng_session *sessions;
+
+ count = lttng_list_sessions(&sessions);
+ DBG("Session count %d", count);
+ if (count < 0) {
+ ret = count;
+ goto error;
+ }
+
+ MSG("Available sessions (UUIDs):");
+ for (i = 0; i < count; i++) {
+ MSG(" %d) %s", i+1, sessions[i].name);
+ }
+
+ free(sessions);
+ MSG("\nTo select a session, use -s, --session UUID.");
+
+ return 0;
+
+error: