X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=liblttngctl%2Fliblttngctl.c;h=fda45ae10d2bc423dea61b94f3a2521c5c074b0c;hp=8258874dc56efd23bd679181be6e1a57c6a37f0e;hb=ca95a21633510288dbb18a3cd8825195e5cbb4f3;hpb=fac6795d6e2c60e79bdc7dab42da94d2025a57d3 diff --git a/liblttngctl/liblttngctl.c b/liblttngctl/liblttngctl.c index 8258874dc..fda45ae10 100644 --- a/liblttngctl/liblttngctl.c +++ b/liblttngctl/liblttngctl.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2011 David Goulet +/* + * Copyright (C) 2011 David Goulet * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -13,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * */ #define _GNU_SOURCE @@ -34,60 +34,122 @@ static int sessiond_socket; static char sessiond_sock_path[PATH_MAX]; /* Communication structure to ltt-sessiond */ -static struct lttcomm_lttng_msg llm; static struct lttcomm_session_msg lsm; /* Prototypes */ static int check_tracing_group(const char *grp_name); -static int ask_sessiond(void); +static int ask_sessiond(enum lttcomm_command_type lct, void **buf); +static int recv_data_sessiond(void *buf, size_t len); +static int send_data_sessiond(void); static int set_session_daemon_path(void); -static void reset_data_struct(void); - -int lttng_connect_sessiond(void); -int lttng_create_session(const char *name, char *session_id); -int lttng_check_session_daemon(void); /* Variables */ static char *tracing_group; static int connected; /* - * ask_sessiond + * send_data_sessiond * - * Send lttcomm_session_msg to the daemon and wait - * for the reply. Data replied will be put in llm + * Send lttcomm_session_msg to the session daemon. * * On success, return 0 * On error, return error code */ -static int ask_sessiond(void) +static int send_data_sessiond(void) { int ret; if (!connected) { - ret = -ECONNREFUSED; - goto error; + ret = -ENOTCONN; + goto end; } ret = lttcomm_send_unix_sock(sessiond_socket, &lsm, sizeof(lsm)); + +end: + return ret; +} + +/* + * recv_data_sessiond + * + * Receive data from the sessiond socket. + * + * On success, return 0 + * On error, return recv() error code + */ +static int recv_data_sessiond(void *buf, size_t len) +{ + int ret; + + if (!connected) { + ret = -ENOTCONN; + goto end; + } + + ret = lttcomm_recv_unix_sock(sessiond_socket, buf, len); + if (ret < 0) { + goto end; + } + +end: + return ret; +} + +/* + * ask_sessiond + * + * Ask the session daemon a specific command + * and put the data into buf. + * + * Return size of data (only payload, not header). + */ +static int ask_sessiond(enum lttcomm_command_type lct, void **buf) +{ + int ret; + size_t size; + void *data = NULL; + struct lttcomm_lttng_msg llm; + + lsm.cmd_type = lct; + + /* Send command to session daemon */ + ret = send_data_sessiond(); if (ret < 0) { - goto error; + goto end; } - ret = lttcomm_recv_unix_sock(sessiond_socket, &llm, sizeof(llm)); + /* Get header from data transmission */ + ret = recv_data_sessiond(&llm, sizeof(llm)); if (ret < 0) { - goto error; + goto end; } - /* Check return code */ + /* Check error code if OK */ if (llm.ret_code != LTTCOMM_OK) { ret = -llm.ret_code; - goto error; + goto end; } - return 0; + size = llm.size_payload; + if (size == 0) { + goto end; + } + + data = (void*) malloc(size); + + /* Get payload data */ + ret = recv_data_sessiond(data, size); + if (ret < 0) { + goto end; + } -error: + *buf = data; + ret = size; + +end: + /* Reset lsm data struct */ + memset(&lsm, 0, sizeof(lsm)); return ret; } @@ -106,67 +168,44 @@ const char *lttng_get_readable_code(int code) } /* - * lttng_create_session + * lttng_ust_list_apps * - * Create a tracing session using "name" to the session daemon. - * If no name is given, the auto session creation is set and - * the daemon will take care of finding a name. + * Ask the session daemon for all UST traceable + * applications. * - * On success, return 0 and session_id point to the uuid str. - * On error, negative value is returned. + * Return the number of pids. + * On error, return negative value. */ -int lttng_create_session(const char *name, char *session_id) +int lttng_ust_list_apps(pid_t **pids) { int ret; - lsm.cmd_type = LTTNG_CREATE_SESSION; - if (name == NULL) { - lsm.u.create_session.auto_session = 1; - } else { - strncpy(lsm.session_name, name, strlen(name)); - lsm.u.create_session.auto_session = 0; - } - - /* Ask the session daemon */ - ret = ask_sessiond(); + ret = ask_sessiond(UST_LIST_APPS, (void**) pids); if (ret < 0) { - goto end; + return ret; } - /* Unparse session ID */ - uuid_unparse(llm.session_id, session_id); - -end: - reset_data_struct(); - - return ret; + return ret / sizeof(pid_t); } /* - * lttng_ust_list_apps + * lttng_list_sessions * - * Ask the session daemon for all UST traceable - * applications. + * Ask the session daemon for all available sessions. * - * Return the size of pids. + * Return number of session. + * On error, return negative value. */ -size_t lttng_ust_list_apps(pid_t **pids) +int lttng_list_sessions(struct lttng_session **sessions) { int ret; - lsm.cmd_type = UST_LIST_APPS; - - ret = ask_sessiond(); + ret = ask_sessiond(LTTNG_LIST_SESSIONS, (void**) sessions); if (ret < 0) { - goto error; + return ret; } - *pids = llm.u.list_apps.pids; - - return llm.u.list_apps.size; - -error: - return ret; + return ret / sizeof(struct lttng_session); } /* @@ -236,17 +275,6 @@ int lttng_check_session_daemon(void) return 0; } -/* - * reset_data_struct - * - * Reset session daemon structures. - */ -static void reset_data_struct(void) -{ - memset(&lsm, 0, sizeof(lsm)); - memset(&llm, 0, sizeof(llm)); -} - /* * set_session_daemon_path *