#ifndef _LIBLTTNGCTL_H
#define _LIBLTTNGCTL_H
+#include <limits.h>
+
/* Default unix group name for tracing.
*/
#define DEFAULT_TRACING_GROUP "tracing"
*/
#define LTTNG_SESSIOND_PATH_ENV "LTTNG_SESSIOND_PATH"
-/*
- * From libuuid
+/* From libuuid
*/
#define UUID_STR_LEN 37
+/* Simple structure representing a session.
+ */
+struct lttng_session {
+ char name[NAME_MAX];
+ char uuid[UUID_STR_LEN];
+};
+
extern int lttng_create_session(const char *name, char *session_id);
extern int lttng_connect_sessiond(void);
extern int lttng_set_tracing_group(const char *name);
extern int lttng_check_session_daemon(void);
extern const char *lttng_get_readable_code(int code);
extern size_t lttng_ust_list_apps(pid_t **pids);
+extern size_t lttng_list_sessions(struct lttng_session **sessions);
#endif /* _LIBLTTNGCTL_H */
return ret;
}
+/*
+ * lttng_list_sessions
+ *
+ * Ask the session daemon for all available sessions.
+ *
+ * Return number of sessions
+ */
+size_t lttng_list_sessions(struct lttng_session **sessions)
+{
+ int ret, first = 0;
+ size_t size = 0;
+ struct lttng_session *ls = NULL;
+
+ lsm.cmd_type = LTTNG_LIST_SESSIONS;
+
+ ret = ask_sessiond();
+ if (ret < 0) {
+ goto error;
+ }
+
+ do {
+ ret = recvfrom_sessiond();
+ if (ret < 0) {
+ goto error;
+ }
+
+ if (first == 0) {
+ first = 1;
+ size = llm.num_pckt;
+ ls = malloc(sizeof(struct lttng_session) * size);
+ }
+ strncpy(ls[size - llm.num_pckt].name, llm.u.list_sessions.name,
+ sizeof(ls[size - llm.num_pckt].name));
+ strncpy(ls[size - llm.num_pckt].uuid, llm.u.list_sessions.uuid,
+ sizeof(ls[size - llm.num_pckt].uuid));
+ } while ((llm.num_pckt - 1) != 0);
+
+ *sessions = ls;
+
+ return size;
+
+error:
+ return ret;
+}
+
/*
* lttng_connect_sessiond
*
[ LTTCOMM_ERR_INDEX(LTTCOMM_NO_SESSION) ] = "No session found",
[ LTTCOMM_ERR_INDEX(LTTCOMM_LIST_FAIL) ] = "Unable to list traceable apps",
[ LTTCOMM_ERR_INDEX(LTTCOMM_NO_APPS) ] = "No traceable apps found",
+ [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_SESS) ] = "No session found",
};
/*
LTTCOMM_START_FAIL, /* Start tracing fail */
LTTCOMM_LIST_FAIL, /* Listing apps fail */
LTTCOMM_NO_APPS, /* No traceable application */
+ LTTCOMM_NO_SESS, /* No sessions available */
LTTCOMM_NR, /* Last element */
};
struct {
pid_t pid;
} list_apps;
+ /* LTTNG_LIST_SESSIONS */
+ struct {
+ char name[NAME_MAX];
+ char uuid[37]; /* See libuuid not exported size UUID_STR_LEN */
+ } list_sessions;
} u;
};
static int init_daemon_socket(void);
static int process_client_msg(int sock, struct lttcomm_session_msg*);
static int send_unix_sock(int sock, void *buf, size_t len);
+static size_t ust_list_apps(pid_t **pids);
static void *thread_manage_clients(void *);
static void *thread_manage_apps(void *);
break;
}
+ case LTTNG_LIST_SESSIONS:
+ {
+ struct ltt_session *iter = NULL;
+
+ llm.num_pckt = session_count;
+ if (llm.num_pckt == 0) {
+ ret = LTTCOMM_NO_SESS;
+ goto error;
+ }
+
+ cds_list_for_each_entry(iter, <t_session_list.head, list) {
+ uuid_unparse(iter->uuid, llm.u.list_sessions.uuid);
+ strncpy(llm.u.list_sessions.name, iter->name,
+ sizeof(llm.u.list_sessions.name));
+ ret = send_unix_sock(sock, (void*) &llm, sizeof(llm));
+ if (ret < 0) {
+ goto send_error;
+ }
+ llm.num_pckt--;
+ }
+
+ break;
+ }
default:
{
/* Undefined command */
/* Prototypes */
static int process_client_opt(void);
static int process_opt_list_apps(void);
+static int process_opt_list_sessions(void);
static void sighandler(int sig);
static int set_signal_handler(void);
}
}
+ if (opt_list_session) {
+ ret = process_opt_list_sessions();
+ if (ret < 0) {
+ goto end;
+ }
+ }
+
return 0;
end:
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 *sess;
+
+ count = lttng_list_sessions(&sess);
+ if (count < 0) {
+ ret = count;
+ goto error;
+ }
+
+ MSG("Available sessions [Name (uuid)]:");
+ for (i = 0; i < count; i++) {
+ MSG("\tName: %s (uuid: %s)", sess[i].name, sess[i].uuid);
+ }
+
+ free(sess);
+ MSG("\nTo select a session, use --session UUID.");
+
+ return 0;
+
+error:
+ return ret;
+}
+
/*
* process_opt_list_apps
*
extern char *opt_sessiond_path;
extern int opt_list_apps;
extern int opt_no_sessiond;
+extern int opt_list_session;
#define SESSIOND_PATH_NUM 6
int opt_verbose = 0;
int opt_list_apps = 0;
int opt_no_sessiond = 0;
+int opt_list_session = 0;
enum {
OPT_HELP = 42,
{"list-apps", 'l', POPT_ARG_VAL, &opt_list_apps, 1, 0},
{"no-sessiond", 0, POPT_ARG_VAL, &opt_no_sessiond, 1, 0},
{"sessiond-path", 0, POPT_ARG_STRING, &opt_sessiond_path, 0, 0},
+ {"list-session", 0, POPT_ARG_VAL, &opt_list_session, 1, 0},
{0, 0, 0, 0, 0, 0}
};
fprintf(ofp, " --no-sessiond Don't spawn a session daemon.\n");
fprintf(ofp, " --sessiond-path Session daemon full path\n");
fprintf(ofp, "\n");
+ fprintf(ofp, "Session options:\n");
+ fprintf(ofp, " --list-session List all available sessions\n");
+ fprintf(ofp, "\n");
fprintf(ofp, "Tracing options:\n");
//fprintf(ofp, " --session [NAME] Specify tracing session. If no NAME is given\n");
//fprintf(ofp, " or option is ommited, a session will be created\n");