From: Mathieu Desnoyers Date: Thu, 20 Oct 2011 18:36:13 +0000 (-0400) Subject: Implement libustctl X-Git-Tag: v1.9.1~167 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=57773204abc43ed7d4350ac0d641ddbbda1e441e;p=lttng-ust.git Implement libustctl We privatise libringbuffer (not installed anymore), exposing a cleaner API (libustctl) instead. This API will be used by the lttng-tools UST consumer. Signed-off-by: Mathieu Desnoyers --- diff --git a/Makefile.am b/Makefile.am index 0a64094b..b9cc1e7d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ ACLOCAL_AMFLAGS = -I config -SUBDIRS = . snprintf liblttng-ust-comm libringbuffer libust include doc \ - libustjava libustfork tests +SUBDIRS = . snprintf liblttng-ust-comm libringbuffer libust libustctl \ + include doc libustjava libustfork tests #temporarily disabled # . libustinstr-malloc diff --git a/configure.ac b/configure.ac index 3018d8d9..10e1af44 100644 --- a/configure.ac +++ b/configure.ac @@ -175,6 +175,7 @@ AC_CONFIG_FILES([ liblttng-ust-comm/Makefile libringbuffer/Makefile libust/Makefile + libustctl/Makefile tests/Makefile tests/hello/Makefile tests/ust-basic-tracing/Makefile diff --git a/include/Makefile.am b/include/Makefile.am index df20225a..d3869ab9 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -5,6 +5,7 @@ nobase_include_HEADERS = \ ust/lttng-tracepoint-event.h \ ust/lttng-tracepoint-event-reset.h \ ust/lttng-events.h \ + ust/lttng-ust-ctl.h \ ust/version.h \ ust/lttng-ust-abi.h \ ust/ringbuffer-abi.h \ diff --git a/include/lttng-ust-comm.h b/include/lttng-ust-comm.h index 2e5c7173..b571832c 100644 --- a/include/lttng-ust-comm.h +++ b/include/lttng-ust-comm.h @@ -27,7 +27,7 @@ */ #include -#include +#include #include /* @@ -52,83 +52,83 @@ /* Queue size of listen(2) */ #define MAX_LISTEN 10 -/* Get the error code index from 0 since - * LTTCOMM_OK start at 1000 +/* Get the error code index from 0. USTCOMM_ERR starts at 1000. */ -#define LTTCOMM_ERR_INDEX(code) (code - LTTCOMM_OK) +#define USTCOMM_ERR_INDEX(code) (code - USTCOMM_ERR) /* - * lttcomm error code. + * ustcomm error code. */ -enum lttcomm_return_code { - LTTCOMM_OK = 1000, /* Ok */ - LTTCOMM_ERR, /* Unknown Error */ - LTTCOMM_UND, /* Undefine command */ - LTTCOMM_NOT_IMPLEMENTED, /* Command not implemented */ - LTTCOMM_UNKNOWN_DOMAIN, /* Tracing domain not known */ - LTTCOMM_ALLOC_FAIL, /* Trace allocation fail */ - LTTCOMM_NO_SESSION, /* No session found */ - LTTCOMM_CREATE_FAIL, /* Create trace fail */ - LTTCOMM_SESSION_FAIL, /* Create session fail */ - LTTCOMM_START_FAIL, /* Start tracing fail */ - LTTCOMM_STOP_FAIL, /* Stop tracing fail */ - LTTCOMM_LIST_FAIL, /* Listing apps fail */ - LTTCOMM_NO_APPS, /* No traceable application */ - LTTCOMM_SESS_NOT_FOUND, /* Session name not found */ - LTTCOMM_NO_TRACE, /* No trace exist */ - LTTCOMM_FATAL, /* Session daemon had a fatal error */ - LTTCOMM_NO_TRACEABLE, /* Error for non traceable app */ - LTTCOMM_SELECT_SESS, /* Must select a session */ - LTTCOMM_EXIST_SESS, /* Session name already exist */ - LTTCOMM_NO_EVENT, /* No event found */ - LTTCOMM_KERN_NA, /* Kernel tracer unavalable */ - LTTCOMM_KERN_EVENT_EXIST, /* Kernel event already exists */ - LTTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */ - LTTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */ - LTTCOMM_KERN_CHAN_NOT_FOUND, /* Kernel channel not found */ - LTTCOMM_KERN_CHAN_DISABLE_FAIL, /* Kernel disable channel failed */ - LTTCOMM_KERN_CHAN_ENABLE_FAIL, /* Kernel enable channel failed */ - LTTCOMM_KERN_CONTEXT_FAIL, /* Kernel add context failed */ - LTTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */ - LTTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */ - LTTCOMM_KERN_META_FAIL, /* Kernel open metadata failed */ - LTTCOMM_KERN_START_FAIL, /* Kernel start trace failed */ - LTTCOMM_KERN_STOP_FAIL, /* Kernel stop trace failed */ - LTTCOMM_KERN_CONSUMER_FAIL, /* Kernel consumer start failed */ - LTTCOMM_KERN_STREAM_FAIL, /* Kernel create stream failed */ - LTTCOMM_KERN_DIR_FAIL, /* Kernel trace directory creation failed */ - LTTCOMM_KERN_DIR_EXIST, /* Kernel trace directory exist */ - LTTCOMM_KERN_NO_SESSION, /* No kernel session found */ - LTTCOMM_KERN_LIST_FAIL, /* Kernel listing events failed */ - KCONSUMERD_COMMAND_SOCK_READY, /* when kconsumerd command socket ready */ - KCONSUMERD_SUCCESS_RECV_FD, /* success on receiving fds */ - KCONSUMERD_ERROR_RECV_FD, /* error on receiving fds */ - KCONSUMERD_POLL_ERROR, /* Error in polling thread in kconsumerd */ - KCONSUMERD_POLL_NVAL, /* Poll on closed fd */ - KCONSUMERD_POLL_HUP, /* All fds have hungup */ - KCONSUMERD_EXIT_SUCCESS, /* kconsumerd exiting normally */ - KCONSUMERD_EXIT_FAILURE, /* kconsumerd exiting on error */ - KCONSUMERD_OUTFD_ERROR, /* error opening the tracefile */ - KCONSUMERD_SPLICE_EBADF, /* EBADF from splice(2) */ - KCONSUMERD_SPLICE_EINVAL, /* EINVAL from splice(2) */ - KCONSUMERD_SPLICE_ENOMEM, /* ENOMEM from splice(2) */ - KCONSUMERD_SPLICE_ESPIPE, /* ESPIPE from splice(2) */ +enum ustcomm_return_code { + USTCOMM_OK = 0, /* Ok */ + /* Range 1 to 999 used for standard error numbers (errno.h) */ + USTCOMM_ERR = 1000, /* Unknown Error */ + USTCOMM_UND, /* Undefine command */ + USTCOMM_NOT_IMPLEMENTED, /* Command not implemented */ + USTCOMM_UNKNOWN_DOMAIN, /* Tracing domain not known */ + USTCOMM_ALLOC_FAIL, /* Trace allocation fail */ + USTCOMM_NO_SESSION, /* No session found */ + USTCOMM_CREATE_FAIL, /* Create trace fail */ + USTCOMM_SESSION_FAIL, /* Create session fail */ + USTCOMM_START_FAIL, /* Start tracing fail */ + USTCOMM_STOP_FAIL, /* Stop tracing fail */ + USTCOMM_LIST_FAIL, /* Listing apps fail */ + USTCOMM_NO_APPS, /* No traceable application */ + USTCOMM_SESS_NOT_FOUND, /* Session name not found */ + USTCOMM_NO_TRACE, /* No trace exist */ + USTCOMM_FATAL, /* Session daemon had a fatal error */ + USTCOMM_NO_TRACEABLE, /* Error for non traceable app */ + USTCOMM_SELECT_SESS, /* Must select a session */ + USTCOMM_EXIST_SESS, /* Session name already exist */ + USTCOMM_NO_EVENT, /* No event found */ + USTCOMM_KERN_NA, /* Kernel tracer unavalable */ + USTCOMM_KERN_EVENT_EXIST, /* Kernel event already exists */ + USTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */ + USTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */ + USTCOMM_KERN_CHAN_NOT_FOUND, /* Kernel channel not found */ + USTCOMM_KERN_CHAN_DISABLE_FAIL, /* Kernel disable channel failed */ + USTCOMM_KERN_CHAN_ENABLE_FAIL, /* Kernel enable channel failed */ + USTCOMM_KERN_CONTEXT_FAIL, /* Kernel add context failed */ + USTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */ + USTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */ + USTCOMM_KERN_META_FAIL, /* Kernel open metadata failed */ + USTCOMM_KERN_START_FAIL, /* Kernel start trace failed */ + USTCOMM_KERN_STOP_FAIL, /* Kernel stop trace failed */ + USTCOMM_KERN_CONSUMER_FAIL, /* Kernel consumer start failed */ + USTCOMM_KERN_STREAM_FAIL, /* Kernel create stream failed */ + USTCOMM_KERN_DIR_FAIL, /* Kernel trace directory creation failed */ + USTCOMM_KERN_DIR_EXIST, /* Kernel trace directory exist */ + USTCOMM_KERN_NO_SESSION, /* No kernel session found */ + USTCOMM_KERN_LIST_FAIL, /* Kernel listing events failed */ + USTCONSUMER_COMMAND_SOCK_READY, /* when kconsumerd command socket ready */ + USTCONSUMER_SUCCESS_RECV_FD, /* success on receiving fds */ + USTCONSUMER_ERROR_RECV_FD, /* error on receiving fds */ + USTCONSUMER_POLL_ERROR, /* Error in polling thread in kconsumerd */ + USTCONSUMER_POLL_NVAL, /* Poll on closed fd */ + USTCONSUMER_POLL_HUP, /* All fds have hungup */ + USTCONSUMER_EXIT_SUCCESS, /* kconsumerd exiting normally */ + USTCONSUMER_EXIT_FAILURE, /* kconsumerd exiting on error */ + USTCONSUMER_OUTFD_ERROR, /* error opening the tracefile */ + USTCONSUMER_SPLICE_EBADF, /* EBADF from splice(2) */ + USTCONSUMER_SPLICE_EINVAL, /* EINVAL from splice(2) */ + USTCONSUMER_SPLICE_ENOMEM, /* ENOMEM from splice(2) */ + USTCONSUMER_SPLICE_ESPIPE, /* ESPIPE from splice(2) */ /* MUST be last element */ - LTTCOMM_NR, /* Last element */ + USTCOMM_NR, /* Last element */ }; /* * Data structure for the commands sent from sessiond to UST. */ -struct lttcomm_ust_msg { +struct ustcomm_ust_msg { uint32_t handle; uint32_t cmd; union { - struct lttng_ust_tracer_version version; struct lttng_ust_channel channel; struct lttng_ust_stream stream; struct lttng_ust_event event; struct lttng_ust_context context; + struct lttng_ust_tracer_version version; } u; }; @@ -136,10 +136,10 @@ struct lttcomm_ust_msg { * Data structure for the response from UST to the session daemon. * cmd_type is sent back in the reply for validation. */ -struct lttcomm_ust_reply { +struct ustcomm_ust_reply { uint32_t handle; uint32_t cmd; - uint32_t ret_code; /* enum enum lttcomm_return_code */ + uint32_t ret_code; /* enum enum ustcomm_return_code */ uint32_t ret_val; /* return value */ union { struct { @@ -148,19 +148,27 @@ struct lttcomm_ust_reply { struct { uint64_t memory_map_size; } stream; + struct lttng_ust_tracer_version version; } u; }; -extern int lttcomm_create_unix_sock(const char *pathname); -extern int lttcomm_connect_unix_sock(const char *pathname); -extern int lttcomm_accept_unix_sock(int sock); -extern int lttcomm_listen_unix_sock(int sock); -extern int lttcomm_close_unix_sock(int sock); +extern int ustcomm_create_unix_sock(const char *pathname); +extern int ustcomm_connect_unix_sock(const char *pathname); +extern int ustcomm_accept_unix_sock(int sock); +extern int ustcomm_listen_unix_sock(int sock); +extern int ustcomm_close_unix_sock(int sock); /* Send fd(s) over a unix socket. */ -extern ssize_t lttcomm_send_fds_unix_sock(int sock, void *buf, int *fds, +extern ssize_t ustcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, size_t len); -extern ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len); -extern ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len); -extern const char *lttcomm_get_readable_code(enum lttcomm_return_code code); +extern ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len); +extern ssize_t ustcomm_send_unix_sock(int sock, void *buf, size_t len); +extern const char *ustcomm_get_readable_code(int code); +extern int ustcomm_send_app_msg(int sock, struct ustcomm_ust_msg *lum); +extern int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur, + uint32_t expected_handle, uint32_t expected_cmd); +extern int ustcomm_send_app_cmd(int sock, + struct ustcomm_ust_msg *lum, + struct ustcomm_ust_reply *lur); +int ustcomm_recv_fd(int sock); #endif /* _LTTNG_UST_COMM_H */ diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c index 0ce9fc87..bfba3b3c 100644 --- a/liblttng-ust-comm/lttng-ust-comm.c +++ b/liblttng-ust-comm/lttng-ust-comm.c @@ -27,91 +27,88 @@ #include #include #include +#include #include /* * Human readable error message. */ -static const char *lttcomm_readable_code[] = { - [ LTTCOMM_ERR_INDEX(LTTCOMM_OK) ] = "Success", - [ LTTCOMM_ERR_INDEX(LTTCOMM_ERR) ] = "Unknown error", - [ LTTCOMM_ERR_INDEX(LTTCOMM_UND) ] = "Undefined command", - [ LTTCOMM_ERR_INDEX(LTTCOMM_NOT_IMPLEMENTED) ] = "Not implemented", - [ LTTCOMM_ERR_INDEX(LTTCOMM_UNKNOWN_DOMAIN) ] = "Unknown tracing domain", - [ 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_SESS_NOT_FOUND) ] = "Session name not found", - [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_TRACE) ] = "No trace found", - [ LTTCOMM_ERR_INDEX(LTTCOMM_FATAL) ] = "Fatal error of the session daemon", - [ LTTCOMM_ERR_INDEX(LTTCOMM_CREATE_FAIL) ] = "Create trace failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_START_FAIL) ] = "Start trace failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_STOP_FAIL) ] = "Stop trace failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_TRACEABLE) ] = "App is not traceable", - [ LTTCOMM_ERR_INDEX(LTTCOMM_SELECT_SESS) ] = "A session MUST be selected", - [ LTTCOMM_ERR_INDEX(LTTCOMM_EXIST_SESS) ] = "Session name already exist", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_NA) ] = "Kernel tracer not available", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_EVENT_EXIST) ] = "Kernel event already exists", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_SESS_FAIL) ] = "Kernel create session failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_FAIL) ] = "Kernel create channel failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_NOT_FOUND) ] = "Kernel channel not found", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_DISABLE_FAIL) ] = "Disable kernel channel failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_ENABLE_FAIL) ] = "Enable kernel channel failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CONTEXT_FAIL) ] = "Add kernel context failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_ENABLE_FAIL) ] = "Enable kernel event failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_DISABLE_FAIL) ] = "Disable kernel event failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_META_FAIL) ] = "Opening metadata failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_START_FAIL) ] = "Starting kernel trace failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_STOP_FAIL) ] = "Stoping kernel trace failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CONSUMER_FAIL) ] = "Kernel consumer start failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_STREAM_FAIL) ] = "Kernel create stream failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_DIR_FAIL) ] = "Kernel trace directory creation failed", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_DIR_EXIST) ] = "Kernel trace directory already exist", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_NO_SESSION) ] = "No kernel session found", - [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_LIST_FAIL) ] = "Listing kernel events failed", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_COMMAND_SOCK_READY) ] = "Kconsumerd command socket ready", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_SUCCESS_RECV_FD) ] = "Kconsumerd success on receiving fds", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_ERROR_RECV_FD) ] = "Kconsumerd error on receiving fds", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_POLL_ERROR) ] = "Kconsumerd error in polling thread", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_POLL_NVAL) ] = "Kconsumerd polling on closed fd", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_POLL_HUP) ] = "Kconsumerd all fd hung up", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_EXIT_SUCCESS) ] = "Kconsumerd exiting normally", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_EXIT_FAILURE) ] = "Kconsumerd exiting on error", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_OUTFD_ERROR) ] = "Kconsumerd error opening the tracefile", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_SPLICE_EBADF) ] = "Kconsumerd splice EBADF", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_SPLICE_EINVAL) ] = "Kconsumerd splice EINVAL", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_SPLICE_ENOMEM) ] = "Kconsumerd splice ENOMEM", - [ LTTCOMM_ERR_INDEX(KCONSUMERD_SPLICE_ESPIPE) ] = "Kconsumerd splice ESPIPE", - [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_EVENT) ] = "Event not found", +static const char *ustcomm_readable_code[] = { + [ USTCOMM_ERR_INDEX(USTCOMM_ERR) ] = "Unknown error", + [ USTCOMM_ERR_INDEX(USTCOMM_UND) ] = "Undefined command", + [ USTCOMM_ERR_INDEX(USTCOMM_NOT_IMPLEMENTED) ] = "Not implemented", + [ USTCOMM_ERR_INDEX(USTCOMM_UNKNOWN_DOMAIN) ] = "Unknown tracing domain", + [ USTCOMM_ERR_INDEX(USTCOMM_NO_SESSION) ] = "No session found", + [ USTCOMM_ERR_INDEX(USTCOMM_LIST_FAIL) ] = "Unable to list traceable apps", + [ USTCOMM_ERR_INDEX(USTCOMM_NO_APPS) ] = "No traceable apps found", + [ USTCOMM_ERR_INDEX(USTCOMM_SESS_NOT_FOUND) ] = "Session name not found", + [ USTCOMM_ERR_INDEX(USTCOMM_NO_TRACE) ] = "No trace found", + [ USTCOMM_ERR_INDEX(USTCOMM_FATAL) ] = "Fatal error of the session daemon", + [ USTCOMM_ERR_INDEX(USTCOMM_CREATE_FAIL) ] = "Create trace failed", + [ USTCOMM_ERR_INDEX(USTCOMM_START_FAIL) ] = "Start trace failed", + [ USTCOMM_ERR_INDEX(USTCOMM_STOP_FAIL) ] = "Stop trace failed", + [ USTCOMM_ERR_INDEX(USTCOMM_NO_TRACEABLE) ] = "App is not traceable", + [ USTCOMM_ERR_INDEX(USTCOMM_SELECT_SESS) ] = "A session MUST be selected", + [ USTCOMM_ERR_INDEX(USTCOMM_EXIST_SESS) ] = "Session name already exist", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_NA) ] = "UST tracer not available", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_EVENT_EXIST) ] = "UST event already exists", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_SESS_FAIL) ] = "UST create session failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_CHAN_FAIL) ] = "UST create channel failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_CHAN_NOT_FOUND) ] = "UST channel not found", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_CHAN_DISABLE_FAIL) ] = "Disable UST channel failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_CHAN_ENABLE_FAIL) ] = "Enable UST channel failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_CONTEXT_FAIL) ] = "Add UST context failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_ENABLE_FAIL) ] = "Enable UST event failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_DISABLE_FAIL) ] = "Disable UST event failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_META_FAIL) ] = "Opening metadata failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_START_FAIL) ] = "Starting UST trace failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_STOP_FAIL) ] = "Stoping UST trace failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_CONSUMER_FAIL) ] = "UST consumer start failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_STREAM_FAIL) ] = "UST create stream failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_DIR_FAIL) ] = "UST trace directory creation failed", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_DIR_EXIST) ] = "UST trace directory already exist", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_NO_SESSION) ] = "No UST session found", + [ USTCOMM_ERR_INDEX(USTCOMM_KERN_LIST_FAIL) ] = "Listing UST events failed", + [ USTCOMM_ERR_INDEX(USTCONSUMER_COMMAND_SOCK_READY) ] = "UST consumer command socket ready", + [ USTCOMM_ERR_INDEX(USTCONSUMER_SUCCESS_RECV_FD) ] = "UST consumer success on receiving fds", + [ USTCOMM_ERR_INDEX(USTCONSUMER_ERROR_RECV_FD) ] = "UST consumer error on receiving fds", + [ USTCOMM_ERR_INDEX(USTCONSUMER_POLL_ERROR) ] = "UST consumer error in polling thread", + [ USTCOMM_ERR_INDEX(USTCONSUMER_POLL_NVAL) ] = "UST consumer polling on closed fd", + [ USTCOMM_ERR_INDEX(USTCONSUMER_POLL_HUP) ] = "UST consumer all fd hung up", + [ USTCOMM_ERR_INDEX(USTCONSUMER_EXIT_SUCCESS) ] = "UST consumer exiting normally", + [ USTCOMM_ERR_INDEX(USTCONSUMER_EXIT_FAILURE) ] = "UST consumer exiting on error", + [ USTCOMM_ERR_INDEX(USTCONSUMER_OUTFD_ERROR) ] = "UST consumer error opening the tracefile", + [ USTCOMM_ERR_INDEX(USTCONSUMER_SPLICE_EBADF) ] = "UST consumer splice EBADF", + [ USTCOMM_ERR_INDEX(USTCONSUMER_SPLICE_EINVAL) ] = "UST consumer splice EINVAL", + [ USTCOMM_ERR_INDEX(USTCONSUMER_SPLICE_ENOMEM) ] = "UST consumer splice ENOMEM", + [ USTCOMM_ERR_INDEX(USTCONSUMER_SPLICE_ESPIPE) ] = "UST consumer splice ESPIPE", + [ USTCOMM_ERR_INDEX(USTCOMM_NO_EVENT) ] = "Event not found", }; /* * lttcom_get_readable_code * * Return ptr to string representing a human readable - * error code from the lttcomm_return_code enum. - * - * These code MUST be negative in other to treat that - * as an error value. + * error code from the ustcomm_return_code enum. */ -const char *lttcomm_get_readable_code(enum lttcomm_return_code code) +const char *ustcomm_get_readable_code(int code) { - int tmp_code = -code; - - if (tmp_code >= LTTCOMM_OK && tmp_code < LTTCOMM_NR) { - return lttcomm_readable_code[LTTCOMM_ERR_INDEX(tmp_code)]; + if (code == USTCOMM_OK) { + return "Success"; } - - return "Unknown error code"; + if (code >= USTCOMM_ERR && code < USTCOMM_NR) { + return ustcomm_readable_code[USTCOMM_ERR_INDEX(code)]; + } + return strerror(code); } /* - * lttcomm_connect_unix_sock + * ustcomm_connect_unix_sock * * Connect to unix socket using the path name. */ -int lttcomm_connect_unix_sock(const char *pathname) +int ustcomm_connect_unix_sock(const char *pathname) { struct sockaddr_un sun; int fd; @@ -152,12 +149,12 @@ error: } /* - * lttcomm_accept_unix_sock + * ustcomm_accept_unix_sock * * Do an accept(2) on the sock and return the * new file descriptor. The socket MUST be bind(2) before. */ -int lttcomm_accept_unix_sock(int sock) +int ustcomm_accept_unix_sock(int sock) { int new_fd; struct sockaddr_un sun; @@ -177,12 +174,12 @@ error: } /* - * lttcomm_create_unix_sock + * ustcomm_create_unix_sock * * Creates a AF_UNIX local socket using pathname * bind the socket upon creation and return the fd. */ -int lttcomm_create_unix_sock(const char *pathname) +int ustcomm_create_unix_sock(const char *pathname) { struct sockaddr_un sun; int fd; @@ -214,11 +211,11 @@ error: } /* - * lttcomm_listen_unix_sock + * ustcomm_listen_unix_sock * * Make the socket listen using MAX_LISTEN. */ -int lttcomm_listen_unix_sock(int sock) +int ustcomm_listen_unix_sock(int sock) { int ret; @@ -231,13 +228,13 @@ int lttcomm_listen_unix_sock(int sock) } /* - * lttcomm_recv_unix_sock + * ustcomm_recv_unix_sock * * Receive data of size len in put that data into * the buf param. Using recvmsg API. * Return the size of received data. */ -ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len) +ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len) { struct msghdr msg = { 0 }; struct iovec iov[1]; @@ -257,12 +254,12 @@ ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len) } /* - * lttcomm_send_unix_sock + * ustcomm_send_unix_sock * * Send buf data of size len. Using sendmsg API. * Return the size of sent data. */ -ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len) +ssize_t ustcomm_send_unix_sock(int sock, void *buf, size_t len) { struct msghdr msg = { 0 }; struct iovec iov[1]; @@ -289,11 +286,11 @@ ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len) } /* - * lttcomm_close_unix_sock + * ustcomm_close_unix_sock * * Shutdown cleanly a unix socket. */ -int lttcomm_close_unix_sock(int sock) +int ustcomm_close_unix_sock(int sock) { int ret; @@ -307,11 +304,11 @@ int lttcomm_close_unix_sock(int sock) } /* - * lttcomm_send_fds_unix_sock + * ustcomm_send_fds_unix_sock * * Send multiple fds on a unix socket. */ -ssize_t lttcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, size_t len) +ssize_t ustcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, size_t len) { struct msghdr msg = { 0 }; struct cmsghdr *cmptr; @@ -349,3 +346,137 @@ ssize_t lttcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, return ret; } + +int ustcomm_send_app_msg(int sock, struct ustcomm_ust_msg *lum) +{ + ssize_t len; + + len = ustcomm_send_unix_sock(sock, lum, sizeof(*lum)); + switch (len) { + case sizeof(*lum): + printf("message successfully sent\n"); + break; + case -1: + if (errno == ECONNRESET) { + printf("remote end closed connection\n"); + return 0; + } + return -1; + default: + printf("incorrect message size: %zd\n", len); + return -1; + } + return 0; +} + +int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur, + uint32_t expected_handle, uint32_t expected_cmd) +{ + ssize_t len; + + memset(lur, 0, sizeof(*lur)); + len = ustcomm_recv_unix_sock(sock, lur, sizeof(*lur)); + switch (len) { + case 0: /* orderly shutdown */ + printf("Application has performed an orderly shutdown\n"); + return -EINVAL; + case sizeof(*lur): + printf("result message received\n"); + if (lur->handle != expected_handle) { + printf("Unexpected result message handle\n"); + return -EINVAL; + } + + if (lur->cmd != expected_cmd) { + printf("Unexpected result message command\n"); + return -EINVAL; + } + if (lur->ret_code != USTCOMM_OK) { + printf("remote operation failed with code %d.\n", + lur->ret_code); + return lur->ret_code; + } + return 0; + case -1: + if (errno == ECONNRESET) { + printf("remote end closed connection\n"); + return -EINVAL; + } + return -1; + default: + printf("incorrect message size: %zd\n", len); + return len > 0 ? -1 : len; + } +} + +int ustcomm_send_app_cmd(int sock, + struct ustcomm_ust_msg *lum, + struct ustcomm_ust_reply *lur) +{ + int ret; + + ret = ustcomm_send_app_msg(sock, lum); + if (ret) + return ret; + ret = ustcomm_recv_app_reply(sock, lur, lum->handle, lum->cmd); + if (ret) + return ret; + return 0; +} + + +/* + * Receives a single fd from socket. + * + * Returns the size of received data + */ +int ustcomm_recv_fd(int sock) +{ + struct iovec iov[1]; + int ret = 0; + int data_fd; + struct cmsghdr *cmsg; + char recv_fd[CMSG_SPACE(sizeof(int))]; + struct msghdr msg = { 0 }; + union { + unsigned char vc[4]; + int vi; + } tmp; + int i; + + /* Prepare to receive the structures */ + iov[0].iov_base = &data_fd; + iov[0].iov_len = sizeof(data_fd); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + msg.msg_control = recv_fd; + msg.msg_controllen = sizeof(recv_fd); + + printf("Waiting to receive fd\n"); + if ((ret = recvmsg(sock, &msg, 0)) < 0) { + perror("recvmsg"); + goto end; + } + if (ret != sizeof(data_fd)) { + printf("Received %d bytes, expected %ld", ret, sizeof(data_fd)); + goto end; + } + cmsg = CMSG_FIRSTHDR(&msg); + if (!cmsg) { + printf("Invalid control message header\n"); + ret = -1; + goto end; + } + if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { + printf("Didn't received any fd\n"); + ret = -1; + goto end; + } + /* this is our fd */ + for (i = 0; i < sizeof(int); i++) + tmp.vc[i] = CMSG_DATA(cmsg)[i]; + ret = tmp.vi; + printf("received fd %d\n", ret); +end: + return ret; +} diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index 2cb99a3e..cf012dfa 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -460,7 +460,10 @@ struct shm_handle *channel_create(const struct lib_ring_buffer_config *config, shmobj = shm_object_table_append(handle->table, shmsize); if (!shmobj) goto error_append; + /* struct channel is at object 0, offset 0 (hardcoded) */ set_shmp(handle->chan, zalloc_shm(shmobj, sizeof(struct channel))); + assert(handle->chan._ref.index == 0); + assert(handle->chan._ref.offset == 0); chan = shmp(handle, handle->chan); if (!chan) goto error_append; @@ -526,7 +529,9 @@ struct shm_handle *channel_handle_create(int shm_fd, int wait_fd, shm_fd, wait_fd, memory_map_size); if (!object) goto error_table_object; - + /* struct channel is at object 0, offset 0 (hardcoded) */ + handle->chan._ref.index = 0; + handle->chan._ref.offset = 0; return handle; error_table_object: diff --git a/libust/lttng-ust-comm.c b/libust/lttng-ust-comm.c index 7971168c..ba600536 100644 --- a/libust/lttng-ust-comm.c +++ b/libust/lttng-ust-comm.c @@ -182,18 +182,18 @@ int register_app_to_sessiond(int socket) return -errno; } - ret = lttcomm_send_unix_sock(socket, ®_msg, sizeof(reg_msg)); + ret = ustcomm_send_unix_sock(socket, ®_msg, sizeof(reg_msg)); if (ret >= 0 && ret != sizeof(reg_msg)) return -EIO; return ret; } static -int send_reply(int sock, struct lttcomm_ust_reply *lur) +int send_reply(int sock, struct ustcomm_ust_reply *lur) { ssize_t len; - len = lttcomm_send_unix_sock(sock, lur, sizeof(*lur)); + len = ustcomm_send_unix_sock(sock, lur, sizeof(*lur)); switch (len) { case sizeof(*lur): DBG("message successfully sent"); @@ -231,11 +231,11 @@ int handle_register_done(struct sock_info *sock_info) static int handle_message(struct sock_info *sock_info, - int sock, struct lttcomm_ust_msg *lum) + int sock, struct ustcomm_ust_msg *lum) { int ret = 0; const struct objd_ops *ops; - struct lttcomm_ust_reply lur; + struct ustcomm_ust_reply lur; int shm_fd, wait_fd; ust_lock(); @@ -280,9 +280,9 @@ end: lur.cmd = lum->cmd; lur.ret_val = ret; if (ret >= 0) { - lur.ret_code = LTTCOMM_OK; + lur.ret_code = USTCOMM_OK; } else { - //lur.ret_code = LTTCOMM_SESSION_FAIL; + //lur.ret_code = USTCOMM_SESSION_FAIL; lur.ret_code = ret; } switch (lum->cmd) { @@ -301,6 +301,9 @@ end: shm_fd = lum->u.channel.shm_fd; wait_fd = lum->u.channel.wait_fd; break; + case LTTNG_UST_VERSION: + lur.u.version = lum->u.version; + break; } ret = send_reply(sock, &lur); if (ret < 0) { @@ -311,16 +314,16 @@ end: if ((lum->cmd == LTTNG_UST_STREAM || lum->cmd == LTTNG_UST_CHANNEL || lum->cmd == LTTNG_UST_METADATA) - && lur.ret_code == LTTCOMM_OK) { + && lur.ret_code == USTCOMM_OK) { /* we also need to send the file descriptors. */ - ret = lttcomm_send_fds_unix_sock(sock, + ret = ustcomm_send_fds_unix_sock(sock, &shm_fd, &shm_fd, 1, sizeof(int)); if (ret < 0) { perror("send shm_fd"); goto error; } - ret = lttcomm_send_fds_unix_sock(sock, + ret = ustcomm_send_fds_unix_sock(sock, &wait_fd, &wait_fd, 1, sizeof(int)); if (ret < 0) { @@ -620,7 +623,7 @@ restart: } /* Register */ - ret = lttcomm_connect_unix_sock(sock_info->sock_path); + ret = ustcomm_connect_unix_sock(sock_info->sock_path); if (ret < 0) { ERR("Error connecting to %s apps socket", sock_info->name); prev_connect_failed = 1; @@ -667,9 +670,9 @@ restart: for (;;) { ssize_t len; - struct lttcomm_ust_msg lum; + struct ustcomm_ust_msg lum; - len = lttcomm_recv_unix_sock(sock, &lum, sizeof(lum)); + len = ustcomm_recv_unix_sock(sock, &lum, sizeof(lum)); switch (len) { case 0: /* orderly shutdown */ DBG("%s ltt-sessiond has performed an orderly shutdown\n", sock_info->name); diff --git a/libustctl/Makefile.am b/libustctl/Makefile.am new file mode 100644 index 00000000..56b04093 --- /dev/null +++ b/libustctl/Makefile.am @@ -0,0 +1,9 @@ +AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/liblttng-ust-comm +AM_CFLAGS = -fno-strict-aliasing + +lib_LTLIBRARIES = libustctl.la + +libustctl_la_SOURCES = ustctl.c + +libustctl_la_LIBADD = $(top_builddir)/liblttng-ust-comm/liblttng-ust-comm.la \ + $(top_builddir)/libringbuffer/libringbuffer.la diff --git a/libustctl/ustctl.c b/libustctl/ustctl.c new file mode 100644 index 00000000..3d886d33 --- /dev/null +++ b/libustctl/ustctl.c @@ -0,0 +1,584 @@ +/* + * Copyright (C) 2011 - Julien Desfossez + * Mathieu Desnoyers + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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. + */ + +#include +#include +#include +#include +#include "lttng-ust-comm.h" + +#include "../libringbuffer/backend.h" +#include "../libringbuffer/frontend.h" + +static +void init_object(struct object_data *data) +{ + data->handle = -1; + data->shm_fd = -1; + data->wait_fd = -1; + data->memory_map_size = 0; +} + +void release_object(int sock, struct object_data *data) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + int ret; + + if (data->shm_fd >= 0) + close(data->shm_fd); + if (data->wait_fd >= 0) + close(data->wait_fd); + memset(&lum, 0, sizeof(lum)); + lum.handle = data->handle; + lum.cmd = LTTNG_UST_RELEASE; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + assert(!ret); + free(data); +} + +/* + * returns session handle. + */ +int ustctl_create_session(int sock) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + int ret, session_handle; + + /* Create session */ + memset(&lum, 0, sizeof(lum)); + lum.handle = LTTNG_UST_ROOT_HANDLE; + lum.cmd = LTTNG_UST_SESSION; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + if (ret) + return ret; + session_handle = lur.ret_val; + DBG("received session handle %u", session_handle); + return session_handle; +} + +/* open the metadata global channel */ +int ustctl_open_metadata(int sock, int session_handle, + struct lttng_ust_channel_attr *chops, + struct object_data **_metadata_data) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + struct object_data *metadata_data; + int ret; + + metadata_data = malloc(sizeof(*metadata_data)); + if (!metadata_data) + return -ENOMEM; + init_object(metadata_data); + /* Create metadata channel */ + memset(&lum, 0, sizeof(lum)); + lum.handle = session_handle; + lum.cmd = LTTNG_UST_METADATA; + lum.u.channel.overwrite = chops->overwrite; + lum.u.channel.subbuf_size = chops->subbuf_size; + lum.u.channel.num_subbuf = chops->num_subbuf; + lum.u.channel.switch_timer_interval = chops->switch_timer_interval; + lum.u.channel.read_timer_interval = chops->read_timer_interval; + lum.u.channel.output = chops->output; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + if (ret) { + free(metadata_data); + return ret; + } + if (lur.ret_code != USTCOMM_OK) { + free(metadata_data); + return lur.ret_code; + } + metadata_data->handle = lur.ret_val; + DBG("received metadata handle %u", metadata_data->handle); + metadata_data->memory_map_size = lur.u.channel.memory_map_size; + /* get shm fd */ + ret = ustcomm_recv_fd(sock); + if (ret < 0) + goto error; + metadata_data->shm_fd = ret; + /* get wait fd */ + ret = ustcomm_recv_fd(sock); + if (ret < 0) + goto error; + metadata_data->wait_fd = ret; + *_metadata_data = metadata_data; + return 0; + +error: + release_object(sock, metadata_data); + return -EINVAL; +} + +int ustctl_create_channel(int sock, int session_handle, + struct lttng_ust_channel_attr *chops, + struct object_data **_channel_data) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + struct object_data *channel_data; + int ret; + + channel_data = malloc(sizeof(*channel_data)); + if (!channel_data) + return -ENOMEM; + init_object(channel_data); + /* Create metadata channel */ + memset(&lum, 0, sizeof(lum)); + lum.handle = session_handle; + lum.cmd = LTTNG_UST_CHANNEL; + lum.u.channel.overwrite = chops->overwrite; + lum.u.channel.subbuf_size = chops->subbuf_size; + lum.u.channel.num_subbuf = chops->num_subbuf; + lum.u.channel.switch_timer_interval = chops->switch_timer_interval; + lum.u.channel.read_timer_interval = chops->read_timer_interval; + lum.u.channel.output = chops->output; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + if (ret) { + free(channel_data); + return ret; + } + if (lur.ret_code != USTCOMM_OK) { + free(channel_data); + return lur.ret_code; + } + channel_data->handle = lur.ret_val; + DBG("received channel handle %u", channel_data->handle); + channel_data->memory_map_size = lur.u.channel.memory_map_size; + /* get shm fd */ + ret = ustcomm_recv_fd(sock); + if (ret < 0) + goto error; + channel_data->shm_fd = ret; + /* get wait fd */ + ret = ustcomm_recv_fd(sock); + if (ret < 0) + goto error; + channel_data->wait_fd = ret; + *_channel_data = channel_data; + return 0; + +error: + release_object(sock, channel_data); + return -EINVAL; +} + +/* + * Return -ENOENT if no more stream is available for creation. + * Return 0 on success. + * Return negative error value on error. + */ +int ustctl_create_stream(int sock, struct object_data *channel_data, + struct object_data **_stream_data) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + struct object_data *stream_data; + int ret, fd; + + stream_data = malloc(sizeof(*stream_data)); + if (!stream_data) + return -ENOMEM; + init_object(stream_data); + memset(&lum, 0, sizeof(lum)); + lum.handle = channel_data->handle; + lum.cmd = LTTNG_UST_STREAM; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + if (ret) { + free(stream_data); + return ret; + } + if (lur.ret_code != USTCOMM_OK) { + free(stream_data); + return lur.ret_code; + } + + stream_data->handle = lur.ret_val; + DBG("received stream handle %u", stream_data->handle); + stream_data->memory_map_size = lur.u.stream.memory_map_size; + /* get shm fd */ + fd = ustcomm_recv_fd(sock); + if (fd < 0) + goto error; + stream_data->shm_fd = fd; + /* get wait fd */ + fd = ustcomm_recv_fd(sock); + if (fd < 0) + goto error; + stream_data->wait_fd = fd; + *_stream_data = stream_data; + return ret; + +error: + release_object(sock, stream_data); + return -EINVAL; +} + +int ustctl_create_event(int sock, struct lttng_ust_event *ev, + struct object_data *channel_data, + struct object_data **_event_data) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + struct object_data *event_data; + int ret; + + event_data = malloc(sizeof(*event_data)); + if (!event_data) + return -ENOMEM; + init_object(event_data); + memset(&lum, 0, sizeof(lum)); + lum.handle = channel_data->handle; + lum.cmd = LTTNG_UST_EVENT; + strncpy(lum.u.event.name, ev->name, + LTTNG_UST_SYM_NAME_LEN); + lum.u.event.instrumentation = ev->instrumentation; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + if (ret) { + free(event_data); + return ret; + } + event_data->handle = lur.ret_val; + DBG("received event handle %u", event_data->handle); + *_event_data = event_data; + return 0; +} + +int ustctl_add_context(int sock, struct lttng_ust_context *ctx, + struct object_data *channel_data, + struct object_data **_context_data) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + struct object_data *context_data; + int ret; + + context_data = malloc(sizeof(*context_data)); + if (!context_data) + return -ENOMEM; + init_object(context_data); + memset(&lum, 0, sizeof(lum)); + lum.handle = channel_data->handle; + lum.cmd = LTTNG_UST_CONTEXT; + lum.u.context.ctx = ctx->ctx; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + if (ret) { + free(context_data); + return ret; + } + context_data->handle = lur.ret_val; + DBG("received context handle %u", context_data->handle); + *_context_data = context_data; + return ret; +} + +/* Enable event, channel and session ioctl */ +int ustctl_enable(int sock, struct object_data *object) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + int ret; + + memset(&lum, 0, sizeof(lum)); + lum.handle = object->handle; + lum.cmd = LTTNG_UST_ENABLE; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + if (ret) + return ret; + DBG("enabled handle %u", object->handle); + return 0; +} + +/* Disable event, channel and session ioctl */ +int ustctl_disable(int sock, struct object_data *object) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + int ret; + + memset(&lum, 0, sizeof(lum)); + lum.handle = object->handle; + lum.cmd = LTTNG_UST_DISABLE; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + if (ret) + return ret; + DBG("disable handle %u", object->handle); + return 0; +} + +int ustctl_start_session(int sock, struct object_data *object) +{ + return ustctl_enable(sock, object); +} + +int ustctl_stop_session(int sock, struct object_data *object) +{ + return ustctl_disable(sock, object); +} + + +int ustctl_tracepoint_list(int sock) +{ + return -ENOSYS; /* not implemented */ +} + +int ustctl_tracer_version(int sock, struct lttng_ust_tracer_version *v) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + int ret; + + memset(&lum, 0, sizeof(lum)); + lum.handle = LTTNG_UST_ROOT_HANDLE; + lum.cmd = LTTNG_UST_TRACER_VERSION; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + if (ret) + return ret; + memcpy(v, &lur.u.version, sizeof(*v)); + DBG("received tracer version"); + return 0; +} + +int ustctl_wait_quiescent(int sock) +{ + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; + int ret; + + memset(&lum, 0, sizeof(lum)); + lum.handle = LTTNG_UST_ROOT_HANDLE; + lum.cmd = LTTNG_UST_WAIT_QUIESCENT; + ret = ustcomm_send_app_cmd(sock, &lum, &lur); + if (ret) + return ret; + DBG("waited for quiescent state"); + return 0; +} + +int ustctl_calibrate(int sock, struct lttng_ust_calibrate *calibrate) +{ + return -ENOSYS; +} + +/* Buffer operations */ + +/* Map channel shm into process memory */ +struct shm_handle *ustctl_map_channel(struct object_data *chan_data) +{ + struct shm_handle *handle; + struct channel *chan; + size_t chan_size; + + handle = channel_handle_create(chan_data->shm_fd, + chan_data->wait_fd, + chan_data->memory_map_size); + if (!handle) { + ERR("create handle error"); + return NULL; + } + /* + * Set to -1 because the shm_handle destruction will take care + * of closing shm_fd and wait_fd. + */ + chan_data->shm_fd = -1; + chan_data->wait_fd = -1; + + /* + * TODO: add consistency checks to be resilient if the + * application try to feed us with incoherent channel structure + * values. + */ + chan = shmp(handle, handle->chan); + /* chan is object 0. This is hardcoded. */ + chan_size = handle->table->objects[0].allocated_len; + handle->shadow_chan = malloc(chan_size); + if (!handle->shadow_chan) { + channel_destroy(chan, handle, 1); + return NULL; + } + memcpy(handle->shadow_chan, chan, chan_size); + return handle; +} + +/* Add stream to channel shm and map its shm into process memory */ +int ustctl_add_stream(struct shm_handle *handle, + struct object_data *stream_data) +{ + int ret; + + if (!stream_data->handle) + return -ENOENT; + /* map stream */ + ret = channel_handle_add_stream(handle, + stream_data->shm_fd, + stream_data->wait_fd, + stream_data->memory_map_size); + if (ret) { + ERR("add stream error\n"); + return ret; + } + /* + * Set to -1 because the shm_handle destruction will take care + * of closing shm_fd and wait_fd. + */ + stream_data->shm_fd = -1; + stream_data->wait_fd = -1; + return 0; +} + +/* For mmap mode, readable without "get" operation */ + +/* returns the length to mmap. */ +int ustctl_get_mmap_len(struct shm_handle *handle, + struct lib_ring_buffer *buf, + unsigned long *len) +{ + unsigned long mmap_buf_len; + struct channel *chan = handle->shadow_chan; + + if (chan->backend.config.output != RING_BUFFER_MMAP) + return -EINVAL; + mmap_buf_len = chan->backend.buf_size; + if (chan->backend.extra_reader_sb) + mmap_buf_len += chan->backend.subbuf_size; + if (mmap_buf_len > INT_MAX) + return -EFBIG; + *len = mmap_buf_len; + return 0; +} + +/* returns the maximum size for sub-buffers. */ +int ustctl_get_max_subbuf_size(struct shm_handle *handle, + struct lib_ring_buffer *buf, + unsigned long *len) +{ + struct channel *chan = handle->shadow_chan; + + *len = chan->backend.subbuf_size; + return 0; +} + +/* + * For mmap mode, operate on the current packet (between get/put or + * get_next/put_next). + */ + +/* returns the offset of the subbuffer belonging to the mmap reader. */ +int ustctl_get_mmap_read_offset(struct shm_handle *handle, + struct lib_ring_buffer *buf, unsigned long *off) +{ + struct channel *chan = handle->shadow_chan; + unsigned long sb_bindex; + + if (chan->backend.config.output != RING_BUFFER_MMAP) + return -EINVAL; + sb_bindex = subbuffer_id_get_index(&chan->backend.config, + buf->backend.buf_rsb.id); + *off = shmp(handle, shmp_index(handle, buf->backend.array, sb_bindex)->shmp)->mmap_offset; + return 0; +} + +/* returns the size of the current sub-buffer, without padding (for mmap). */ +int ustctl_get_subbuf_size(struct shm_handle *handle, + struct lib_ring_buffer *buf, unsigned long *len) +{ + struct channel *chan = handle->shadow_chan; + + *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf, + handle); + return 0; +} + +/* returns the size of the current sub-buffer, without padding (for mmap). */ +int ustctl_get_padded_subbuf_size(struct shm_handle *handle, + struct lib_ring_buffer *buf, unsigned long *len) +{ + struct channel *chan = handle->shadow_chan; + + *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf, + handle); + *len = PAGE_ALIGN(*len); + return 0; +} + +/* Get exclusive read access to the next sub-buffer that can be read. */ +int ustctl_get_next_subbuf(struct shm_handle *handle, + struct lib_ring_buffer *buf) +{ + return lib_ring_buffer_get_next_subbuf(buf, handle); +} + + +/* Release exclusive sub-buffer access, move consumer forward. */ +int ustctl_put_next_subbuf(struct shm_handle *handle, + struct lib_ring_buffer *buf) +{ + lib_ring_buffer_put_next_subbuf(buf, handle); + return 0; +} + +/* snapshot */ + +/* Get a snapshot of the current ring buffer producer and consumer positions */ +int ustctl_snapshot(struct shm_handle *handle, + struct lib_ring_buffer *buf) +{ + return lib_ring_buffer_snapshot(buf, &buf->cons_snapshot, + &buf->prod_snapshot, handle); +} + +/* Get the consumer position (iteration start) */ +int ustctl_snapshot_get_consumed(struct shm_handle *handle, + struct lib_ring_buffer *buf, unsigned long *pos) +{ + *pos = buf->cons_snapshot; + return 0; +} + +/* Get the producer position (iteration end) */ +int ustctl_snapshot_get_produced(struct shm_handle *handle, + struct lib_ring_buffer *buf, unsigned long *pos) +{ + *pos = buf->prod_snapshot; + return 0; +} + +/* Get exclusive read access to the specified sub-buffer position */ +int ustctl_get_subbuf(struct shm_handle *handle, + struct lib_ring_buffer *buf, unsigned long *pos) +{ + return lib_ring_buffer_get_subbuf(buf, *pos, handle); +} + +/* Release exclusive sub-buffer access */ +int ustctl_put_subbuf(struct shm_handle *handle, + struct lib_ring_buffer *buf) +{ + lib_ring_buffer_put_subbuf(buf, handle); + return 0; +} + +int ustctl_buffer_flush(struct shm_handle *handle, + struct lib_ring_buffer *buf) +{ + lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE, handle); + return 0; +} diff --git a/tests/ust-basic-tracing/ust-basic-tracing.c b/tests/ust-basic-tracing/ust-basic-tracing.c index e97552a1..42e82424 100644 --- a/tests/ust-basic-tracing/ust-basic-tracing.c +++ b/tests/ust-basic-tracing/ust-basic-tracing.c @@ -69,141 +69,6 @@ static void handle_signals(int signo) quit_program = 1; } -static int send_app_msg(int sock, struct lttcomm_ust_msg *lum) -{ - ssize_t len; - - len = lttcomm_send_unix_sock(sock, lum, sizeof(*lum)); - switch (len) { - case sizeof(*lum): - printf("message successfully sent\n"); - break; - case -1: - if (errno == ECONNRESET) { - printf("remote end closed connection\n"); - return 0; - } - return -1; - default: - printf("incorrect message size: %zd\n", len); - return -1; - } - return 0; -} - -static int recv_app_reply(int sock, struct lttcomm_ust_reply *lur, - uint32_t expected_handle, uint32_t expected_cmd) -{ - ssize_t len; - - memset(lur, 0, sizeof(*lur)); - len = lttcomm_recv_unix_sock(sock, lur, sizeof(*lur)); - switch (len) { - case 0: /* orderly shutdown */ - printf("Application has performed an orderly shutdown\n"); - return -EINVAL; - case sizeof(*lur): - printf("result message received\n"); - if (lur->handle != expected_handle) { - printf("Unexpected result message handle\n"); - return -EINVAL; - } - - if (lur->cmd != expected_cmd) { - printf("Unexpected result message command\n"); - return -EINVAL; - } - if (lur->ret_code != LTTCOMM_OK) { - printf("remote operation failed with code %d.\n", - lur->ret_code); - return lur->ret_code; - } - return 0; - case -1: - if (errno == ECONNRESET) { - printf("remote end closed connection\n"); - return -EINVAL; - } - return -1; - default: - printf("incorrect message size: %zd\n", len); - return len > 0 ? -1 : len; - } -} - -static int send_app_cmd(int sock, - struct lttcomm_ust_msg *lum, - struct lttcomm_ust_reply *lur) -{ - int ret; - - ret = send_app_msg(sock, lum); - if (ret) - return ret; - ret = recv_app_reply(sock, lur, lum->handle, lum->cmd); - if (ret) - return ret; - return 0; -} - - -/* - * Receives a single fd from socket. - * - * Returns the size of received data - */ -static int lttcomm_recv_fd(int sock) -{ - struct iovec iov[1]; - int ret = 0; - int data_fd; - struct cmsghdr *cmsg; - char recv_fd[CMSG_SPACE(sizeof(int))]; - struct msghdr msg = { 0 }; - union { - unsigned char vc[4]; - int vi; - } tmp; - int i; - - /* Prepare to receive the structures */ - iov[0].iov_base = &data_fd; - iov[0].iov_len = sizeof(data_fd); - msg.msg_iov = iov; - msg.msg_iovlen = 1; - msg.msg_control = recv_fd; - msg.msg_controllen = sizeof(recv_fd); - - printf("Waiting to receive fd\n"); - if ((ret = recvmsg(sock, &msg, 0)) < 0) { - perror("recvmsg"); - goto end; - } - if (ret != sizeof(data_fd)) { - printf("Received %d bytes, expected %ld", ret, sizeof(data_fd)); - goto end; - } - cmsg = CMSG_FIRSTHDR(&msg); - if (!cmsg) { - printf("Invalid control message header\n"); - ret = -1; - goto end; - } - if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { - printf("Didn't received any fd\n"); - ret = -1; - goto end; - } - /* this is our fd */ - for (i = 0; i < sizeof(int); i++) - tmp.vc[i] = CMSG_DATA(cmsg)[i]; - ret = tmp.vi; - printf("received fd %d\n", ret); -end: - return ret; -} - - static int open_streams(int sock, int channel_handle, struct object_data *stream_datas, int nr_check) @@ -211,29 +76,29 @@ int open_streams(int sock, int channel_handle, struct object_data *stream_datas, int ret, k = 0; for (;;) { - struct lttcomm_ust_msg lum; - struct lttcomm_ust_reply lur; + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; memset(&lum, 0, sizeof(lum)); lum.handle = channel_handle; lum.cmd = LTTNG_UST_STREAM; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (!ret) { assert(k < nr_check); stream_datas[k].handle = lur.ret_val; printf("received stream handle %u\n", stream_datas[k].handle); - if (lur.ret_code == LTTCOMM_OK) { + if (lur.ret_code == USTCOMM_OK) { ssize_t len; stream_datas[k].memory_map_size = lur.u.stream.memory_map_size; /* get shm fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; stream_datas[k].shm_fd = len; /* get wait fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; stream_datas[k].wait_fd = len; @@ -254,15 +119,15 @@ int close_streams(int sock, struct object_data *stream_datas, int nr_check) int ret, k; for (k = 0; k < nr_check; k++) { - struct lttcomm_ust_msg lum; - struct lttcomm_ust_reply lur; + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; if (!stream_datas[k].handle) continue; memset(&lum, 0, sizeof(lum)); lum.handle = stream_datas[k].handle; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) { printf("Error closing stream\n"); return ret; @@ -461,18 +326,19 @@ int consume_buffers(const char *outputpath) return 0; } +static int send_app_msgs(int sock, const char *outputpath, unsigned int nr_events, const char **event_names) { - struct lttcomm_ust_msg lum; - struct lttcomm_ust_reply lur; + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; int ret, k; /* Create session */ memset(&lum, 0, sizeof(lum)); lum.handle = LTTNG_UST_ROOT_HANDLE; lum.cmd = LTTNG_UST_SESSION; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; session_handle = lur.ret_val; @@ -488,22 +354,22 @@ int send_app_msgs(int sock, const char *outputpath, lum.u.channel.switch_timer_interval = 0; lum.u.channel.read_timer_interval = 0; lum.u.channel.output = LTTNG_UST_MMAP; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; metadata_data.handle = lur.ret_val; printf("received metadata handle %u\n", metadata_data.handle); - if (lur.ret_code == LTTCOMM_OK) { + if (lur.ret_code == USTCOMM_OK) { ssize_t len; metadata_data.memory_map_size = lur.u.channel.memory_map_size; /* get shm fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; metadata_data.shm_fd = len; /* get wait fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; metadata_data.wait_fd = len; @@ -529,22 +395,22 @@ int send_app_msgs(int sock, const char *outputpath, lum.u.channel.switch_timer_interval = 0; lum.u.channel.read_timer_interval = 0; lum.u.channel.output = LTTNG_UST_MMAP; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; channel_data.handle = lur.ret_val; printf("received channel handle %u\n", channel_data.handle); - if (lur.ret_code == LTTCOMM_OK) { + if (lur.ret_code == USTCOMM_OK) { ssize_t len; channel_data.memory_map_size = lur.u.channel.memory_map_size; /* get shm fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; channel_data.shm_fd = len; /* get wait fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; channel_data.wait_fd = len; @@ -558,7 +424,7 @@ int send_app_msgs(int sock, const char *outputpath, strncpy(lum.u.event.name, event_names[k], LTTNG_UST_SYM_NAME_LEN); lum.u.event.instrumentation = LTTNG_UST_TRACEPOINT; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; event_handle[k] = lur.ret_val; @@ -573,7 +439,7 @@ int send_app_msgs(int sock, const char *outputpath, //lum.u.context.ctx = LTTNG_UST_CONTEXT_PTHREAD_ID; //lum.u.context.ctx = LTTNG_UST_CONTEXT_VPID; //lum.u.context.ctx = LTTNG_UST_CONTEXT_PROCNAME; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; context_handle = lur.ret_val; @@ -590,7 +456,7 @@ int send_app_msgs(int sock, const char *outputpath, memset(&lum, 0, sizeof(lum)); lum.handle = session_handle; lum.cmd = LTTNG_UST_SESSION_START; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; printf("Session handle %u started.\n", session_handle); @@ -599,7 +465,7 @@ int send_app_msgs(int sock, const char *outputpath, memset(&lum, 0, sizeof(lum)); lum.handle = LTTNG_UST_ROOT_HANDLE; lum.cmd = LTTNG_UST_REGISTER_DONE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; printf("Registration done acknowledged.\n"); @@ -623,7 +489,7 @@ int send_app_msgs(int sock, const char *outputpath, memset(&lum, 0, sizeof(lum)); lum.handle = context_handle; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; @@ -632,14 +498,14 @@ int send_app_msgs(int sock, const char *outputpath, memset(&lum, 0, sizeof(lum)); lum.handle = event_handle[k]; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; } memset(&lum, 0, sizeof(lum)); lum.handle = channel_data.handle; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; if (channel_data.shm_fd >= 0) { @@ -661,7 +527,7 @@ int send_app_msgs(int sock, const char *outputpath, memset(&lum, 0, sizeof(lum)); lum.handle = metadata_data.handle; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; if (metadata_data.shm_fd >= 0) { @@ -679,7 +545,7 @@ int send_app_msgs(int sock, const char *outputpath, memset(&lum, 0, sizeof(lum)); lum.handle = session_handle; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; @@ -918,7 +784,7 @@ int main(int argc, const char **argv) DEFAULT_HOME_APPS_UNIX_SOCK, home_dir); } - ret = lttcomm_create_unix_sock(apps_sock_path); + ret = ustcomm_create_unix_sock(apps_sock_path); if (ret < 0) { perror("create error"); return ret; @@ -936,7 +802,7 @@ int main(int argc, const char **argv) } umask(old_umask); } - ret = lttcomm_listen_unix_sock(apps_socket); + ret = ustcomm_listen_unix_sock(apps_socket); if (ret < 0) { perror("listen error"); return ret; @@ -967,7 +833,7 @@ int main(int argc, const char **argv) break; printf("Accepting application registration\n"); - sock = lttcomm_accept_unix_sock(apps_socket); + sock = ustcomm_accept_unix_sock(apps_socket); if (sock < 0) { perror("accept error"); goto end; @@ -977,9 +843,9 @@ int main(int argc, const char **argv) * Basic recv here to handle the very simple data * that the libust send to register (reg_msg). */ - len = lttcomm_recv_unix_sock(sock, ®_msg, sizeof(reg_msg)); + len = ustcomm_recv_unix_sock(sock, ®_msg, sizeof(reg_msg)); if (len < 0 || len != sizeof(reg_msg)) { - perror("lttcomm_recv_unix_sock"); + perror("ustcomm_recv_unix_sock"); continue; } memcpy(bufname, reg_msg.name, 16); diff --git a/tests/ust-multi-test/ust-multi-test.c b/tests/ust-multi-test/ust-multi-test.c index 87352c1d..59f54a9c 100644 --- a/tests/ust-multi-test/ust-multi-test.c +++ b/tests/ust-multi-test/ust-multi-test.c @@ -76,141 +76,6 @@ static void handle_signals(int signo) quit_program = 1; } -static int send_app_msg(int sock, struct lttcomm_ust_msg *lum) -{ - ssize_t len; - - len = lttcomm_send_unix_sock(sock, lum, sizeof(*lum)); - switch (len) { - case sizeof(*lum): - printf("message successfully sent\n"); - break; - case -1: - if (errno == ECONNRESET) { - printf("remote end closed connection\n"); - return 0; - } - return -1; - default: - printf("incorrect message size: %zd\n", len); - return -1; - } - return 0; -} - -static int recv_app_reply(int sock, struct lttcomm_ust_reply *lur, - uint32_t expected_handle, uint32_t expected_cmd) -{ - ssize_t len; - - memset(lur, 0, sizeof(*lur)); - len = lttcomm_recv_unix_sock(sock, lur, sizeof(*lur)); - switch (len) { - case 0: /* orderly shutdown */ - printf("Application has performed an orderly shutdown\n"); - return -EINVAL; - case sizeof(*lur): - printf("result message received\n"); - if (lur->handle != expected_handle) { - printf("Unexpected result message handle\n"); - return -EINVAL; - } - - if (lur->cmd != expected_cmd) { - printf("Unexpected result message command\n"); - return -EINVAL; - } - if (lur->ret_code != LTTCOMM_OK) { - printf("remote operation failed with code %d.\n", - lur->ret_code); - return lur->ret_code; - } - return 0; - case -1: - if (errno == ECONNRESET) { - printf("remote end closed connection\n"); - return -EINVAL; - } - return -1; - default: - printf("incorrect message size: %zd\n", len); - return len > 0 ? -1 : len; - } -} - -static int send_app_cmd(int sock, - struct lttcomm_ust_msg *lum, - struct lttcomm_ust_reply *lur) -{ - int ret; - - ret = send_app_msg(sock, lum); - if (ret) - return ret; - ret = recv_app_reply(sock, lur, lum->handle, lum->cmd); - if (ret) - return ret; - return 0; -} - - -/* - * Receives a single fd from socket. - * - * Returns the size of received data - */ -static int lttcomm_recv_fd(int sock) -{ - struct iovec iov[1]; - int ret = 0; - int data_fd; - struct cmsghdr *cmsg; - char recv_fd[CMSG_SPACE(sizeof(int))]; - struct msghdr msg = { 0 }; - union { - unsigned char vc[4]; - int vi; - } tmp; - int i; - - /* Prepare to receive the structures */ - iov[0].iov_base = &data_fd; - iov[0].iov_len = sizeof(data_fd); - msg.msg_iov = iov; - msg.msg_iovlen = 1; - msg.msg_control = recv_fd; - msg.msg_controllen = sizeof(recv_fd); - - printf("Waiting to receive fd\n"); - if ((ret = recvmsg(sock, &msg, 0)) < 0) { - perror("recvmsg"); - goto end; - } - if (ret != sizeof(data_fd)) { - printf("Received %d bytes, expected %ld", ret, sizeof(data_fd)); - goto end; - } - cmsg = CMSG_FIRSTHDR(&msg); - if (!cmsg) { - printf("Invalid control message header\n"); - ret = -1; - goto end; - } - if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { - printf("Didn't received any fd\n"); - ret = -1; - goto end; - } - /* this is our fd */ - for (i = 0; i < sizeof(int); i++) - tmp.vc[i] = CMSG_DATA(cmsg)[i]; - ret = tmp.vi; - printf("received fd %d\n", ret); -end: - return ret; -} - - static int open_streams(int sock, int channel_handle, struct object_data *stream_datas, int nr_check) @@ -218,29 +83,29 @@ int open_streams(int sock, int channel_handle, struct object_data *stream_datas, int ret, k = 0; for (;;) { - struct lttcomm_ust_msg lum; - struct lttcomm_ust_reply lur; + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; memset(&lum, 0, sizeof(lum)); lum.handle = channel_handle; lum.cmd = LTTNG_UST_STREAM; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (!ret) { assert(k < nr_check); stream_datas[k].handle = lur.ret_val; printf("received stream handle %u\n", stream_datas[k].handle); - if (lur.ret_code == LTTCOMM_OK) { + if (lur.ret_code == USTCOMM_OK) { ssize_t len; stream_datas[k].memory_map_size = lur.u.stream.memory_map_size; /* get shm fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; stream_datas[k].shm_fd = len; /* get wait fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; stream_datas[k].wait_fd = len; @@ -261,15 +126,15 @@ int close_streams(int sock, struct object_data *stream_datas, int nr_check) int ret, k; for (k = 0; k < nr_check; k++) { - struct lttcomm_ust_msg lum; - struct lttcomm_ust_reply lur; + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; if (!stream_datas[k].handle) continue; memset(&lum, 0, sizeof(lum)); lum.handle = stream_datas[k].handle; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) { printf("Error closing stream\n"); return ret; @@ -475,8 +340,8 @@ int consume_buffers(void) int send_app_msgs(int sock) { - struct lttcomm_ust_msg lum; - struct lttcomm_ust_reply lur; + struct ustcomm_ust_msg lum; + struct ustcomm_ust_reply lur; int ret, i, j, k; for (i = 0; i < NR_SESSIONS; i++) { @@ -484,7 +349,7 @@ int send_app_msgs(int sock) memset(&lum, 0, sizeof(lum)); lum.handle = LTTNG_UST_ROOT_HANDLE; lum.cmd = LTTNG_UST_SESSION; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; session_handle[i] = lur.ret_val; @@ -500,22 +365,22 @@ int send_app_msgs(int sock) lum.u.channel.switch_timer_interval = 0; lum.u.channel.read_timer_interval = 0; lum.u.channel.output = LTTNG_UST_MMAP; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; metadata_data[i].handle = lur.ret_val; printf("received metadata handle %u\n", metadata_data[i].handle); - if (lur.ret_code == LTTCOMM_OK) { + if (lur.ret_code == USTCOMM_OK) { ssize_t len; metadata_data[i].memory_map_size = lur.u.channel.memory_map_size; /* get shm fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; metadata_data[i].shm_fd = len; /* get wait fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; metadata_data[i].wait_fd = len; @@ -542,22 +407,22 @@ int send_app_msgs(int sock) lum.u.channel.switch_timer_interval = 0; lum.u.channel.read_timer_interval = 0; lum.u.channel.output = LTTNG_UST_MMAP; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; channel_data[i][j].handle = lur.ret_val; printf("received channel handle %u\n", channel_data[i][j].handle); - if (lur.ret_code == LTTCOMM_OK) { + if (lur.ret_code == USTCOMM_OK) { ssize_t len; channel_data[i][j].memory_map_size = lur.u.channel.memory_map_size; /* get shm fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; channel_data[i][j].shm_fd = len; /* get wait fd */ - len = lttcomm_recv_fd(sock); + len = ustcomm_recv_fd(sock); if (len < 0) return -EINVAL; channel_data[i][j].wait_fd = len; @@ -571,7 +436,7 @@ int send_app_msgs(int sock) strncpy(lum.u.event.name, evname[k], LTTNG_UST_SYM_NAME_LEN); lum.u.event.instrumentation = LTTNG_UST_TRACEPOINT; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; event_handle[i][j][k] = lur.ret_val; @@ -590,7 +455,7 @@ int send_app_msgs(int sock) memset(&lum, 0, sizeof(lum)); lum.handle = session_handle[i]; lum.cmd = LTTNG_UST_SESSION_START; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; printf("Session handle %u started.\n", session_handle[i]); @@ -600,7 +465,7 @@ int send_app_msgs(int sock) memset(&lum, 0, sizeof(lum)); lum.handle = LTTNG_UST_ROOT_HANDLE; lum.cmd = LTTNG_UST_REGISTER_DONE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; printf("Registration done acknowledged.\n"); @@ -627,14 +492,14 @@ int send_app_msgs(int sock) memset(&lum, 0, sizeof(lum)); lum.handle = event_handle[i][j][k]; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; } memset(&lum, 0, sizeof(lum)); lum.handle = channel_data[i][j].handle; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; if (channel_data[i][j].shm_fd >= 0) { @@ -657,7 +522,7 @@ int send_app_msgs(int sock) memset(&lum, 0, sizeof(lum)); lum.handle = metadata_data[i].handle; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; if (metadata_data[i].shm_fd >= 0) { @@ -675,7 +540,7 @@ int send_app_msgs(int sock) memset(&lum, 0, sizeof(lum)); lum.handle = session_handle[i]; lum.cmd = LTTNG_UST_RELEASE; - ret = send_app_cmd(sock, &lum, &lur); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; } @@ -898,7 +763,7 @@ int main(int argc, char **argv) DEFAULT_HOME_APPS_UNIX_SOCK, home_dir); } - ret = lttcomm_create_unix_sock(apps_sock_path); + ret = ustcomm_create_unix_sock(apps_sock_path); if (ret < 0) { perror("create error"); return ret; @@ -916,7 +781,7 @@ int main(int argc, char **argv) } umask(old_umask); } - ret = lttcomm_listen_unix_sock(apps_socket); + ret = ustcomm_listen_unix_sock(apps_socket); if (ret < 0) { perror("listen error"); return ret; @@ -947,7 +812,7 @@ int main(int argc, char **argv) break; printf("Accepting application registration\n"); - sock = lttcomm_accept_unix_sock(apps_socket); + sock = ustcomm_accept_unix_sock(apps_socket); if (sock < 0) { perror("accept error"); goto end; @@ -957,9 +822,9 @@ int main(int argc, char **argv) * Basic recv here to handle the very simple data * that the libust send to register (reg_msg). */ - len = lttcomm_recv_unix_sock(sock, ®_msg, sizeof(reg_msg)); + len = ustcomm_recv_unix_sock(sock, ®_msg, sizeof(reg_msg)); if (len < 0 || len != sizeof(reg_msg)) { - perror("lttcomm_recv_unix_sock"); + perror("ustcomm_recv_unix_sock"); continue; } memcpy(bufname, reg_msg.name, 16);