4 * Linux Trace Toolkit Control Library
6 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
7 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * SPDX-License-Identifier: LGPL-2.1-only
13 #include "lttng/domain.h"
22 #include <common/bytecode/bytecode.h>
23 #include <common/common.h>
24 #include <common/compat/errno.h>
25 #include <common/compat/string.h>
26 #include <common/defaults.h>
27 #include <common/dynamic-buffer.h>
28 #include <common/dynamic-array.h>
29 #include <common/payload.h>
30 #include <common/payload-view.h>
31 #include <common/sessiond-comm/sessiond-comm.h>
32 #include <common/tracker.h>
33 #include <common/unix.h>
34 #include <common/uri.h>
35 #include <common/utils.h>
36 #include <lttng/channel-internal.h>
37 #include <lttng/destruction-handle.h>
38 #include <lttng/endpoint.h>
39 #include <lttng/event-internal.h>
40 #include <lttng/health-internal.h>
41 #include <lttng/lttng.h>
42 #include <lttng/map/map-internal.h>
43 #include <lttng/map/map-query-internal.h>
44 #include <lttng/session-descriptor-internal.h>
45 #include <lttng/session-internal.h>
46 #include <lttng/trigger/trigger-internal.h>
47 #include <lttng/userspace-probe-internal.h>
48 #include <lttng/lttng-error.h>
50 #include <common/filter/filter-ast.h>
51 #include <common/filter/filter-parser.h>
52 #include <common/filter/memstream.h>
53 #include "lttng-ctl-helper.h"
55 #define COPY_DOMAIN_PACKED(dst, src) \
57 struct lttng_domain _tmp_domain; \
59 lttng_ctl_copy_lttng_domain(&_tmp_domain, &src); \
63 /* Socket to session daemon for communication */
64 static int sessiond_socket
= -1;
65 static char sessiond_sock_path
[PATH_MAX
];
68 static char *tracing_group
;
74 * Those two variables are used by error.h to silent or control the verbosity of
75 * error message. They are global to the library so application linking with it
76 * are able to compile correctly and also control verbosity of the library.
79 int lttng_opt_verbose
;
83 * Copy domain to lttcomm_session_msg domain.
85 * If domain is unknown, default domain will be the kernel.
88 void lttng_ctl_copy_lttng_domain(struct lttng_domain
*dst
,
89 struct lttng_domain
*src
)
93 case LTTNG_DOMAIN_KERNEL
:
94 case LTTNG_DOMAIN_UST
:
95 case LTTNG_DOMAIN_JUL
:
96 case LTTNG_DOMAIN_LOG4J
:
97 case LTTNG_DOMAIN_PYTHON
:
98 memcpy(dst
, src
, sizeof(struct lttng_domain
));
101 memset(dst
, 0, sizeof(struct lttng_domain
));
108 * Send lttcomm_session_msg to the session daemon.
110 * On success, returns the number of bytes sent (>=0)
111 * On error, returns -1
113 static int send_session_msg(struct lttcomm_session_msg
*lsm
)
118 ret
= -LTTNG_ERR_NO_SESSIOND
;
122 DBG("LSM cmd type: '%s' (%d)", lttcomm_sessiond_command_str(lsm
->cmd_type
),
125 ret
= lttcomm_send_creds_unix_sock(sessiond_socket
, lsm
,
126 sizeof(struct lttcomm_session_msg
));
128 ret
= -LTTNG_ERR_FATAL
;
136 * Send var len data to the session daemon.
138 * On success, returns the number of bytes sent (>=0)
139 * On error, returns -1
141 static int send_session_varlen(const void *data
, size_t len
)
146 ret
= -LTTNG_ERR_NO_SESSIOND
;
155 ret
= lttcomm_send_unix_sock(sessiond_socket
, data
, len
);
157 ret
= -LTTNG_ERR_FATAL
;
165 * Send file descriptors to the session daemon.
167 * On success, returns the number of bytes sent (>=0)
168 * On error, returns -1
170 static int send_session_fds(const int *fds
, size_t nb_fd
)
175 ret
= -LTTNG_ERR_NO_SESSIOND
;
179 if (!fds
|| !nb_fd
) {
184 ret
= lttcomm_send_fds_unix_sock(sessiond_socket
, fds
, nb_fd
);
186 ret
= -LTTNG_ERR_FATAL
;
194 * Receive data from the sessiond socket.
196 * On success, returns the number of bytes received (>=0)
197 * On error, returns a negative lttng_error_code.
199 static int recv_data_sessiond(void *buf
, size_t len
)
206 ret
= -LTTNG_ERR_NO_SESSIOND
;
210 ret
= lttcomm_recv_unix_sock(sessiond_socket
, buf
, len
);
212 ret
= -LTTNG_ERR_FATAL
;
213 } else if (ret
== 0) {
214 ret
= -LTTNG_ERR_NO_SESSIOND
;
222 * Receive a payload from the session daemon by appending to an existing
224 * On success, returns the number of bytes received (>=0)
225 * On error, returns a negative lttng_error_code.
227 static int recv_payload_sessiond(struct lttng_payload
*payload
, size_t len
)
230 const size_t original_payload_size
= payload
->buffer
.size
;
232 ret
= lttng_dynamic_buffer_set_size(
233 &payload
->buffer
, payload
->buffer
.size
+ len
);
235 ret
= -LTTNG_ERR_NOMEM
;
239 ret
= recv_data_sessiond(
240 payload
->buffer
.data
+ original_payload_size
, len
);
246 * Check if we are in the specified group.
248 * If yes return 1, else return -1.
251 int lttng_check_tracing_group(void)
253 gid_t
*grp_list
, tracing_gid
;
254 int grp_list_size
, grp_id
, i
;
256 const char *grp_name
= tracing_group
;
258 /* Get GID of group 'tracing' */
259 if (utils_get_group_id(grp_name
, false, &tracing_gid
)) {
260 /* If grp_tracing is NULL, the group does not exist. */
264 /* Get number of supplementary group IDs */
265 grp_list_size
= getgroups(0, NULL
);
266 if (grp_list_size
< 0) {
271 /* Alloc group list of the right size */
272 grp_list
= zmalloc(grp_list_size
* sizeof(gid_t
));
277 grp_id
= getgroups(grp_list_size
, grp_list
);
283 for (i
= 0; i
< grp_list_size
; i
++) {
284 if (grp_list
[i
] == tracing_gid
) {
297 static int check_enough_available_memory(size_t num_bytes_requested_per_cpu
)
301 size_t best_mem_info
;
302 size_t num_bytes_requested_total
;
305 * Get the number of CPU currently online to compute the amount of
306 * memory needed to create a buffer for every CPU.
308 num_cpu
= sysconf(_SC_NPROCESSORS_ONLN
);
313 num_bytes_requested_total
= num_bytes_requested_per_cpu
* num_cpu
;
316 * Try to get the `MemAvail` field of `/proc/meminfo`. This is the most
317 * reliable estimate we can get but it is only exposed by the kernel
318 * since 3.14. (See Linux kernel commit:
319 * 34e431b0ae398fc54ea69ff85ec700722c9da773)
321 ret
= utils_get_memory_available(&best_mem_info
);
327 * As a backup plan, use `MemTotal` field of `/proc/meminfo`. This
328 * is a sanity check for obvious user error.
330 ret
= utils_get_memory_total(&best_mem_info
);
338 return best_mem_info
>= num_bytes_requested_total
;
342 * Try connect to session daemon with sock_path.
344 * Return 0 on success, else -1
346 static int try_connect_sessiond(const char *sock_path
)
350 /* If socket exist, we check if the daemon listens for connect. */
351 ret
= access(sock_path
, F_OK
);
357 ret
= lttcomm_connect_unix_sock(sock_path
);
363 ret
= lttcomm_close_unix_sock(ret
);
365 PERROR("lttcomm_close_unix_sock");
375 * Set sessiond socket path by putting it in the global sessiond_sock_path
378 * Returns 0 on success, negative value on failure (the sessiond socket path
379 * is somehow too long or ENOMEM).
381 static int set_session_daemon_path(void)
383 int in_tgroup
= 0; /* In tracing group. */
389 /* Are we in the tracing group ? */
390 in_tgroup
= lttng_check_tracing_group();
393 if ((uid
== 0) || in_tgroup
) {
394 const int ret
= lttng_strncpy(sessiond_sock_path
,
395 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
,
396 sizeof(sessiond_sock_path
));
408 ret
= try_connect_sessiond(sessiond_sock_path
);
412 /* Global session daemon not available... */
414 /* ...or not in tracing group (and not root), default */
417 * With GNU C < 2.1, snprintf returns -1 if the target buffer
419 * With GNU C >= 2.1, snprintf returns the required size
420 * (excluding closing null)
422 ret
= snprintf(sessiond_sock_path
, sizeof(sessiond_sock_path
),
423 DEFAULT_HOME_CLIENT_UNIX_SOCK
, utils_get_home_dir());
424 if ((ret
< 0) || (ret
>= sizeof(sessiond_sock_path
))) {
436 * Connect to the LTTng session daemon.
438 * On success, return the socket's file descriptor. On error, return -1.
440 LTTNG_HIDDEN
int connect_sessiond(void)
444 ret
= set_session_daemon_path();
449 /* Connect to the sesssion daemon. */
450 ret
= lttcomm_connect_unix_sock(sessiond_sock_path
);
461 static void reset_global_sessiond_connection_state(void)
463 sessiond_socket
= -1;
468 * Clean disconnect from the session daemon.
470 * On success, return 0. On error, return -1.
472 static int disconnect_sessiond(void)
477 ret
= lttcomm_close_unix_sock(sessiond_socket
);
478 reset_global_sessiond_connection_state();
484 static int recv_sessiond_optional_data(size_t len
, void **user_buf
,
492 ret
= -LTTNG_ERR_INVALID
;
502 ret
= recv_data_sessiond(buf
, len
);
508 ret
= -LTTNG_ERR_INVALID
;
512 /* Move ownership of command header buffer to user. */
517 /* No command header. */
533 * Ask the session daemon a specific command and put the data into buf.
534 * Takes extra var. len. data and file descriptors as input to send to the
537 * Return size of data (only payload, not header) or a negative error code.
540 int lttng_ctl_ask_sessiond_fds_varlen(struct lttcomm_session_msg
*lsm
,
541 const int *fds
, size_t nb_fd
, const void *vardata
,
542 size_t vardata_len
, void **user_payload_buf
,
543 void **user_cmd_header_buf
, size_t *user_cmd_header_len
)
547 struct lttcomm_lttng_msg llm
;
549 ret
= connect_sessiond();
551 ret
= -LTTNG_ERR_NO_SESSIOND
;
554 sessiond_socket
= ret
;
558 ret
= send_session_msg(lsm
);
560 /* Ret value is a valid lttng error code. */
563 /* Send var len data */
564 ret
= send_session_varlen(vardata
, vardata_len
);
566 /* Ret value is a valid lttng error code. */
571 ret
= send_session_fds(fds
, nb_fd
);
573 /* Ret value is a valid lttng error code. */
577 /* Get header from data transmission */
578 ret
= recv_data_sessiond(&llm
, sizeof(llm
));
580 /* Ret value is a valid lttng error code. */
584 /* Check error code if OK */
585 if (llm
.ret_code
!= LTTNG_OK
) {
590 /* Get command header from data transmission */
591 ret
= recv_sessiond_optional_data(llm
.cmd_header_size
,
592 user_cmd_header_buf
, user_cmd_header_len
);
597 /* Get payload from data transmission */
598 ret
= recv_sessiond_optional_data(llm
.data_size
, user_payload_buf
,
607 disconnect_sessiond();
612 int lttng_ctl_ask_sessiond_payload(struct lttng_payload_view
*message
,
613 struct lttng_payload
*reply
)
616 struct lttcomm_lttng_msg llm
;
617 const int fd_count
= lttng_payload_view_get_fd_handle_count(message
);
619 assert(reply
->buffer
.size
== 0);
620 assert(lttng_dynamic_pointer_array_get_count(&reply
->_fd_handles
) == 0);
622 ret
= connect_sessiond();
624 ret
= -LTTNG_ERR_NO_SESSIOND
;
627 sessiond_socket
= ret
;
631 /* Send command to session daemon */
632 ret
= lttcomm_send_creds_unix_sock(sessiond_socket
, message
->buffer
.data
,
633 message
->buffer
.size
);
635 ret
= -LTTNG_ERR_FATAL
;
640 ret
= lttcomm_send_payload_view_fds_unix_sock(sessiond_socket
,
643 ret
= -LTTNG_ERR_FATAL
;
648 /* Get header from data transmission */
649 ret
= recv_payload_sessiond(reply
, sizeof(llm
));
651 /* Ret value is a valid lttng error code. */
655 llm
= *((typeof(llm
) *) reply
->buffer
.data
);
657 /* Check error code if OK */
658 if (llm
.ret_code
!= LTTNG_OK
) {
659 if (llm
.ret_code
< LTTNG_OK
|| llm
.ret_code
>= LTTNG_ERR_NR
) {
660 /* Invalid error code received. */
661 ret
= -LTTNG_ERR_UNK
;
668 if (llm
.cmd_header_size
> 0) {
669 ret
= recv_payload_sessiond(reply
, llm
.cmd_header_size
);
675 /* Get command header from data transmission */
676 if (llm
.data_size
> 0) {
677 ret
= recv_payload_sessiond(reply
, llm
.data_size
);
683 if (llm
.fd_count
> 0) {
684 ret
= lttcomm_recv_payload_fds_unix_sock(
685 sessiond_socket
, llm
.fd_count
, reply
);
691 /* Don't return the llm header to the caller. */
692 memmove(reply
->buffer
.data
, reply
->buffer
.data
+ sizeof(llm
),
693 reply
->buffer
.size
- sizeof(llm
));
694 ret
= lttng_dynamic_buffer_set_size(
695 &reply
->buffer
, reply
->buffer
.size
- sizeof(llm
));
697 /* Can't happen as size is reduced. */
701 ret
= reply
->buffer
.size
;
704 disconnect_sessiond();
709 * Create lttng handle and return pointer.
711 * The returned pointer will be NULL in case of malloc() error.
713 struct lttng_handle
*lttng_create_handle(const char *session_name
,
714 struct lttng_domain
*domain
)
717 struct lttng_handle
*handle
= NULL
;
719 handle
= zmalloc(sizeof(struct lttng_handle
));
720 if (handle
== NULL
) {
721 PERROR("malloc handle");
725 /* Copy session name */
726 ret
= lttng_strncpy(handle
->session_name
, session_name
? : "",
727 sizeof(handle
->session_name
));
732 /* Copy lttng domain or leave initialized to 0. */
734 lttng_ctl_copy_lttng_domain(&handle
->domain
, domain
);
745 * Destroy handle by free(3) the pointer.
747 void lttng_destroy_handle(struct lttng_handle
*handle
)
753 * Register an outside consumer.
755 * Returns size of returned session payload data or a negative error code.
757 int lttng_register_consumer(struct lttng_handle
*handle
,
758 const char *socket_path
)
761 struct lttcomm_session_msg lsm
;
763 if (handle
== NULL
|| socket_path
== NULL
) {
764 ret
= -LTTNG_ERR_INVALID
;
768 memset(&lsm
, 0, sizeof(lsm
));
769 lsm
.cmd_type
= LTTNG_REGISTER_CONSUMER
;
770 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
771 sizeof(lsm
.session
.name
));
773 ret
= -LTTNG_ERR_INVALID
;
777 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
779 ret
= lttng_strncpy(lsm
.u
.reg
.path
, socket_path
,
780 sizeof(lsm
.u
.reg
.path
));
782 ret
= -LTTNG_ERR_INVALID
;
786 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
792 * Start tracing for all traces of the session.
794 * Returns size of returned session payload data or a negative error code.
796 int lttng_start_tracing(const char *session_name
)
799 struct lttcomm_session_msg lsm
;
801 if (session_name
== NULL
) {
802 ret
= -LTTNG_ERR_INVALID
;
806 memset(&lsm
, 0, sizeof(lsm
));
807 lsm
.cmd_type
= LTTNG_START_TRACE
;
809 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
810 sizeof(lsm
.session
.name
));
812 ret
= -LTTNG_ERR_INVALID
;
816 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
822 * Stop tracing for all traces of the session.
824 static int _lttng_stop_tracing(const char *session_name
, int wait
)
827 struct lttcomm_session_msg lsm
;
829 if (session_name
== NULL
) {
830 ret
= -LTTNG_ERR_INVALID
;
834 memset(&lsm
, 0, sizeof(lsm
));
835 lsm
.cmd_type
= LTTNG_STOP_TRACE
;
837 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
838 sizeof(lsm
.session
.name
));
840 ret
= -LTTNG_ERR_INVALID
;
844 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
845 if (ret
< 0 && ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
853 /* Check for data availability */
855 data_ret
= lttng_data_pending(session_name
);
857 /* Return the data available call error. */
863 * Data sleep time before retrying (in usec). Don't sleep if the
864 * call returned value indicates availability.
867 usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME_US
);
869 } while (data_ret
!= 0);
877 * Stop tracing and wait for data availability.
879 int lttng_stop_tracing(const char *session_name
)
881 return _lttng_stop_tracing(session_name
, 1);
885 * Stop tracing but _don't_ wait for data availability.
887 int lttng_stop_tracing_no_wait(const char *session_name
)
889 return _lttng_stop_tracing(session_name
, 0);
893 * Add context to a channel.
895 * If the given channel is NULL, add the contexts to all channels.
896 * The event_name param is ignored.
898 * Returns the size of the returned payload data or a negative error code.
900 int lttng_add_context(struct lttng_handle
*handle
,
901 struct lttng_event_context
*ctx
, const char *event_name
,
902 const char *channel_name
)
907 struct lttcomm_session_msg lsm
;
909 /* Safety check. Both are mandatory. */
910 if (handle
== NULL
|| ctx
== NULL
) {
911 ret
= -LTTNG_ERR_INVALID
;
915 memset(&lsm
, 0, sizeof(lsm
));
916 lsm
.cmd_type
= LTTNG_ADD_CONTEXT
;
918 /* If no channel name, send empty string. */
919 ret
= lttng_strncpy(lsm
.u
.context
.channel_name
, channel_name
?: "",
920 sizeof(lsm
.u
.context
.channel_name
));
922 ret
= -LTTNG_ERR_INVALID
;
926 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
927 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
928 sizeof(lsm
.session
.name
));
930 ret
= -LTTNG_ERR_INVALID
;
934 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
935 size_t provider_len
, ctx_len
;
936 const char *provider_name
= ctx
->u
.app_ctx
.provider_name
;
937 const char *ctx_name
= ctx
->u
.app_ctx
.ctx_name
;
939 if (!provider_name
|| !ctx_name
) {
940 ret
= -LTTNG_ERR_INVALID
;
944 provider_len
= strlen(provider_name
);
945 if (provider_len
== 0) {
946 ret
= -LTTNG_ERR_INVALID
;
949 lsm
.u
.context
.provider_name_len
= provider_len
;
951 ctx_len
= strlen(ctx_name
);
953 ret
= -LTTNG_ERR_INVALID
;
956 lsm
.u
.context
.context_name_len
= ctx_len
;
958 len
= provider_len
+ ctx_len
;
961 ret
= -LTTNG_ERR_NOMEM
;
965 memcpy(buf
, provider_name
, provider_len
);
966 memcpy(buf
+ provider_len
, ctx_name
, ctx_len
);
968 memcpy(&lsm
.u
.context
.ctx
, ctx
, sizeof(struct lttng_event_context
));
970 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
972 * Don't leak application addresses to the sessiond.
973 * This is only necessary when ctx is for an app ctx otherwise
974 * the values inside the union (type & config) are overwritten.
976 lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
= NULL
;
977 lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
= NULL
;
980 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, buf
, len
, NULL
);
987 * Enable event(s) for a channel.
989 * If no event name is specified, all events are enabled.
990 * If no channel name is specified, the default 'channel0' is used.
992 * Returns size of returned session payload data or a negative error code.
994 int lttng_enable_event(struct lttng_handle
*handle
,
995 struct lttng_event
*ev
, const char *channel_name
)
997 return lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
1002 * Create or enable an event with a filter expression.
1004 * Return negative error value on error.
1005 * Return size of returned session payload data if OK.
1007 int lttng_enable_event_with_filter(struct lttng_handle
*handle
,
1008 struct lttng_event
*event
, const char *channel_name
,
1009 const char *filter_expression
)
1011 return lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
1012 filter_expression
, 0, NULL
);
1016 * Depending on the event, return a newly allocated agent filter expression or
1017 * NULL if not applicable.
1019 * An event with NO loglevel and the name is * will return NULL.
1021 static char *set_agent_filter(const char *filter
, struct lttng_event
*ev
)
1024 char *agent_filter
= NULL
;
1028 /* Don't add filter for the '*' event. */
1029 if (strcmp(ev
->name
, "*") != 0) {
1031 err
= asprintf(&agent_filter
, "(%s) && (logger_name == \"%s\")", filter
,
1034 err
= asprintf(&agent_filter
, "logger_name == \"%s\"", ev
->name
);
1042 /* Add loglevel filtering if any for the JUL domain. */
1043 if (ev
->loglevel_type
!= LTTNG_EVENT_LOGLEVEL_ALL
) {
1046 if (ev
->loglevel_type
== LTTNG_EVENT_LOGLEVEL_RANGE
) {
1052 if (filter
|| agent_filter
) {
1055 err
= asprintf(&new_filter
, "(%s) && (int_loglevel %s %d)",
1056 agent_filter
? agent_filter
: filter
, op
,
1061 agent_filter
= new_filter
;
1063 err
= asprintf(&agent_filter
, "int_loglevel %s %d", op
,
1072 return agent_filter
;
1079 * Enable event(s) for a channel, possibly with exclusions and a filter.
1080 * If no event name is specified, all events are enabled.
1081 * If no channel name is specified, the default name is used.
1082 * If filter expression is not NULL, the filter is set for the event.
1083 * If exclusion count is not zero, the exclusions are set for the event.
1084 * Returns size of returned session payload data or a negative error code.
1086 int lttng_enable_event_with_exclusions(struct lttng_handle
*handle
,
1087 struct lttng_event
*ev
, const char *channel_name
,
1088 const char *original_filter_expression
,
1089 int exclusion_count
, char **exclusion_list
)
1091 struct lttcomm_session_msg lsm
;
1092 struct lttng_payload payload
;
1094 unsigned int free_filter_expression
= 0;
1095 struct filter_parser_ctx
*ctx
= NULL
;
1098 * We have either a filter or some exclusions, so we need to set up
1099 * a variable-length payload from where to send the data.
1101 lttng_payload_init(&payload
);
1104 * Cast as non-const since we may replace the filter expression
1105 * by a dynamically allocated string. Otherwise, the original
1106 * string is not modified.
1108 char *filter_expression
= (char *) original_filter_expression
;
1110 if (handle
== NULL
|| ev
== NULL
) {
1111 ret
= -LTTNG_ERR_INVALID
;
1116 * Empty filter string will always be rejected by the parser
1117 * anyway, so treat this corner-case early to eliminate
1118 * lttng_fmemopen error for 0-byte allocation.
1120 if (filter_expression
&& filter_expression
[0] == '\0') {
1121 ret
= -LTTNG_ERR_INVALID
;
1125 memset(&lsm
, 0, sizeof(lsm
));
1127 /* If no channel name, send empty string. */
1128 ret
= lttng_strncpy(lsm
.u
.enable
.channel_name
, channel_name
?: "",
1129 sizeof(lsm
.u
.enable
.channel_name
));
1131 ret
= -LTTNG_ERR_INVALID
;
1135 lsm
.cmd_type
= LTTNG_ENABLE_EVENT
;
1136 if (ev
->name
[0] == '\0') {
1137 /* Enable all events. */
1138 ret
= lttng_strncpy(ev
->name
, "*", sizeof(ev
->name
));
1142 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1143 memcpy(&lsm
.u
.enable
.event
, ev
, sizeof(lsm
.u
.enable
.event
));
1145 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1146 sizeof(lsm
.session
.name
));
1148 ret
= -LTTNG_ERR_INVALID
;
1152 lsm
.u
.enable
.exclusion_count
= exclusion_count
;
1153 lsm
.u
.enable
.bytecode_len
= 0;
1155 /* Parse filter expression. */
1156 if (filter_expression
!= NULL
|| handle
->domain
.type
== LTTNG_DOMAIN_JUL
1157 || handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
1158 || handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1159 if (handle
->domain
.type
== LTTNG_DOMAIN_JUL
||
1160 handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
||
1161 handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1164 /* Setup JUL filter if needed. */
1165 agent_filter
= set_agent_filter(filter_expression
, ev
);
1166 if (!agent_filter
) {
1167 if (!filter_expression
) {
1169 * No JUL and no filter, just skip
1176 * With an agent filter, the original filter has
1177 * been added to it thus replace the filter
1180 filter_expression
= agent_filter
;
1181 free_filter_expression
= 1;
1185 ret
= filter_parser_ctx_create_from_filter_expression(filter_expression
, &ctx
);
1190 lsm
.u
.enable
.bytecode_len
= sizeof(ctx
->bytecode
->b
)
1191 + bytecode_get_len(&ctx
->bytecode
->b
);
1192 lsm
.u
.enable
.expression_len
= strlen(filter_expression
) + 1;
1195 ret
= lttng_dynamic_buffer_set_capacity(&payload
.buffer
,
1196 lsm
.u
.enable
.bytecode_len
+
1197 lsm
.u
.enable
.expression_len
+
1198 LTTNG_SYMBOL_NAME_LEN
*
1201 ret
= -LTTNG_ERR_EXCLUSION_NOMEM
;
1205 /* Put exclusion names first in the data. */
1206 for (i
= 0; i
< exclusion_count
; i
++) {
1207 size_t exclusion_len
;
1209 exclusion_len
= lttng_strnlen(*(exclusion_list
+ i
),
1210 LTTNG_SYMBOL_NAME_LEN
);
1211 if (exclusion_len
== LTTNG_SYMBOL_NAME_LEN
) {
1212 /* Exclusion is not NULL-terminated. */
1213 ret
= -LTTNG_ERR_INVALID
;
1217 ret
= lttng_dynamic_buffer_append(&payload
.buffer
,
1218 exclusion_list
[i
], exclusion_len
);
1223 for (int i
= 0; i
< (LTTNG_SYMBOL_NAME_LEN
- exclusion_len
); i
++) {
1226 lttng_dynamic_buffer_append(&payload
.buffer
, &c
, 1);
1230 /* Add filter expression next. */
1231 if (filter_expression
) {
1232 ret
= lttng_dynamic_buffer_append(&payload
.buffer
,
1233 filter_expression
, lsm
.u
.enable
.expression_len
);
1238 /* Add filter bytecode next. */
1239 if (ctx
&& lsm
.u
.enable
.bytecode_len
!= 0) {
1240 ret
= lttng_dynamic_buffer_append(&payload
.buffer
,
1241 &ctx
->bytecode
->b
, lsm
.u
.enable
.bytecode_len
);
1246 if (ev
->extended
.ptr
) {
1247 struct lttng_event_extended
*ev_ext
=
1248 (struct lttng_event_extended
*) ev
->extended
.ptr
;
1250 if (ev_ext
->probe_location
) {
1252 * lttng_userspace_probe_location_serialize returns the
1253 * number of bytes that was appended to the buffer.
1255 ret
= lttng_userspace_probe_location_serialize(
1256 ev_ext
->probe_location
, &payload
);
1262 * Set the size of the userspace probe location element
1263 * of the buffer so that the receiving side knows where
1266 lsm
.u
.enable
.userspace_probe_location_len
= ret
;
1271 struct lttng_payload_view view
= lttng_payload_view_from_payload(
1273 int fd_count
= lttng_payload_view_get_fd_handle_count(&view
);
1280 assert(fd_count
== 0 || fd_count
== 1);
1281 if (fd_count
== 1) {
1282 struct fd_handle
*handle
=
1283 lttng_payload_view_pop_fd_handle(&view
);
1289 fd_to_send
= fd_handle_get_fd(handle
);
1290 fd_handle_put(handle
);
1293 ret
= lttng_ctl_ask_sessiond_fds_varlen(&lsm
,
1294 fd_count
? &fd_to_send
: NULL
, fd_count
,
1295 view
.buffer
.size
? view
.buffer
.data
: NULL
,
1296 view
.buffer
.size
, NULL
, NULL
, 0);
1300 if (filter_expression
&& ctx
) {
1301 filter_bytecode_free(ctx
);
1302 filter_ir_free(ctx
);
1303 filter_parser_ctx_free(ctx
);
1306 if (free_filter_expression
) {
1308 * The filter expression has been replaced and must be freed as
1309 * it is not the original filter expression received as a
1312 free(filter_expression
);
1316 * Return directly to the caller and don't ask the sessiond since
1317 * something went wrong in the parsing of data above.
1319 lttng_payload_reset(&payload
);
1323 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1327 int lttng_disable_event_ext(struct lttng_handle
*handle
,
1328 struct lttng_event
*ev
, const char *channel_name
,
1329 const char *original_filter_expression
)
1331 struct lttcomm_session_msg lsm
;
1334 unsigned int free_filter_expression
= 0;
1335 struct filter_parser_ctx
*ctx
= NULL
;
1337 * Cast as non-const since we may replace the filter expression
1338 * by a dynamically allocated string. Otherwise, the original
1339 * string is not modified.
1341 char *filter_expression
= (char *) original_filter_expression
;
1343 if (handle
== NULL
|| ev
== NULL
) {
1344 ret
= -LTTNG_ERR_INVALID
;
1349 * Empty filter string will always be rejected by the parser
1350 * anyway, so treat this corner-case early to eliminate
1351 * lttng_fmemopen error for 0-byte allocation.
1353 if (filter_expression
&& filter_expression
[0] == '\0') {
1354 ret
= -LTTNG_ERR_INVALID
;
1358 memset(&lsm
, 0, sizeof(lsm
));
1360 /* If no channel name, send empty string. */
1361 ret
= lttng_strncpy(lsm
.u
.disable
.channel_name
, channel_name
?: "",
1362 sizeof(lsm
.u
.disable
.channel_name
));
1364 ret
= -LTTNG_ERR_INVALID
;
1368 lsm
.cmd_type
= LTTNG_DISABLE_EVENT
;
1370 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1371 memcpy(&lsm
.u
.disable
.event
, ev
, sizeof(lsm
.u
.disable
.event
));
1373 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1374 sizeof(lsm
.session
.name
));
1376 ret
= -LTTNG_ERR_INVALID
;
1380 lsm
.u
.disable
.bytecode_len
= 0;
1383 * For the JUL domain, a filter is enforced except for the
1384 * disable all event. This is done to avoid having the event in
1385 * all sessions thus filtering by logger name.
1387 if (filter_expression
== NULL
&&
1388 (handle
->domain
.type
!= LTTNG_DOMAIN_JUL
&&
1389 handle
->domain
.type
!= LTTNG_DOMAIN_LOG4J
&&
1390 handle
->domain
.type
!= LTTNG_DOMAIN_PYTHON
)) {
1395 * We have a filter, so we need to set up a variable-length
1396 * memory block from where to send the data.
1399 /* Parse filter expression */
1400 if (filter_expression
!= NULL
|| handle
->domain
.type
== LTTNG_DOMAIN_JUL
1401 || handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
1402 || handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1403 if (handle
->domain
.type
== LTTNG_DOMAIN_JUL
||
1404 handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
||
1405 handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1408 /* Setup JUL filter if needed. */
1409 agent_filter
= set_agent_filter(filter_expression
, ev
);
1410 if (!agent_filter
) {
1411 if (!filter_expression
) {
1413 * No JUL and no filter, just skip
1420 * With a JUL filter, the original filter has
1421 * been added to it thus replace the filter
1424 filter_expression
= agent_filter
;
1425 free_filter_expression
= 1;
1429 ret
= filter_parser_ctx_create_from_filter_expression(filter_expression
, &ctx
);
1434 lsm
.u
.enable
.bytecode_len
= sizeof(ctx
->bytecode
->b
)
1435 + bytecode_get_len(&ctx
->bytecode
->b
);
1436 lsm
.u
.enable
.expression_len
= strlen(filter_expression
) + 1;
1439 varlen_data
= zmalloc(lsm
.u
.disable
.bytecode_len
1440 + lsm
.u
.disable
.expression_len
);
1442 ret
= -LTTNG_ERR_EXCLUSION_NOMEM
;
1446 /* Add filter expression. */
1447 if (lsm
.u
.disable
.expression_len
!= 0) {
1450 lsm
.u
.disable
.expression_len
);
1452 /* Add filter bytecode next. */
1453 if (ctx
&& lsm
.u
.disable
.bytecode_len
!= 0) {
1455 + lsm
.u
.disable
.expression_len
,
1457 lsm
.u
.disable
.bytecode_len
);
1460 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, varlen_data
,
1461 lsm
.u
.disable
.bytecode_len
+ lsm
.u
.disable
.expression_len
, NULL
);
1465 if (filter_expression
&& ctx
) {
1466 filter_bytecode_free(ctx
);
1467 filter_ir_free(ctx
);
1468 filter_parser_ctx_free(ctx
);
1471 if (free_filter_expression
) {
1473 * The filter expression has been replaced and must be freed as
1474 * it is not the original filter expression received as a
1477 free(filter_expression
);
1481 * Return directly to the caller and don't ask the sessiond since
1482 * something went wrong in the parsing of data above.
1487 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1492 * Disable event(s) of a channel and domain.
1493 * If no event name is specified, all events are disabled.
1494 * If no channel name is specified, the default 'channel0' is used.
1495 * Returns size of returned session payload data or a negative error code.
1497 int lttng_disable_event(struct lttng_handle
*handle
, const char *name
,
1498 const char *channel_name
)
1501 struct lttng_event ev
;
1503 memset(&ev
, 0, sizeof(ev
));
1505 ev
.type
= LTTNG_EVENT_ALL
;
1506 ret
= lttng_strncpy(ev
.name
, name
?: "", sizeof(ev
.name
));
1508 ret
= -LTTNG_ERR_INVALID
;
1512 ret
= lttng_disable_event_ext(handle
, &ev
, channel_name
, NULL
);
1517 struct lttng_channel
*lttng_channel_create(struct lttng_domain
*domain
)
1519 struct lttng_channel
*channel
= NULL
;
1520 struct lttng_channel_extended
*extended
= NULL
;
1526 /* Validate domain. */
1527 switch (domain
->type
) {
1528 case LTTNG_DOMAIN_UST
:
1529 switch (domain
->buf_type
) {
1530 case LTTNG_BUFFER_PER_UID
:
1531 case LTTNG_BUFFER_PER_PID
:
1537 case LTTNG_DOMAIN_KERNEL
:
1538 if (domain
->buf_type
!= LTTNG_BUFFER_GLOBAL
) {
1546 channel
= zmalloc(sizeof(*channel
));
1551 extended
= zmalloc(sizeof(*extended
));
1556 channel
->attr
.extended
.ptr
= extended
;
1558 lttng_channel_set_default_attr(domain
, &channel
->attr
);
1566 void lttng_channel_destroy(struct lttng_channel
*channel
)
1572 if (channel
->attr
.extended
.ptr
) {
1573 free(channel
->attr
.extended
.ptr
);
1579 * Enable channel per domain
1580 * Returns size of returned session payload data or a negative error code.
1582 int lttng_enable_channel(struct lttng_handle
*handle
,
1583 struct lttng_channel
*in_chan
)
1586 struct lttcomm_session_msg lsm
;
1587 size_t total_buffer_size_needed_per_cpu
= 0;
1589 /* NULL arguments are forbidden. No default values. */
1590 if (handle
== NULL
|| in_chan
== NULL
) {
1591 return -LTTNG_ERR_INVALID
;
1594 memset(&lsm
, 0, sizeof(lsm
));
1595 memcpy(&lsm
.u
.channel
.chan
, in_chan
, sizeof(lsm
.u
.channel
.chan
));
1596 lsm
.u
.channel
.chan
.attr
.extended
.ptr
= NULL
;
1598 if (!in_chan
->attr
.extended
.ptr
) {
1599 struct lttng_channel
*channel
;
1600 struct lttng_channel_extended
*extended
;
1602 channel
= lttng_channel_create(&handle
->domain
);
1604 return -LTTNG_ERR_NOMEM
;
1608 * Create a new channel in order to use default extended
1611 extended
= (struct lttng_channel_extended
*)
1612 channel
->attr
.extended
.ptr
;
1613 memcpy(&lsm
.u
.channel
.extended
, extended
, sizeof(*extended
));
1614 lttng_channel_destroy(channel
);
1616 struct lttng_channel_extended
*extended
;
1618 extended
= (struct lttng_channel_extended
*)
1619 in_chan
->attr
.extended
.ptr
;
1620 memcpy(&lsm
.u
.channel
.extended
, extended
, sizeof(*extended
));
1624 * Verify that the amount of memory required to create the requested
1625 * buffer is available on the system at the moment.
1627 total_buffer_size_needed_per_cpu
= lsm
.u
.channel
.chan
.attr
.num_subbuf
*
1628 lsm
.u
.channel
.chan
.attr
.subbuf_size
;
1629 if (!check_enough_available_memory(total_buffer_size_needed_per_cpu
)) {
1630 return -LTTNG_ERR_NOMEM
;
1633 lsm
.cmd_type
= LTTNG_ENABLE_CHANNEL
;
1634 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1636 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1637 sizeof(lsm
.session
.name
));
1639 ret
= -LTTNG_ERR_INVALID
;
1643 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1648 enum lttng_error_code
lttng_add_map(struct lttng_handle
*handle
,
1649 struct lttng_map
*map
)
1653 enum lttng_error_code ret_code
;
1654 struct lttcomm_session_msg lsm
= {
1655 .cmd_type
= LTTNG_ADD_MAP
,
1657 struct lttcomm_session_msg
*message_lsm
;
1658 struct lttng_payload message
;
1659 struct lttng_payload reply
;
1661 lttng_payload_init(&message
);
1662 lttng_payload_init(&reply
);
1665 ret_code
= LTTNG_ERR_INVALID
;
1669 lsm
.domain
.type
= lttng_map_get_domain(map
);
1671 lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1672 sizeof(lsm
.session
.name
));
1674 ret
= lttng_dynamic_buffer_append(&message
.buffer
, &lsm
, sizeof(lsm
));
1676 ret_code
= LTTNG_ERR_NOMEM
;
1680 message_lsm
= (struct lttcomm_session_msg
*) message
.buffer
.data
;
1682 ret
= lttng_map_serialize(map
, &message
);
1684 ret_code
= LTTNG_ERR_UNK
;
1688 message_lsm
->u
.add_map
.length
= (uint32_t) message
.buffer
.size
- sizeof(lsm
);
1691 struct lttng_payload_view message_view
=
1692 lttng_payload_view_from_payload(&message
, 0, -1);
1694 message_lsm
->fd_count
= lttng_payload_view_get_fd_handle_count(
1697 ret
= lttng_ctl_ask_sessiond_payload(&message_view
, &reply
);
1704 ret_code
= LTTNG_OK
;
1707 lttng_payload_reset(&message
);
1708 lttng_payload_reset(&reply
);
1712 enum lttng_error_code
lttng_enable_map(struct lttng_handle
*handle
,
1713 const char *map_name
)
1716 enum lttng_error_code ret_code
;
1717 struct lttcomm_session_msg lsm
;
1718 struct lttng_payload message
;
1719 struct lttng_payload_view lsm_view
=
1720 lttng_payload_view_init_from_buffer(
1721 (const char *) &lsm
, 0, sizeof(lsm
));
1722 struct lttng_payload reply
;
1724 lttng_payload_init(&message
);
1725 lttng_payload_init(&reply
);
1727 memset(&lsm
, 0, sizeof(lsm
));
1728 lsm
.cmd_type
= LTTNG_ENABLE_MAP
;
1730 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1732 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1733 sizeof(lsm
.session
.name
));
1735 ret_code
= LTTNG_ERR_INVALID
;
1739 ret
= lttng_strncpy(lsm
.u
.enable_map
.map_name
, map_name
,
1740 sizeof(lsm
.u
.enable_map
.map_name
));
1742 ret_code
= LTTNG_ERR_INVALID
;
1746 ret
= lttng_dynamic_buffer_append(&message
.buffer
, &lsm
, sizeof(lsm
));
1748 ret_code
= LTTNG_ERR_NOMEM
;
1752 ret
= lttng_ctl_ask_sessiond_payload(&lsm_view
, &reply
);
1754 ret_code
= LTTNG_ERR_UNK
;
1758 ret_code
= LTTNG_OK
;
1761 lttng_payload_reset(&message
);
1762 lttng_payload_reset(&reply
);
1766 enum lttng_error_code
lttng_disable_map(struct lttng_handle
*handle
,
1767 const char *map_name
)
1770 enum lttng_error_code ret_code
;
1771 struct lttcomm_session_msg lsm
;
1772 struct lttng_payload message
;
1773 struct lttng_payload_view lsm_view
=
1774 lttng_payload_view_init_from_buffer(
1775 (const char *) &lsm
, 0, sizeof(lsm
));
1776 struct lttng_payload reply
;
1778 lttng_payload_init(&message
);
1779 lttng_payload_init(&reply
);
1781 memset(&lsm
, 0, sizeof(lsm
));
1782 lsm
.cmd_type
= LTTNG_DISABLE_MAP
;
1784 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1786 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1787 sizeof(lsm
.session
.name
));
1789 ret_code
= LTTNG_ERR_INVALID
;
1793 ret
= lttng_strncpy(lsm
.u
.disable_map
.map_name
, map_name
,
1794 sizeof(lsm
.u
.disable_map
.map_name
));
1796 ret_code
= LTTNG_ERR_INVALID
;
1800 ret
= lttng_dynamic_buffer_append(&message
.buffer
, &lsm
, sizeof(lsm
));
1802 ret_code
= LTTNG_ERR_NOMEM
;
1806 ret
= lttng_ctl_ask_sessiond_payload(&lsm_view
, &reply
);
1808 ret_code
= LTTNG_ERR_UNK
;
1812 ret_code
= LTTNG_OK
;
1815 lttng_payload_reset(&message
);
1816 lttng_payload_reset(&reply
);
1821 * All tracing will be stopped for registered events of the channel.
1822 * Returns size of returned session payload data or a negative error code.
1824 int lttng_disable_channel(struct lttng_handle
*handle
, const char *name
)
1827 struct lttcomm_session_msg lsm
;
1829 /* Safety check. Both are mandatory. */
1830 if (handle
== NULL
|| name
== NULL
) {
1831 return -LTTNG_ERR_INVALID
;
1834 memset(&lsm
, 0, sizeof(lsm
));
1836 lsm
.cmd_type
= LTTNG_DISABLE_CHANNEL
;
1838 ret
= lttng_strncpy(lsm
.u
.disable
.channel_name
, name
,
1839 sizeof(lsm
.u
.disable
.channel_name
));
1841 ret
= -LTTNG_ERR_INVALID
;
1845 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1847 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1848 sizeof(lsm
.session
.name
));
1850 ret
= -LTTNG_ERR_INVALID
;
1854 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1860 * Lists all available tracepoints of domain.
1861 * Sets the contents of the events array.
1862 * Returns the number of lttng_event entries in events;
1863 * on error, returns a negative value.
1865 int lttng_list_tracepoints(struct lttng_handle
*handle
,
1866 struct lttng_event
**events
)
1869 struct lttcomm_session_msg lsm
;
1871 if (handle
== NULL
) {
1872 return -LTTNG_ERR_INVALID
;
1875 memset(&lsm
, 0, sizeof(lsm
));
1876 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINTS
;
1877 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1879 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) events
);
1884 return ret
/ sizeof(struct lttng_event
);
1888 * Lists all available tracepoint fields of domain.
1889 * Sets the contents of the event field array.
1890 * Returns the number of lttng_event_field entries in events;
1891 * on error, returns a negative value.
1893 int lttng_list_tracepoint_fields(struct lttng_handle
*handle
,
1894 struct lttng_event_field
**fields
)
1897 struct lttcomm_session_msg lsm
;
1899 if (handle
== NULL
) {
1900 return -LTTNG_ERR_INVALID
;
1903 memset(&lsm
, 0, sizeof(lsm
));
1904 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINT_FIELDS
;
1905 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1907 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) fields
);
1912 return ret
/ sizeof(struct lttng_event_field
);
1916 * Lists all available kernel system calls. Allocates and sets the contents of
1919 * Returns the number of lttng_event entries in events; on error, returns a
1922 int lttng_list_syscalls(struct lttng_event
**events
)
1925 struct lttcomm_session_msg lsm
;
1928 return -LTTNG_ERR_INVALID
;
1931 memset(&lsm
, 0, sizeof(lsm
));
1932 lsm
.cmd_type
= LTTNG_LIST_SYSCALLS
;
1933 /* Force kernel domain for system calls. */
1934 lsm
.domain
.type
= LTTNG_DOMAIN_KERNEL
;
1936 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) events
);
1941 return ret
/ sizeof(struct lttng_event
);
1945 * Returns a human readable string describing
1946 * the error code (a negative value).
1948 const char *lttng_strerror(int code
)
1950 return error_get_str(code
);
1953 enum lttng_error_code
lttng_create_session_ext(
1954 struct lttng_session_descriptor
*session_descriptor
)
1956 enum lttng_error_code ret_code
;
1957 struct lttcomm_session_msg lsm
= {
1958 .cmd_type
= LTTNG_CREATE_SESSION_EXT
,
1961 struct lttng_buffer_view reply_view
;
1963 bool sessiond_must_generate_ouput
;
1964 struct lttng_dynamic_buffer payload
;
1966 size_t descriptor_size
;
1967 struct lttng_session_descriptor
*descriptor_reply
= NULL
;
1969 lttng_dynamic_buffer_init(&payload
);
1970 if (!session_descriptor
) {
1971 ret_code
= LTTNG_ERR_INVALID
;
1975 sessiond_must_generate_ouput
=
1976 !lttng_session_descriptor_is_output_destination_initialized(
1977 session_descriptor
);
1978 if (sessiond_must_generate_ouput
) {
1979 const char *home_dir
= utils_get_home_dir();
1980 size_t home_dir_len
= home_dir
? strlen(home_dir
) + 1 : 0;
1982 if (!home_dir
|| home_dir_len
> LTTNG_PATH_MAX
) {
1983 ret_code
= LTTNG_ERR_FATAL
;
1987 lsm
.u
.create_session
.home_dir_size
= (uint16_t) home_dir_len
;
1988 ret
= lttng_dynamic_buffer_append(&payload
, home_dir
,
1991 ret_code
= LTTNG_ERR_NOMEM
;
1996 descriptor_size
= payload
.size
;
1997 ret
= lttng_session_descriptor_serialize(session_descriptor
,
2000 ret_code
= LTTNG_ERR_INVALID
;
2003 descriptor_size
= payload
.size
- descriptor_size
;
2004 lsm
.u
.create_session
.session_descriptor_size
= descriptor_size
;
2006 /* Command returns a session descriptor on success. */
2007 reply_ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, payload
.data
,
2008 payload
.size
, &reply
);
2009 if (reply_ret
< 0) {
2010 ret_code
= -reply_ret
;
2012 } else if (reply_ret
== 0) {
2013 /* Socket unexpectedly closed by the session daemon. */
2014 ret_code
= LTTNG_ERR_FATAL
;
2018 reply_view
= lttng_buffer_view_init(reply
, 0, reply_ret
);
2019 ret
= lttng_session_descriptor_create_from_buffer(&reply_view
,
2022 ret_code
= LTTNG_ERR_FATAL
;
2025 ret_code
= LTTNG_OK
;
2026 lttng_session_descriptor_assign(session_descriptor
, descriptor_reply
);
2029 lttng_dynamic_buffer_reset(&payload
);
2030 lttng_session_descriptor_destroy(descriptor_reply
);
2035 * Create a new session using name and url for destination.
2037 * Return 0 on success else a negative LTTng error code.
2039 int lttng_create_session(const char *name
, const char *url
)
2043 struct lttng_uri
*uris
= NULL
;
2044 struct lttng_session_descriptor
*descriptor
= NULL
;
2045 enum lttng_error_code ret_code
;
2048 ret
= -LTTNG_ERR_INVALID
;
2052 size
= uri_parse_str_urls(url
, NULL
, &uris
);
2054 ret
= -LTTNG_ERR_INVALID
;
2059 descriptor
= lttng_session_descriptor_create(name
);
2062 if (uris
[0].dtype
!= LTTNG_DST_PATH
) {
2063 ret
= -LTTNG_ERR_INVALID
;
2066 descriptor
= lttng_session_descriptor_local_create(name
,
2070 descriptor
= lttng_session_descriptor_network_create(name
, url
,
2074 ret
= -LTTNG_ERR_INVALID
;
2078 ret
= -LTTNG_ERR_INVALID
;
2081 ret_code
= lttng_create_session_ext(descriptor
);
2082 ret
= ret_code
== LTTNG_OK
? 0 : -ret_code
;
2084 lttng_session_descriptor_destroy(descriptor
);
2090 * Create a session exclusively used for snapshot.
2092 * Return 0 on success else a negative LTTng error code.
2094 int lttng_create_session_snapshot(const char *name
, const char *snapshot_url
)
2097 enum lttng_error_code ret_code
;
2099 struct lttng_uri
*uris
= NULL
;
2100 struct lttng_session_descriptor
*descriptor
= NULL
;
2103 ret
= -LTTNG_ERR_INVALID
;
2107 size
= uri_parse_str_urls(snapshot_url
, NULL
, &uris
);
2109 ret
= -LTTNG_ERR_INVALID
;
2113 * If the user does not specify a custom subdir, use the session name.
2115 if (size
> 0 && uris
[0].dtype
!= LTTNG_DST_PATH
&&
2116 strlen(uris
[0].subdir
) == 0) {
2117 ret
= snprintf(uris
[0].subdir
, sizeof(uris
[0].subdir
), "%s",
2120 PERROR("Failed to set session name as network destination sub-directory");
2121 ret
= -LTTNG_ERR_FATAL
;
2123 } else if (ret
>= sizeof(uris
[0].subdir
)) {
2124 /* Truncated output. */
2125 ret
= -LTTNG_ERR_INVALID
;
2132 descriptor
= lttng_session_descriptor_snapshot_create(name
);
2135 if (uris
[0].dtype
!= LTTNG_DST_PATH
) {
2136 ret
= -LTTNG_ERR_INVALID
;
2139 descriptor
= lttng_session_descriptor_snapshot_local_create(
2144 descriptor
= lttng_session_descriptor_snapshot_network_create(
2150 ret
= -LTTNG_ERR_INVALID
;
2154 ret
= -LTTNG_ERR_INVALID
;
2157 ret_code
= lttng_create_session_ext(descriptor
);
2158 ret
= ret_code
== LTTNG_OK
? 0 : -ret_code
;
2160 lttng_session_descriptor_destroy(descriptor
);
2166 * Create a session exclusively used for live.
2168 * Return 0 on success else a negative LTTng error code.
2170 int lttng_create_session_live(const char *name
, const char *url
,
2171 unsigned int timer_interval
)
2174 enum lttng_error_code ret_code
;
2175 struct lttng_session_descriptor
*descriptor
= NULL
;
2178 ret
= -LTTNG_ERR_INVALID
;
2183 descriptor
= lttng_session_descriptor_live_network_create(
2184 name
, url
, NULL
, timer_interval
);
2186 descriptor
= lttng_session_descriptor_live_create(
2187 name
, timer_interval
);
2190 ret
= -LTTNG_ERR_INVALID
;
2193 ret_code
= lttng_create_session_ext(descriptor
);
2194 ret
= ret_code
== LTTNG_OK
? 0 : -ret_code
;
2196 lttng_session_descriptor_destroy(descriptor
);
2201 * Stop the session and wait for the data before destroying it
2203 * Return 0 on success else a negative LTTng error code.
2205 int lttng_destroy_session(const char *session_name
)
2208 enum lttng_error_code ret_code
;
2209 enum lttng_destruction_handle_status status
;
2210 struct lttng_destruction_handle
*handle
= NULL
;
2213 * Stop the tracing and wait for the data to be
2216 ret
= _lttng_stop_tracing(session_name
, 1);
2217 if (ret
&& ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
2221 ret_code
= lttng_destroy_session_ext(session_name
, &handle
);
2222 if (ret_code
!= LTTNG_OK
) {
2223 ret
= (int) -ret_code
;
2228 /* Block until the completion of the destruction of the session. */
2229 status
= lttng_destruction_handle_wait_for_completion(handle
, -1);
2230 if (status
!= LTTNG_DESTRUCTION_HANDLE_STATUS_COMPLETED
) {
2231 ret
= -LTTNG_ERR_UNK
;
2235 status
= lttng_destruction_handle_get_result(handle
, &ret_code
);
2236 if (status
!= LTTNG_DESTRUCTION_HANDLE_STATUS_OK
) {
2237 ret
= -LTTNG_ERR_UNK
;
2240 ret
= ret_code
== LTTNG_OK
? 0 : -ret_code
;
2242 lttng_destruction_handle_destroy(handle
);
2247 * Destroy the session without waiting for the data.
2249 int lttng_destroy_session_no_wait(const char *session_name
)
2251 enum lttng_error_code ret_code
;
2253 ret_code
= lttng_destroy_session_ext(session_name
, NULL
);
2254 return ret_code
== LTTNG_OK
? ret_code
: -ret_code
;
2258 * Ask the session daemon for all available sessions.
2259 * Sets the contents of the sessions array.
2260 * Returns the number of lttng_session entries in sessions;
2261 * on error, returns a negative value.
2263 int lttng_list_sessions(struct lttng_session
**out_sessions
)
2266 struct lttcomm_session_msg lsm
;
2267 const size_t session_size
= sizeof(struct lttng_session
) +
2268 sizeof(struct lttng_session_extended
);
2269 size_t session_count
, i
;
2270 struct lttng_session_extended
*sessions_extended_begin
;
2271 struct lttng_session
*sessions
= NULL
;
2273 memset(&lsm
, 0, sizeof(lsm
));
2274 lsm
.cmd_type
= LTTNG_LIST_SESSIONS
;
2275 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) &sessions
);
2280 ret
= -LTTNG_ERR_FATAL
;
2284 if (ret
% session_size
) {
2285 ret
= -LTTNG_ERR_UNK
;
2287 *out_sessions
= NULL
;
2290 session_count
= (size_t) ret
/ session_size
;
2291 sessions_extended_begin
= (struct lttng_session_extended
*)
2292 (&sessions
[session_count
]);
2294 /* Set extended session info pointers. */
2295 for (i
= 0; i
< session_count
; i
++) {
2296 struct lttng_session
*session
= &sessions
[i
];
2297 struct lttng_session_extended
*extended
=
2298 &(sessions_extended_begin
[i
]);
2300 session
->extended
.ptr
= extended
;
2303 ret
= (int) session_count
;
2304 *out_sessions
= sessions
;
2309 enum lttng_error_code
lttng_session_get_creation_time(
2310 const struct lttng_session
*session
, uint64_t *creation_time
)
2312 enum lttng_error_code ret
= LTTNG_OK
;
2313 struct lttng_session_extended
*extended
;
2315 if (!session
|| !creation_time
|| !session
->extended
.ptr
) {
2316 ret
= LTTNG_ERR_INVALID
;
2320 extended
= session
->extended
.ptr
;
2321 if (!extended
->creation_time
.is_set
) {
2322 /* Not created on the session daemon yet. */
2323 ret
= LTTNG_ERR_SESSION_NOT_EXIST
;
2326 *creation_time
= extended
->creation_time
.value
;
2331 int lttng_set_session_shm_path(const char *session_name
,
2332 const char *shm_path
)
2335 struct lttcomm_session_msg lsm
;
2337 if (session_name
== NULL
) {
2338 return -LTTNG_ERR_INVALID
;
2341 memset(&lsm
, 0, sizeof(lsm
));
2342 lsm
.cmd_type
= LTTNG_SET_SESSION_SHM_PATH
;
2344 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
2345 sizeof(lsm
.session
.name
));
2347 ret
= -LTTNG_ERR_INVALID
;
2351 ret
= lttng_strncpy(lsm
.u
.set_shm_path
.shm_path
, shm_path
?: "",
2352 sizeof(lsm
.u
.set_shm_path
.shm_path
));
2354 ret
= -LTTNG_ERR_INVALID
;
2358 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
2364 * Ask the session daemon for all available domains of a session.
2365 * Sets the contents of the domains array.
2366 * Returns the number of lttng_domain entries in domains;
2367 * on error, returns a negative value.
2369 int lttng_list_domains(const char *session_name
,
2370 struct lttng_domain
**domains
)
2373 struct lttcomm_session_msg lsm
;
2375 if (session_name
== NULL
) {
2376 ret
= -LTTNG_ERR_INVALID
;
2380 memset(&lsm
, 0, sizeof(lsm
));
2381 lsm
.cmd_type
= LTTNG_LIST_DOMAINS
;
2383 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
2384 sizeof(lsm
.session
.name
));
2386 ret
= -LTTNG_ERR_INVALID
;
2390 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) domains
);
2395 return ret
/ sizeof(struct lttng_domain
);
2401 * Ask the session daemon for all available channels of a session.
2402 * Sets the contents of the channels array.
2403 * Returns the number of lttng_channel entries in channels;
2404 * on error, returns a negative value.
2406 int lttng_list_channels(struct lttng_handle
*handle
,
2407 struct lttng_channel
**channels
)
2410 size_t channel_count
, i
;
2411 const size_t channel_size
= sizeof(struct lttng_channel
) +
2412 sizeof(struct lttng_channel_extended
);
2413 struct lttcomm_session_msg lsm
;
2416 if (handle
== NULL
) {
2417 ret
= -LTTNG_ERR_INVALID
;
2421 memset(&lsm
, 0, sizeof(lsm
));
2422 lsm
.cmd_type
= LTTNG_LIST_CHANNELS
;
2423 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
2424 sizeof(lsm
.session
.name
));
2426 ret
= -LTTNG_ERR_INVALID
;
2430 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
2432 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) channels
);
2437 if (ret
% channel_size
) {
2438 ret
= -LTTNG_ERR_UNK
;
2443 channel_count
= (size_t) ret
/ channel_size
;
2445 /* Set extended info pointers */
2446 extended_at
= ((void *) *channels
) +
2447 channel_count
* sizeof(struct lttng_channel
);
2448 for (i
= 0; i
< channel_count
; i
++) {
2449 struct lttng_channel
*chan
= &(*channels
)[i
];
2451 chan
->attr
.extended
.ptr
= extended_at
;
2452 extended_at
+= sizeof(struct lttng_channel_extended
);
2455 ret
= (int) channel_count
;
2460 enum lttng_error_code
lttng_list_maps(struct lttng_handle
*handle
,
2461 struct lttng_map_list
**map_list
)
2464 enum lttng_error_code ret_code
= LTTNG_OK
;
2465 struct lttcomm_session_msg lsm
= { .cmd_type
= LTTNG_LIST_MAPS
};
2466 struct lttng_map_list
*local_map_list
= NULL
;
2467 struct lttng_payload reply
;
2468 struct lttng_payload_view lsm_view
=
2469 lttng_payload_view_init_from_buffer(
2470 (const char *) &lsm
, 0, sizeof(lsm
));
2472 lttng_payload_init(&reply
);
2474 if (handle
== NULL
) {
2475 ret
= -LTTNG_ERR_INVALID
;
2479 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
2480 sizeof(lsm
.session
.name
));
2482 ret
= -LTTNG_ERR_INVALID
;
2486 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
2488 ret
= lttng_ctl_ask_sessiond_payload(&lsm_view
, &reply
);
2490 ret_code
= (enum lttng_error_code
) -ret
;
2495 struct lttng_payload_view reply_view
=
2496 lttng_payload_view_from_payload(
2497 &reply
, 0, reply
.buffer
.size
);
2499 ret
= lttng_map_list_create_from_payload(
2500 &reply_view
, &local_map_list
);
2502 ret_code
= LTTNG_ERR_FATAL
;
2507 *map_list
= local_map_list
;
2508 local_map_list
= NULL
;
2510 lttng_payload_reset(&reply
);
2511 lttng_map_list_destroy(local_map_list
);
2516 * Ask the session daemon for all available events of a session channel.
2517 * Sets the contents of the events array.
2518 * Returns the number of lttng_event entries in events;
2519 * on error, returns a negative value.
2521 int lttng_list_events(struct lttng_handle
*handle
,
2522 const char *channel_name
, struct lttng_event
**events
)
2525 struct lttcomm_session_msg lsm
= {};
2526 const struct lttcomm_event_command_header
*cmd_header
= NULL
;
2527 uint32_t nb_events
, i
;
2528 const void *comm_ext_at
;
2529 struct lttng_dynamic_buffer listing
;
2531 struct lttng_payload payload
;
2532 struct lttng_payload payload_copy
;
2533 struct lttng_payload_view lsm_view
=
2534 lttng_payload_view_init_from_buffer(
2535 (const char *) &lsm
, 0, sizeof(lsm
));
2536 struct lttng_buffer_view cmd_header_view
;
2537 struct lttng_buffer_view cmd_payload_view
;
2538 struct lttng_buffer_view flat_events_view
;
2539 struct lttng_buffer_view ext_view
;
2541 /* Safety check. An handle and channel name are mandatory */
2542 if (handle
== NULL
|| channel_name
== NULL
) {
2543 ret
= -LTTNG_ERR_INVALID
;
2547 lttng_payload_init(&payload
);
2548 lttng_payload_init(&payload_copy
);
2550 lsm
.cmd_type
= LTTNG_LIST_EVENTS
;
2551 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
2552 sizeof(lsm
.session
.name
));
2554 ret
= -LTTNG_ERR_INVALID
;
2558 ret
= lttng_strncpy(lsm
.u
.list
.channel_name
, channel_name
,
2559 sizeof(lsm
.u
.list
.channel_name
));
2561 ret
= -LTTNG_ERR_INVALID
;
2565 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
2567 ret
= lttng_ctl_ask_sessiond_payload(&lsm_view
, &payload
);
2573 * A copy of the payload is performed since it will be
2574 * consumed twice. Consuming the same payload twice is invalid since
2575 * it will cause any received file descriptor to become "shared"
2576 * between different instances of the resulting objects.
2578 ret
= lttng_payload_copy(&payload
, &payload_copy
);
2580 ret
= -LTTNG_ERR_NOMEM
;
2584 cmd_header_view
= lttng_buffer_view_from_dynamic_buffer(
2585 &payload
.buffer
, 0, sizeof(*cmd_header
));
2586 if (!lttng_buffer_view_is_valid(&cmd_header_view
)) {
2587 ret
= -LTTNG_ERR_INVALID_PROTOCOL
;
2591 cmd_header
= (typeof(cmd_header
)) cmd_header_view
.data
;
2593 /* Set number of events and free command header */
2594 nb_events
= cmd_header
->nb_events
;
2595 if (nb_events
> INT_MAX
) {
2596 ret
= -LTTNG_ERR_OVERFLOW
;
2600 cmd_payload_view
= lttng_buffer_view_from_dynamic_buffer(
2601 &payload
.buffer
, sizeof(*cmd_header
), -1);
2604 * The buffer that is returned must contain a "flat" version of
2605 * the events that are returned. In other words, all pointers
2606 * within an lttng_event must point to a location within the returned
2607 * buffer so that the user may free everything by simply calling free()
2608 * on the returned buffer. This is needed in order to maintain API
2611 * A first pass is performed to compute the size of the buffer that
2612 * must be allocated. A second pass is then performed to setup
2613 * the returned events so that their members always point within the
2616 * The layout of the returned buffer is as follows:
2617 * - struct lttng_event[nb_events],
2618 * - nb_events times the following:
2619 * - struct lttng_event_extended,
2620 * - flattened version of userspace_probe_location
2621 * - filter_expression
2623 * - padding to align to 64-bits
2625 ext_view
= lttng_buffer_view_from_view(&cmd_payload_view
,
2626 nb_events
* sizeof(struct lttng_event
), -1);
2627 comm_ext_at
= ext_view
.data
;
2628 storage_req
= nb_events
* sizeof(struct lttng_event
);
2630 struct lttng_payload_view payload_view
=
2631 lttng_payload_view_from_payload(&payload
, 0, -1);
2633 for (i
= 0; i
< nb_events
; i
++) {
2634 const struct lttcomm_event_extended_header
*ext_comm
=
2635 (struct lttcomm_event_extended_header
*)
2637 int probe_storage_req
= 0;
2639 comm_ext_at
+= sizeof(*ext_comm
);
2640 comm_ext_at
+= ext_comm
->filter_len
;
2641 comm_ext_at
+= ext_comm
->nb_exclusions
*
2642 LTTNG_SYMBOL_NAME_LEN
;
2644 if (ext_comm
->userspace_probe_location_len
) {
2645 struct lttng_userspace_probe_location
2646 *probe_location
= NULL
;
2647 struct lttng_payload_view probe_location_view
= lttng_payload_view_from_view(
2649 (const char *) comm_ext_at
-
2650 payload_view
.buffer
.data
,
2651 ext_comm
->userspace_probe_location_len
);
2653 if (!lttng_payload_view_is_valid(&probe_location_view
)) {
2654 ret
= -LTTNG_ERR_PROBE_LOCATION_INVAL
;
2659 * Create a temporary userspace probe location
2660 * to determine the size needed by a "flattened"
2661 * version of that same probe location.
2663 ret
= lttng_userspace_probe_location_create_from_payload(
2664 &probe_location_view
,
2667 ret
= -LTTNG_ERR_PROBE_LOCATION_INVAL
;
2671 ret
= lttng_userspace_probe_location_flatten(
2672 probe_location
, NULL
);
2673 lttng_userspace_probe_location_destroy(
2676 ret
= -LTTNG_ERR_PROBE_LOCATION_INVAL
;
2680 probe_storage_req
= ret
;
2681 comm_ext_at
+= ext_comm
->userspace_probe_location_len
;
2684 storage_req
+= sizeof(struct lttng_event_extended
);
2685 storage_req
+= ext_comm
->filter_len
;
2686 storage_req
+= ext_comm
->nb_exclusions
*
2687 LTTNG_SYMBOL_NAME_LEN
;
2688 /* Padding to ensure the flat probe is aligned. */
2689 storage_req
= ALIGN_TO(storage_req
, sizeof(uint64_t));
2690 storage_req
+= probe_storage_req
;
2694 lttng_dynamic_buffer_init(&listing
);
2696 * We must ensure that "listing" is never resized so as to preserve
2697 * the validity of the flattened objects.
2699 ret
= lttng_dynamic_buffer_set_capacity(&listing
, storage_req
);
2701 ret
= -LTTNG_ERR_NOMEM
;
2705 cmd_payload_view
= lttng_buffer_view_from_dynamic_buffer(
2706 &payload_copy
.buffer
, sizeof(*cmd_header
), -1);
2707 flat_events_view
= lttng_buffer_view_from_view(&cmd_payload_view
, 0,
2708 nb_events
* sizeof(struct lttng_event
));
2709 ret
= lttng_dynamic_buffer_append_view(&listing
, &flat_events_view
);
2711 ret
= -LTTNG_ERR_NOMEM
;
2712 goto free_dynamic_buffer
;
2715 ext_view
= lttng_buffer_view_from_view(&cmd_payload_view
,
2716 nb_events
* sizeof(struct lttng_event
), -1);
2717 comm_ext_at
= ext_view
.data
;
2720 struct lttng_payload_view payload_copy_view
=
2721 lttng_payload_view_from_payload(
2722 &payload_copy
, 0, -1);
2724 for (i
= 0; i
< nb_events
; i
++) {
2725 struct lttng_event
*event
= (typeof(event
))(
2727 (sizeof(struct lttng_event
) * i
));
2728 const struct lttcomm_event_extended_header
*ext_comm
=
2729 (typeof(ext_comm
)) comm_ext_at
;
2730 struct lttng_event_extended
*event_extended
=
2731 (typeof(event_extended
))(listing
.data
+
2734 /* Insert struct lttng_event_extended. */
2735 ret
= lttng_dynamic_buffer_set_size(&listing
,
2736 listing
.size
+ sizeof(*event_extended
));
2738 ret
= -LTTNG_ERR_NOMEM
;
2739 goto free_dynamic_buffer
;
2741 event
->extended
.ptr
= event_extended
;
2743 comm_ext_at
+= sizeof(*ext_comm
);
2745 /* Insert filter expression. */
2746 if (ext_comm
->filter_len
) {
2747 event_extended
->filter_expression
=
2748 listing
.data
+ listing
.size
;
2749 ret
= lttng_dynamic_buffer_append(&listing
,
2751 ext_comm
->filter_len
);
2753 ret
= -LTTNG_ERR_NOMEM
;
2754 goto free_dynamic_buffer
;
2756 comm_ext_at
+= ext_comm
->filter_len
;
2759 /* Insert exclusions. */
2760 if (ext_comm
->nb_exclusions
) {
2761 event_extended
->exclusions
.count
=
2762 ext_comm
->nb_exclusions
;
2763 event_extended
->exclusions
.strings
=
2764 listing
.data
+ listing
.size
;
2766 ret
= lttng_dynamic_buffer_append(&listing
,
2768 ext_comm
->nb_exclusions
*
2769 LTTNG_SYMBOL_NAME_LEN
);
2771 ret
= -LTTNG_ERR_NOMEM
;
2772 goto free_dynamic_buffer
;
2774 comm_ext_at
+= ext_comm
->nb_exclusions
*
2775 LTTNG_SYMBOL_NAME_LEN
;
2778 /* Insert padding to align to 64-bits. */
2779 ret
= lttng_dynamic_buffer_set_size(&listing
,
2780 ALIGN_TO(listing
.size
,
2783 ret
= -LTTNG_ERR_NOMEM
;
2784 goto free_dynamic_buffer
;
2787 /* Insert flattened userspace probe location. */
2788 if (ext_comm
->userspace_probe_location_len
) {
2789 struct lttng_userspace_probe_location
2790 *probe_location
= NULL
;
2791 struct lttng_payload_view probe_location_view
= lttng_payload_view_from_view(
2793 (const char *) comm_ext_at
-
2794 payload_copy_view
.buffer
.data
,
2795 ext_comm
->userspace_probe_location_len
);
2797 if (!lttng_payload_view_is_valid(&probe_location_view
)) {
2798 ret
= -LTTNG_ERR_PROBE_LOCATION_INVAL
;
2799 goto free_dynamic_buffer
;
2802 ret
= lttng_userspace_probe_location_create_from_payload(
2803 &probe_location_view
,
2806 ret
= -LTTNG_ERR_PROBE_LOCATION_INVAL
;
2807 goto free_dynamic_buffer
;
2810 event_extended
->probe_location
= (struct lttng_userspace_probe_location
2813 ret
= lttng_userspace_probe_location_flatten(
2814 probe_location
, &listing
);
2815 lttng_userspace_probe_location_destroy(
2818 ret
= -LTTNG_ERR_PROBE_LOCATION_INVAL
;
2819 goto free_dynamic_buffer
;
2822 comm_ext_at
+= ext_comm
->userspace_probe_location_len
;
2827 /* Don't reset listing buffer as we return its content. */
2828 *events
= (struct lttng_event
*) listing
.data
;
2829 lttng_dynamic_buffer_init(&listing
);
2830 ret
= (int) nb_events
;
2831 free_dynamic_buffer
:
2832 lttng_dynamic_buffer_reset(&listing
);
2834 lttng_payload_reset(&payload
);
2835 lttng_payload_reset(&payload_copy
);
2840 * Sets the tracing_group variable with name.
2841 * This function allocates memory pointed to by tracing_group.
2842 * On success, returns 0, on error, returns -1 (null name) or -ENOMEM.
2844 int lttng_set_tracing_group(const char *name
)
2847 return -LTTNG_ERR_INVALID
;
2850 if (asprintf(&tracing_group
, "%s", name
) < 0) {
2851 return -LTTNG_ERR_FATAL
;
2857 int lttng_calibrate(struct lttng_handle
*handle
,
2858 struct lttng_calibrate
*calibrate
)
2861 * This command was removed in LTTng 2.9.
2863 return -LTTNG_ERR_UND
;
2867 * Set default channel attributes.
2868 * If either or both of the arguments are null, attr content is zeroe'd.
2870 void lttng_channel_set_default_attr(struct lttng_domain
*domain
,
2871 struct lttng_channel_attr
*attr
)
2873 struct lttng_channel_extended
*extended
;
2876 if (attr
== NULL
|| domain
== NULL
) {
2880 extended
= (struct lttng_channel_extended
*) attr
->extended
.ptr
;
2881 memset(attr
, 0, sizeof(struct lttng_channel_attr
));
2883 /* Same for all domains. */
2884 attr
->overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
2885 attr
->tracefile_size
= DEFAULT_CHANNEL_TRACEFILE_SIZE
;
2886 attr
->tracefile_count
= DEFAULT_CHANNEL_TRACEFILE_COUNT
;
2888 switch (domain
->type
) {
2889 case LTTNG_DOMAIN_KERNEL
:
2890 attr
->switch_timer_interval
=
2891 DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER
;
2892 attr
->read_timer_interval
= DEFAULT_KERNEL_CHANNEL_READ_TIMER
;
2893 attr
->subbuf_size
= default_get_kernel_channel_subbuf_size();
2894 attr
->num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
2895 attr
->output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
2897 extended
->monitor_timer_interval
=
2898 DEFAULT_KERNEL_CHANNEL_MONITOR_TIMER
;
2899 extended
->blocking_timeout
=
2900 DEFAULT_KERNEL_CHANNEL_BLOCKING_TIMEOUT
;
2903 case LTTNG_DOMAIN_UST
:
2904 switch (domain
->buf_type
) {
2905 case LTTNG_BUFFER_PER_UID
:
2906 attr
->subbuf_size
= default_get_ust_uid_channel_subbuf_size();
2907 attr
->num_subbuf
= DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM
;
2908 attr
->output
= DEFAULT_UST_UID_CHANNEL_OUTPUT
;
2909 attr
->switch_timer_interval
=
2910 DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER
;
2911 attr
->read_timer_interval
=
2912 DEFAULT_UST_UID_CHANNEL_READ_TIMER
;
2914 extended
->monitor_timer_interval
=
2915 DEFAULT_UST_UID_CHANNEL_MONITOR_TIMER
;
2916 extended
->blocking_timeout
=
2917 DEFAULT_UST_UID_CHANNEL_BLOCKING_TIMEOUT
;
2920 case LTTNG_BUFFER_PER_PID
:
2922 attr
->subbuf_size
= default_get_ust_pid_channel_subbuf_size();
2923 attr
->num_subbuf
= DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM
;
2924 attr
->output
= DEFAULT_UST_PID_CHANNEL_OUTPUT
;
2925 attr
->switch_timer_interval
=
2926 DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER
;
2927 attr
->read_timer_interval
=
2928 DEFAULT_UST_PID_CHANNEL_READ_TIMER
;
2930 extended
->monitor_timer_interval
=
2931 DEFAULT_UST_PID_CHANNEL_MONITOR_TIMER
;
2932 extended
->blocking_timeout
=
2933 DEFAULT_UST_PID_CHANNEL_BLOCKING_TIMEOUT
;
2938 /* Default behavior: leave set to 0. */
2942 attr
->extended
.ptr
= extended
;
2945 int lttng_channel_get_discarded_event_count(struct lttng_channel
*channel
,
2946 uint64_t *discarded_events
)
2949 struct lttng_channel_extended
*chan_ext
;
2951 if (!channel
|| !discarded_events
) {
2952 ret
= -LTTNG_ERR_INVALID
;
2956 chan_ext
= channel
->attr
.extended
.ptr
;
2959 * This can happen since the lttng_channel structure is
2960 * used for other tasks where this pointer is never set.
2962 *discarded_events
= 0;
2966 *discarded_events
= chan_ext
->discarded_events
;
2971 int lttng_channel_get_lost_packet_count(struct lttng_channel
*channel
,
2972 uint64_t *lost_packets
)
2975 struct lttng_channel_extended
*chan_ext
;
2977 if (!channel
|| !lost_packets
) {
2978 ret
= -LTTNG_ERR_INVALID
;
2982 chan_ext
= channel
->attr
.extended
.ptr
;
2985 * This can happen since the lttng_channel structure is
2986 * used for other tasks where this pointer is never set.
2992 *lost_packets
= chan_ext
->lost_packets
;
2997 int lttng_channel_get_monitor_timer_interval(struct lttng_channel
*chan
,
2998 uint64_t *monitor_timer_interval
)
3002 if (!chan
|| !monitor_timer_interval
) {
3003 ret
= -LTTNG_ERR_INVALID
;
3007 if (!chan
->attr
.extended
.ptr
) {
3008 ret
= -LTTNG_ERR_INVALID
;
3012 *monitor_timer_interval
= ((struct lttng_channel_extended
*)
3013 chan
->attr
.extended
.ptr
)->monitor_timer_interval
;
3018 int lttng_channel_set_monitor_timer_interval(struct lttng_channel
*chan
,
3019 uint64_t monitor_timer_interval
)
3023 if (!chan
|| !chan
->attr
.extended
.ptr
) {
3024 ret
= -LTTNG_ERR_INVALID
;
3028 ((struct lttng_channel_extended
*)
3029 chan
->attr
.extended
.ptr
)->monitor_timer_interval
=
3030 monitor_timer_interval
;
3035 int lttng_channel_get_blocking_timeout(struct lttng_channel
*chan
,
3036 int64_t *blocking_timeout
)
3040 if (!chan
|| !blocking_timeout
) {
3041 ret
= -LTTNG_ERR_INVALID
;
3045 if (!chan
->attr
.extended
.ptr
) {
3046 ret
= -LTTNG_ERR_INVALID
;
3050 *blocking_timeout
= ((struct lttng_channel_extended
*)
3051 chan
->attr
.extended
.ptr
)->blocking_timeout
;
3056 int lttng_channel_set_blocking_timeout(struct lttng_channel
*chan
,
3057 int64_t blocking_timeout
)
3060 int64_t msec_timeout
;
3062 if (!chan
|| !chan
->attr
.extended
.ptr
) {
3063 ret
= -LTTNG_ERR_INVALID
;
3067 if (blocking_timeout
< 0 && blocking_timeout
!= -1) {
3068 ret
= -LTTNG_ERR_INVALID
;
3073 * LTTng-ust's use of poll() to implement this timeout mechanism forces
3074 * us to accept a narrower range of values (msecs expressed as a signed
3077 msec_timeout
= blocking_timeout
/ 1000;
3078 if (msec_timeout
!= (int32_t) msec_timeout
) {
3079 ret
= -LTTNG_ERR_INVALID
;
3083 ((struct lttng_channel_extended
*)
3084 chan
->attr
.extended
.ptr
)->blocking_timeout
=
3091 * Check if session daemon is alive.
3093 * Return 1 if alive or 0 if not.
3094 * On error returns a negative value.
3096 int lttng_session_daemon_alive(void)
3100 ret
= set_session_daemon_path();
3106 if (*sessiond_sock_path
== '\0') {
3108 * No socket path set. Weird error which means the constructor
3114 ret
= try_connect_sessiond(sessiond_sock_path
);
3125 * Set URL for a consumer for a session and domain.
3127 * Return 0 on success, else a negative value.
3129 int lttng_set_consumer_url(struct lttng_handle
*handle
,
3130 const char *control_url
, const char *data_url
)
3134 struct lttcomm_session_msg lsm
;
3135 struct lttng_uri
*uris
= NULL
;
3137 if (handle
== NULL
|| (control_url
== NULL
&& data_url
== NULL
)) {
3138 ret
= -LTTNG_ERR_INVALID
;
3142 memset(&lsm
, 0, sizeof(lsm
));
3144 lsm
.cmd_type
= LTTNG_SET_CONSUMER_URI
;
3146 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
3147 sizeof(lsm
.session
.name
));
3149 ret
= -LTTNG_ERR_INVALID
;
3153 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
3155 size
= uri_parse_str_urls(control_url
, data_url
, &uris
);
3157 ret
= -LTTNG_ERR_INVALID
;
3161 lsm
.u
.uri
.size
= size
;
3163 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
3164 sizeof(struct lttng_uri
) * size
, NULL
);
3174 int lttng_enable_consumer(struct lttng_handle
*handle
);
3175 int lttng_enable_consumer(struct lttng_handle
*handle
)
3183 int lttng_disable_consumer(struct lttng_handle
*handle
);
3184 int lttng_disable_consumer(struct lttng_handle
*handle
)
3192 int _lttng_create_session_ext(const char *name
, const char *url
,
3193 const char *datetime
);
3194 int _lttng_create_session_ext(const char *name
, const char *url
,
3195 const char *datetime
)
3201 * For a given session name, this call checks if the data is ready to be read
3202 * or is still being extracted by the consumer(s) hence not ready to be used by
3205 int lttng_data_pending(const char *session_name
)
3208 struct lttcomm_session_msg lsm
;
3209 uint8_t *pending
= NULL
;
3211 if (session_name
== NULL
) {
3212 return -LTTNG_ERR_INVALID
;
3215 memset(&lsm
, 0, sizeof(lsm
));
3216 lsm
.cmd_type
= LTTNG_DATA_PENDING
;
3218 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
3219 sizeof(lsm
.session
.name
));
3221 ret
= -LTTNG_ERR_INVALID
;
3225 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) &pending
);
3228 } else if (ret
!= 1) {
3229 /* Unexpected payload size */
3230 ret
= -LTTNG_ERR_INVALID
;
3232 } else if (!pending
) {
3233 /* Internal error. */
3234 ret
= -LTTNG_ERR_UNK
;
3238 ret
= (int) *pending
;
3245 * Regenerate the metadata for a session.
3246 * Return 0 on success, a negative error code on error.
3248 int lttng_regenerate_metadata(const char *session_name
)
3251 struct lttcomm_session_msg lsm
;
3253 if (!session_name
) {
3254 ret
= -LTTNG_ERR_INVALID
;
3258 memset(&lsm
, 0, sizeof(lsm
));
3259 lsm
.cmd_type
= LTTNG_REGENERATE_METADATA
;
3261 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
3262 sizeof(lsm
.session
.name
));
3264 ret
= -LTTNG_ERR_INVALID
;
3268 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
3279 * Deprecated, replaced by lttng_regenerate_metadata.
3281 int lttng_metadata_regenerate(const char *session_name
)
3283 return lttng_regenerate_metadata(session_name
);
3287 * Regenerate the statedump of a session.
3288 * Return 0 on success, a negative error code on error.
3290 int lttng_regenerate_statedump(const char *session_name
)
3293 struct lttcomm_session_msg lsm
;
3295 if (!session_name
) {
3296 ret
= -LTTNG_ERR_INVALID
;
3300 memset(&lsm
, 0, sizeof(lsm
));
3301 lsm
.cmd_type
= LTTNG_REGENERATE_STATEDUMP
;
3303 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
3304 sizeof(lsm
.session
.name
));
3306 ret
= -LTTNG_ERR_INVALID
;
3310 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
3320 int lttng_register_trigger(struct lttng_trigger
*trigger
)
3323 struct lttcomm_session_msg lsm
= {
3324 .cmd_type
= LTTNG_REGISTER_TRIGGER
,
3326 struct lttcomm_session_msg
*message_lsm
;
3327 struct lttng_payload message
;
3328 struct lttng_payload reply
;
3329 struct lttng_trigger
*reply_trigger
= NULL
;
3330 enum lttng_domain_type domain_type
;
3331 const struct lttng_credentials user_creds
= {
3332 .uid
= LTTNG_OPTIONAL_INIT_VALUE(geteuid()),
3333 .gid
= LTTNG_OPTIONAL_INIT_UNSET
,
3337 lttng_payload_init(&message
);
3338 lttng_payload_init(&reply
);
3341 ret
= -LTTNG_ERR_INVALID
;
3345 if (!trigger
->creds
.uid
.is_set
) {
3346 /* Use the client's credentials as the trigger credentials. */
3347 lttng_trigger_set_credentials(trigger
, &user_creds
);
3350 * Validate that either the current trigger credentials and the
3351 * client credentials are identical or that the current user is
3352 * root. The root user can register, unregister triggers for
3353 * himself and other users.
3355 * This check is also present on the sessiond side, using the
3356 * credentials passed on the socket. These check are all
3359 const struct lttng_credentials
*trigger_creds
=
3360 lttng_trigger_get_credentials(trigger
);
3362 if (!lttng_credentials_is_equal_uid(trigger_creds
, &user_creds
)) {
3363 if (lttng_credentials_get_uid(&user_creds
) != 0) {
3364 ret
= -LTTNG_ERR_EPERM
;
3370 if (!lttng_trigger_validate(trigger
)) {
3371 ret
= -LTTNG_ERR_INVALID_TRIGGER
;
3375 domain_type
= lttng_trigger_get_underlying_domain_type_restriction(
3378 lsm
.domain
.type
= domain_type
;
3380 ret
= lttng_dynamic_buffer_append(&message
.buffer
, &lsm
, sizeof(lsm
));
3382 ret
= -LTTNG_ERR_NOMEM
;
3386 ret
= lttng_trigger_serialize(trigger
, &message
);
3388 ret
= -LTTNG_ERR_UNK
;
3393 * This is needed to populate the trigger object size for the command
3396 message_lsm
= (struct lttcomm_session_msg
*) message
.buffer
.data
;
3398 message_lsm
->u
.trigger
.length
= (uint32_t) message
.buffer
.size
- sizeof(lsm
);
3401 struct lttng_payload_view message_view
=
3402 lttng_payload_view_from_payload(
3405 message_lsm
->fd_count
= lttng_payload_view_get_fd_handle_count(
3407 ret
= lttng_ctl_ask_sessiond_payload(&message_view
, &reply
);
3414 struct lttng_payload_view reply_view
=
3415 lttng_payload_view_from_payload(
3416 &reply
, 0, reply
.buffer
.size
);
3418 ret
= lttng_trigger_create_from_payload(
3419 &reply_view
, &reply_trigger
);
3421 ret
= -LTTNG_ERR_FATAL
;
3426 ret
= lttng_trigger_assign_name(trigger
, reply_trigger
);
3428 ret
= -LTTNG_ERR_FATAL
;
3434 lttng_payload_reset(&message
);
3435 lttng_payload_reset(&reply
);
3436 lttng_trigger_destroy(reply_trigger
);
3440 int lttng_unregister_trigger(const struct lttng_trigger
*trigger
)
3443 struct lttcomm_session_msg lsm
;
3444 struct lttcomm_session_msg
*message_lsm
;
3445 struct lttng_payload message
;
3446 struct lttng_payload reply
;
3447 struct lttng_trigger
*copy
= NULL
;
3448 const struct lttng_credentials user_creds
= {
3449 .uid
= LTTNG_OPTIONAL_INIT_VALUE(geteuid()),
3450 .gid
= LTTNG_OPTIONAL_INIT_UNSET
,
3453 lttng_payload_init(&message
);
3454 lttng_payload_init(&reply
);
3457 ret
= -LTTNG_ERR_INVALID
;
3461 copy
= lttng_trigger_copy(trigger
);
3463 ret
= -LTTNG_ERR_UNK
;
3467 if (!copy
->creds
.uid
.is_set
) {
3468 /* Use the client credentials as the trigger credentials */
3469 lttng_trigger_set_credentials(copy
, &user_creds
);
3472 * Validate that either the current trigger credentials and the
3473 * client credentials are identical or that the current user is
3474 * root. The root user can register, unregister triggers for
3475 * himself and other users.
3477 * This check is also present on the sessiond side, using the
3478 * credentials passed on the socket. These check are all
3481 const struct lttng_credentials
*trigger_creds
=
3482 lttng_trigger_get_credentials(copy
);
3483 if (!lttng_credentials_is_equal_uid(trigger_creds
, &user_creds
)) {
3484 if (lttng_credentials_get_uid(&user_creds
) != 0) {
3485 ret
= -LTTNG_ERR_EPERM
;
3491 if (!lttng_trigger_validate(copy
)) {
3492 ret
= -LTTNG_ERR_INVALID_TRIGGER
;
3496 memset(&lsm
, 0, sizeof(lsm
));
3497 lsm
.cmd_type
= LTTNG_UNREGISTER_TRIGGER
;
3499 ret
= lttng_dynamic_buffer_append(&message
.buffer
, &lsm
, sizeof(lsm
));
3501 ret
= -LTTNG_ERR_NOMEM
;
3506 * This is needed to populate the trigger object size for the command
3507 * header and number of fds sent.
3509 message_lsm
= (struct lttcomm_session_msg
*) message
.buffer
.data
;
3511 ret
= lttng_trigger_serialize(copy
, &message
);
3513 ret
= -LTTNG_ERR_UNK
;
3517 message_lsm
->u
.trigger
.length
= (uint32_t) message
.buffer
.size
- sizeof(lsm
);
3520 struct lttng_payload_view message_view
=
3521 lttng_payload_view_from_payload(
3525 * Update the message header with the number of fd that will be
3528 message_lsm
->fd_count
= lttng_payload_view_get_fd_handle_count(
3531 ret
= lttng_ctl_ask_sessiond_payload(&message_view
, &reply
);
3539 lttng_trigger_destroy(copy
);
3540 lttng_payload_reset(&message
);
3541 lttng_payload_reset(&reply
);
3546 * Ask the session daemon for all registered triggers for the current user.
3548 * Allocates and return an lttng_triggers set.
3549 * On error, returns a suitable lttng_error_code.
3551 enum lttng_error_code
lttng_list_triggers(struct lttng_triggers
**triggers
)
3554 enum lttng_error_code ret_code
= LTTNG_OK
;
3555 struct lttcomm_session_msg lsm
= { .cmd_type
= LTTNG_LIST_TRIGGERS
};
3556 struct lttng_triggers
*local_triggers
= NULL
;
3557 struct lttng_payload reply
;
3558 struct lttng_payload_view lsm_view
=
3559 lttng_payload_view_init_from_buffer(
3560 (const char *) &lsm
, 0, sizeof(lsm
));
3562 lttng_payload_init(&reply
);
3564 ret
= lttng_ctl_ask_sessiond_payload(&lsm_view
, &reply
);
3566 ret_code
= (enum lttng_error_code
) -ret
;
3571 struct lttng_payload_view reply_view
=
3572 lttng_payload_view_from_payload(
3573 &reply
, 0, reply
.buffer
.size
);
3575 ret
= lttng_triggers_create_from_payload(
3576 &reply_view
, &local_triggers
);
3578 ret_code
= LTTNG_ERR_FATAL
;
3583 *triggers
= local_triggers
;
3584 local_triggers
= NULL
;
3586 lttng_payload_reset(&reply
);
3587 lttng_triggers_destroy(local_triggers
);
3592 * Ask the session daemon for all values for a given map.
3593 * On error, returns a negative value.
3595 enum lttng_error_code
lttng_list_map_content(
3596 struct lttng_handle
*handle
, const struct lttng_map
*map
,
3597 const struct lttng_map_query
*map_query
,
3598 struct lttng_map_content
**map_content
)
3600 struct lttcomm_session_msg lsm
= {
3601 .cmd_type
= LTTNG_LIST_MAP_VALUES
,
3603 struct lttcomm_session_msg
*message_lsm
;
3604 struct lttng_payload message
;
3605 struct lttng_payload reply
;
3606 enum lttng_error_code ret
;
3607 struct lttng_map_content
*local_map_content
= NULL
;
3608 uint32_t map_length
, map_query_length
;
3610 lttng_payload_init(&message
);
3611 lttng_payload_init(&reply
);
3613 if (!map
|| !map_query
) {
3614 ret
= -LTTNG_ERR_INVALID
;
3618 lsm
.domain
.type
= handle
->domain
.type
;
3619 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
3620 sizeof(lsm
.session
.name
));
3622 ret
= -LTTNG_ERR_NOMEM
;
3626 ret
= lttng_dynamic_buffer_append(&message
.buffer
, &lsm
, sizeof(lsm
));
3628 ret
= -LTTNG_ERR_NOMEM
;
3632 ret
= lttng_map_serialize(map
, &message
);
3634 ret
= -LTTNG_ERR_UNK
;
3638 map_length
= (uint32_t) message
.buffer
.size
- sizeof(lsm
);
3640 ret
= lttng_map_query_serialize(map_query
, &message
);
3642 ret
= -LTTNG_ERR_UNK
;
3645 map_query_length
= (uint32_t) message
.buffer
.size
- map_length
- sizeof(lsm
);
3647 message_lsm
= (struct lttcomm_session_msg
*) message
.buffer
.data
;
3648 message_lsm
->u
.list_map_values
.map_length
= map_length
;
3649 message_lsm
->u
.list_map_values
.query_length
= map_query_length
;
3651 struct lttng_payload_view message_view
=
3652 lttng_payload_view_from_payload(
3655 ret
= lttng_ctl_ask_sessiond_payload(&message_view
, &reply
);
3663 struct lttng_payload_view reply_view
=
3664 lttng_payload_view_from_payload(
3665 &reply
, 0, reply
.buffer
.size
);
3666 ret
= lttng_map_content_create_from_payload(
3667 &reply_view
, &local_map_content
);
3669 ret
= LTTNG_ERR_FATAL
;
3674 *map_content
= local_map_content
;
3675 local_map_content
= NULL
;
3680 lttng_payload_reset(&reply
);
3681 lttng_payload_reset(&message
);
3682 lttng_map_content_destroy(local_map_content
);
3689 static void __attribute__((constructor
)) init(void)
3691 /* Set default session group */
3692 lttng_set_tracing_group(DEFAULT_TRACING_GROUP
);
3698 static void __attribute__((destructor
)) lttng_ctl_exit(void)
3700 free(tracing_group
);