4 * Linux Trace Toolkit Control Library
6 * Copyright (C) 2011 EfficiOS Inc.
7 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * SPDX-License-Identifier: LGPL-2.1-only
23 #include <common/buffer-view.h>
24 #include <common/common.h>
25 #include <common/compat/string.h>
26 #include <common/defaults.h>
27 #include <common/dynamic-array.h>
28 #include <common/dynamic-buffer.h>
29 #include <common/macros.h>
30 #include <common/sessiond-comm/sessiond-comm.h>
31 #include <common/tracker.h>
32 #include <common/uri.h>
33 #include <common/utils.h>
34 #include <lttng/channel-internal.h>
35 #include <lttng/destruction-handle.h>
36 #include <lttng/endpoint.h>
37 #include <lttng/event-internal.h>
38 #include <lttng/health-internal.h>
39 #include <lttng/lttng.h>
40 #include <lttng/session-descriptor-internal.h>
41 #include <lttng/session-internal.h>
42 #include <lttng/trigger/trigger-internal.h>
43 #include <lttng/userspace-probe-internal.h>
45 #include "filter/filter-ast.h"
46 #include "filter/filter-parser.h"
47 #include "filter/filter-bytecode.h"
48 #include "filter/memstream.h"
49 #include "lttng-ctl-helper.h"
52 static const int print_xml
= 1;
53 #define dbg_printf(fmt, args...) \
54 printf("[debug liblttng-ctl] " fmt, ## args)
56 static const int print_xml
= 0;
57 #define dbg_printf(fmt, args...) \
59 /* do nothing but check printf format */ \
61 printf("[debug liblttnctl] " fmt, ## args); \
65 #define COPY_DOMAIN_PACKED(dst, src) \
67 struct lttng_domain _tmp_domain; \
69 lttng_ctl_copy_lttng_domain(&_tmp_domain, &src); \
73 /* Socket to session daemon for communication */
74 static int sessiond_socket
= -1;
75 static char sessiond_sock_path
[PATH_MAX
];
78 static char *tracing_group
;
84 * Those two variables are used by error.h to silent or control the verbosity of
85 * error message. They are global to the library so application linking with it
86 * are able to compile correctly and also control verbosity of the library.
89 int lttng_opt_verbose
;
93 * Copy domain to lttcomm_session_msg domain.
95 * If domain is unknown, default domain will be the kernel.
98 void lttng_ctl_copy_lttng_domain(struct lttng_domain
*dst
,
99 struct lttng_domain
*src
)
103 case LTTNG_DOMAIN_KERNEL
:
104 case LTTNG_DOMAIN_UST
:
105 case LTTNG_DOMAIN_JUL
:
106 case LTTNG_DOMAIN_LOG4J
:
107 case LTTNG_DOMAIN_PYTHON
:
108 memcpy(dst
, src
, sizeof(struct lttng_domain
));
111 memset(dst
, 0, sizeof(struct lttng_domain
));
118 * Send lttcomm_session_msg to the session daemon.
120 * On success, returns the number of bytes sent (>=0)
121 * On error, returns -1
123 static int send_session_msg(struct lttcomm_session_msg
*lsm
)
128 ret
= -LTTNG_ERR_NO_SESSIOND
;
132 DBG("LSM cmd type : %d", lsm
->cmd_type
);
134 ret
= lttcomm_send_creds_unix_sock(sessiond_socket
, lsm
,
135 sizeof(struct lttcomm_session_msg
));
137 ret
= -LTTNG_ERR_FATAL
;
145 * Send var len data to the session daemon.
147 * On success, returns the number of bytes sent (>=0)
148 * On error, returns -1
150 static int send_session_varlen(const void *data
, size_t len
)
155 ret
= -LTTNG_ERR_NO_SESSIOND
;
164 ret
= lttcomm_send_unix_sock(sessiond_socket
, data
, len
);
166 ret
= -LTTNG_ERR_FATAL
;
174 * Send file descriptors to the session daemon.
176 * On success, returns the number of bytes sent (>=0)
177 * On error, returns -1
179 static int send_session_fds(const int *fds
, size_t nb_fd
)
184 ret
= -LTTNG_ERR_NO_SESSIOND
;
188 if (!fds
|| !nb_fd
) {
193 ret
= lttcomm_send_fds_unix_sock(sessiond_socket
, fds
, nb_fd
);
195 ret
= -LTTNG_ERR_FATAL
;
203 * Receive data from the sessiond socket.
205 * On success, returns the number of bytes received (>=0)
206 * On error, returns -1 (recvmsg() error) or -ENOTCONN
208 static int recv_data_sessiond(void *buf
, size_t len
)
213 ret
= -LTTNG_ERR_NO_SESSIOND
;
217 ret
= lttcomm_recv_unix_sock(sessiond_socket
, buf
, len
);
219 ret
= -LTTNG_ERR_FATAL
;
227 * Check if we are in the specified group.
229 * If yes return 1, else return -1.
232 int lttng_check_tracing_group(void)
234 gid_t
*grp_list
, tracing_gid
;
235 int grp_list_size
, grp_id
, i
;
237 const char *grp_name
= tracing_group
;
239 /* Get GID of group 'tracing' */
240 if (utils_get_group_id(grp_name
, false, &tracing_gid
)) {
241 /* If grp_tracing is NULL, the group does not exist. */
245 /* Get number of supplementary group IDs */
246 grp_list_size
= getgroups(0, NULL
);
247 if (grp_list_size
< 0) {
252 /* Alloc group list of the right size */
253 grp_list
= zmalloc(grp_list_size
* sizeof(gid_t
));
258 grp_id
= getgroups(grp_list_size
, grp_list
);
264 for (i
= 0; i
< grp_list_size
; i
++) {
265 if (grp_list
[i
] == tracing_gid
) {
278 static enum lttng_error_code
check_enough_available_memory(
279 uint64_t num_bytes_requested_per_cpu
)
283 uint64_t best_mem_info
;
284 uint64_t num_bytes_requested_total
;
287 * Get the number of CPU currently online to compute the amount of
288 * memory needed to create a buffer for every CPU.
290 num_cpu
= sysconf(_SC_NPROCESSORS_ONLN
);
292 ret
= LTTNG_ERR_FATAL
;
296 if (num_bytes_requested_per_cpu
> UINT64_MAX
/ (uint64_t) num_cpu
) {
298 ret
= LTTNG_ERR_OVERFLOW
;
302 num_bytes_requested_total
=
303 num_bytes_requested_per_cpu
* (uint64_t) num_cpu
;
306 * Try to get the `MemAvail` field of `/proc/meminfo`. This is the most
307 * reliable estimate we can get but it is only exposed by the kernel
308 * since 3.14. (See Linux kernel commit:
309 * 34e431b0ae398fc54ea69ff85ec700722c9da773)
311 ret
= utils_get_memory_available(&best_mem_info
);
317 * As a backup plan, use `MemTotal` field of `/proc/meminfo`. This
318 * is a sanity check for obvious user error.
320 ret
= utils_get_memory_total(&best_mem_info
);
325 /* No valid source of information. */
326 ret
= LTTNG_ERR_NOMEM
;
330 if (best_mem_info
>= num_bytes_requested_total
) {
333 ret
= LTTNG_ERR_NOMEM
;
340 * Try connect to session daemon with sock_path.
342 * Return 0 on success, else -1
344 static int try_connect_sessiond(const char *sock_path
)
348 /* If socket exist, we check if the daemon listens for connect. */
349 ret
= access(sock_path
, F_OK
);
355 ret
= lttcomm_connect_unix_sock(sock_path
);
361 ret
= lttcomm_close_unix_sock(ret
);
363 PERROR("lttcomm_close_unix_sock");
373 * Set sessiond socket path by putting it in the global sessiond_sock_path
376 * Returns 0 on success, negative value on failure (the sessiond socket path
377 * is somehow too long or ENOMEM).
379 static int set_session_daemon_path(void)
381 int in_tgroup
= 0; /* In tracing group. */
387 /* Are we in the tracing group ? */
388 in_tgroup
= lttng_check_tracing_group();
391 if ((uid
== 0) || in_tgroup
== 1) {
392 const int ret
= lttng_strncpy(sessiond_sock_path
,
393 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
,
394 sizeof(sessiond_sock_path
));
406 ret
= try_connect_sessiond(sessiond_sock_path
);
410 /* Global session daemon not available... */
412 /* ...or not in tracing group (and not root), default */
415 * With GNU C < 2.1, snprintf returns -1 if the target buffer
417 * With GNU C >= 2.1, snprintf returns the required size
418 * (excluding closing null)
420 ret
= snprintf(sessiond_sock_path
, sizeof(sessiond_sock_path
),
421 DEFAULT_HOME_CLIENT_UNIX_SOCK
, utils_get_home_dir());
422 if ((ret
< 0) || (ret
>= sizeof(sessiond_sock_path
))) {
434 * Connect to the LTTng session daemon.
436 * On success, return the socket's file descriptor. On error, return -1.
438 LTTNG_HIDDEN
int connect_sessiond(void)
442 ret
= set_session_daemon_path();
447 /* Connect to the sesssion daemon. */
448 ret
= lttcomm_connect_unix_sock(sessiond_sock_path
);
459 static void reset_global_sessiond_connection_state(void)
461 sessiond_socket
= -1;
466 * Clean disconnect from the session daemon.
468 * On success, return 0. On error, return -1.
470 static int disconnect_sessiond(void)
475 ret
= lttcomm_close_unix_sock(sessiond_socket
);
476 reset_global_sessiond_connection_state();
482 static int recv_sessiond_optional_data(size_t len
, void **user_buf
,
490 ret
= -LTTNG_ERR_INVALID
;
500 ret
= recv_data_sessiond(buf
, len
);
506 ret
= -LTTNG_ERR_INVALID
;
510 /* Move ownership of command header buffer to user. */
515 /* No command header. */
531 * Ask the session daemon a specific command and put the data into buf.
532 * Takes extra var. len. data and file descriptors as input to send to the
535 * Return size of data (only payload, not header) or a negative error code.
538 int lttng_ctl_ask_sessiond_fds_varlen(struct lttcomm_session_msg
*lsm
,
539 const int *fds
, size_t nb_fd
, const void *vardata
,
540 size_t vardata_len
, void **user_payload_buf
,
541 void **user_cmd_header_buf
, size_t *user_cmd_header_len
)
545 struct lttcomm_lttng_msg llm
;
547 ret
= connect_sessiond();
549 ret
= -LTTNG_ERR_NO_SESSIOND
;
552 sessiond_socket
= ret
;
556 /* Send command to session daemon */
557 ret
= send_session_msg(lsm
);
559 /* Ret value is a valid lttng error code. */
562 /* Send var len data */
563 ret
= send_session_varlen(vardata
, vardata_len
);
565 /* Ret value is a valid lttng error code. */
570 ret
= send_session_fds(fds
, nb_fd
);
572 /* Ret value is a valid lttng error code. */
576 /* Get header from data transmission */
577 ret
= recv_data_sessiond(&llm
, sizeof(llm
));
579 /* Ret value is a valid lttng error code. */
583 /* Check error code if OK */
584 if (llm
.ret_code
!= LTTNG_OK
) {
589 /* Get command header from data transmission */
590 ret
= recv_sessiond_optional_data(llm
.cmd_header_size
,
591 user_cmd_header_buf
, user_cmd_header_len
);
596 /* Get payload from data transmission */
597 ret
= recv_sessiond_optional_data(llm
.data_size
, user_payload_buf
,
606 disconnect_sessiond();
611 * Create lttng handle and return pointer.
613 * The returned pointer will be NULL in case of malloc() error.
615 struct lttng_handle
*lttng_create_handle(const char *session_name
,
616 struct lttng_domain
*domain
)
619 struct lttng_handle
*handle
= NULL
;
621 handle
= zmalloc(sizeof(struct lttng_handle
));
622 if (handle
== NULL
) {
623 PERROR("malloc handle");
627 /* Copy session name */
628 ret
= lttng_strncpy(handle
->session_name
, session_name
? : "",
629 sizeof(handle
->session_name
));
634 /* Copy lttng domain or leave initialized to 0. */
636 lttng_ctl_copy_lttng_domain(&handle
->domain
, domain
);
647 * Destroy handle by free(3) the pointer.
649 void lttng_destroy_handle(struct lttng_handle
*handle
)
655 * Register an outside consumer.
657 * Returns size of returned session payload data or a negative error code.
659 int lttng_register_consumer(struct lttng_handle
*handle
,
660 const char *socket_path
)
663 struct lttcomm_session_msg lsm
;
665 if (handle
== NULL
|| socket_path
== NULL
) {
666 ret
= -LTTNG_ERR_INVALID
;
670 memset(&lsm
, 0, sizeof(lsm
));
671 lsm
.cmd_type
= LTTNG_REGISTER_CONSUMER
;
672 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
673 sizeof(lsm
.session
.name
));
675 ret
= -LTTNG_ERR_INVALID
;
679 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
681 ret
= lttng_strncpy(lsm
.u
.reg
.path
, socket_path
,
682 sizeof(lsm
.u
.reg
.path
));
684 ret
= -LTTNG_ERR_INVALID
;
688 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
694 * Start tracing for all traces of the session.
696 * Returns size of returned session payload data or a negative error code.
698 int lttng_start_tracing(const char *session_name
)
701 struct lttcomm_session_msg lsm
;
703 if (session_name
== NULL
) {
704 ret
= -LTTNG_ERR_INVALID
;
708 memset(&lsm
, 0, sizeof(lsm
));
709 lsm
.cmd_type
= LTTNG_START_TRACE
;
711 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
712 sizeof(lsm
.session
.name
));
714 ret
= -LTTNG_ERR_INVALID
;
718 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
724 * Stop tracing for all traces of the session.
726 static int _lttng_stop_tracing(const char *session_name
, int wait
)
729 struct lttcomm_session_msg lsm
;
731 if (session_name
== NULL
) {
732 ret
= -LTTNG_ERR_INVALID
;
736 memset(&lsm
, 0, sizeof(lsm
));
737 lsm
.cmd_type
= LTTNG_STOP_TRACE
;
739 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
740 sizeof(lsm
.session
.name
));
742 ret
= -LTTNG_ERR_INVALID
;
746 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
747 if (ret
< 0 && ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
755 /* Check for data availability */
757 data_ret
= lttng_data_pending(session_name
);
759 /* Return the data available call error. */
765 * Data sleep time before retrying (in usec). Don't sleep if the
766 * call returned value indicates availability.
769 usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME_US
);
771 } while (data_ret
!= 0);
779 * Stop tracing and wait for data availability.
781 int lttng_stop_tracing(const char *session_name
)
783 return _lttng_stop_tracing(session_name
, 1);
787 * Stop tracing but _don't_ wait for data availability.
789 int lttng_stop_tracing_no_wait(const char *session_name
)
791 return _lttng_stop_tracing(session_name
, 0);
795 * Add context to a channel.
797 * If the given channel is NULL, add the contexts to all channels.
798 * The event_name param is ignored.
800 * Returns the size of the returned payload data or a negative error code.
802 int lttng_add_context(struct lttng_handle
*handle
,
803 struct lttng_event_context
*ctx
, const char *event_name
,
804 const char *channel_name
)
809 struct lttcomm_session_msg lsm
;
811 /* Safety check. Both are mandatory. */
812 if (handle
== NULL
|| ctx
== NULL
) {
813 ret
= -LTTNG_ERR_INVALID
;
817 memset(&lsm
, 0, sizeof(lsm
));
818 lsm
.cmd_type
= LTTNG_ADD_CONTEXT
;
820 /* If no channel name, send empty string. */
821 ret
= lttng_strncpy(lsm
.u
.context
.channel_name
, channel_name
?: "",
822 sizeof(lsm
.u
.context
.channel_name
));
824 ret
= -LTTNG_ERR_INVALID
;
828 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
829 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
830 sizeof(lsm
.session
.name
));
832 ret
= -LTTNG_ERR_INVALID
;
836 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
837 size_t provider_len
, ctx_len
;
838 const char *provider_name
= ctx
->u
.app_ctx
.provider_name
;
839 const char *ctx_name
= ctx
->u
.app_ctx
.ctx_name
;
841 if (!provider_name
|| !ctx_name
) {
842 ret
= -LTTNG_ERR_INVALID
;
846 provider_len
= strlen(provider_name
);
847 if (provider_len
== 0) {
848 ret
= -LTTNG_ERR_INVALID
;
851 lsm
.u
.context
.provider_name_len
= provider_len
;
853 ctx_len
= strlen(ctx_name
);
855 ret
= -LTTNG_ERR_INVALID
;
858 lsm
.u
.context
.context_name_len
= ctx_len
;
860 len
= provider_len
+ ctx_len
;
863 ret
= -LTTNG_ERR_NOMEM
;
867 memcpy(buf
, provider_name
, provider_len
);
868 memcpy(buf
+ provider_len
, ctx_name
, ctx_len
);
870 memcpy(&lsm
.u
.context
.ctx
, ctx
, sizeof(struct lttng_event_context
));
872 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
874 * Don't leak application addresses to the sessiond.
875 * This is only necessary when ctx is for an app ctx otherwise
876 * the values inside the union (type & config) are overwritten.
878 lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
= NULL
;
879 lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
= NULL
;
882 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, buf
, len
, NULL
);
889 * Enable event(s) for a channel.
891 * If no event name is specified, all events are enabled.
892 * If no channel name is specified, the default 'channel0' is used.
894 * Returns size of returned session payload data or a negative error code.
896 int lttng_enable_event(struct lttng_handle
*handle
,
897 struct lttng_event
*ev
, const char *channel_name
)
899 return lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
904 * Create or enable an event with a filter expression.
906 * Return negative error value on error.
907 * Return size of returned session payload data if OK.
909 int lttng_enable_event_with_filter(struct lttng_handle
*handle
,
910 struct lttng_event
*event
, const char *channel_name
,
911 const char *filter_expression
)
913 return lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
914 filter_expression
, 0, NULL
);
918 * Depending on the event, return a newly allocated agent filter expression or
919 * NULL if not applicable.
921 * An event with NO loglevel and the name is * will return NULL.
923 static char *set_agent_filter(const char *filter
, struct lttng_event
*ev
)
926 char *agent_filter
= NULL
;
930 /* Don't add filter for the '*' event. */
931 if (strcmp(ev
->name
, "*") != 0) {
933 err
= asprintf(&agent_filter
, "(%s) && (logger_name == \"%s\")", filter
,
936 err
= asprintf(&agent_filter
, "logger_name == \"%s\"", ev
->name
);
944 /* Add loglevel filtering if any for the JUL domain. */
945 if (ev
->loglevel_type
!= LTTNG_EVENT_LOGLEVEL_ALL
) {
948 if (ev
->loglevel_type
== LTTNG_EVENT_LOGLEVEL_RANGE
) {
954 if (filter
|| agent_filter
) {
957 err
= asprintf(&new_filter
, "(%s) && (int_loglevel %s %d)",
958 agent_filter
? agent_filter
: filter
, op
,
963 agent_filter
= new_filter
;
965 err
= asprintf(&agent_filter
, "int_loglevel %s %d", op
,
981 * Generate the filter bytecode from a given filter expression string. Put the
982 * newly allocated parser context in ctxp and populate the lsm object with the
985 * Return 0 on success else a LTTNG_ERR_* code and ctxp is untouched.
987 static int generate_filter(char *filter_expression
,
988 size_t *bytecode_len
,
989 struct filter_parser_ctx
**ctxp
)
992 struct filter_parser_ctx
*ctx
= NULL
;
995 assert(filter_expression
);
999 * Casting const to non-const, as the underlying function will use it in
1002 fmem
= lttng_fmemopen((void *) filter_expression
,
1003 strlen(filter_expression
), "r");
1005 fprintf(stderr
, "Error opening memory as stream\n");
1006 ret
= -LTTNG_ERR_FILTER_NOMEM
;
1009 ctx
= filter_parser_ctx_alloc(fmem
);
1011 fprintf(stderr
, "Error allocating parser\n");
1012 ret
= -LTTNG_ERR_FILTER_NOMEM
;
1013 goto filter_alloc_error
;
1015 ret
= filter_parser_ctx_append_ast(ctx
);
1017 fprintf(stderr
, "Parse error\n");
1018 ret
= -LTTNG_ERR_FILTER_INVAL
;
1022 ret
= filter_visitor_print_xml(ctx
, stdout
, 0);
1025 fprintf(stderr
, "XML print error\n");
1026 ret
= -LTTNG_ERR_FILTER_INVAL
;
1031 dbg_printf("Generating IR... ");
1033 ret
= filter_visitor_ir_generate(ctx
);
1035 fprintf(stderr
, "Generate IR error\n");
1036 ret
= -LTTNG_ERR_FILTER_INVAL
;
1039 dbg_printf("done\n");
1041 dbg_printf("Validating IR... ");
1043 ret
= filter_visitor_ir_check_binary_op_nesting(ctx
);
1045 ret
= -LTTNG_ERR_FILTER_INVAL
;
1049 /* Normalize globbing patterns in the expression. */
1050 ret
= filter_visitor_ir_normalize_glob_patterns(ctx
);
1052 ret
= -LTTNG_ERR_FILTER_INVAL
;
1056 /* Validate strings used as literals in the expression. */
1057 ret
= filter_visitor_ir_validate_string(ctx
);
1059 ret
= -LTTNG_ERR_FILTER_INVAL
;
1063 /* Validate globbing patterns in the expression. */
1064 ret
= filter_visitor_ir_validate_globbing(ctx
);
1066 ret
= -LTTNG_ERR_FILTER_INVAL
;
1070 dbg_printf("done\n");
1072 dbg_printf("Generating bytecode... ");
1074 ret
= filter_visitor_bytecode_generate(ctx
);
1076 fprintf(stderr
, "Generate bytecode error\n");
1077 ret
= -LTTNG_ERR_FILTER_INVAL
;
1080 dbg_printf("done\n");
1081 dbg_printf("Size of bytecode generated: %u bytes.\n",
1082 bytecode_get_len(&ctx
->bytecode
->b
));
1084 *bytecode_len
= sizeof(ctx
->bytecode
->b
) +
1085 bytecode_get_len(&ctx
->bytecode
->b
);
1087 /* No need to keep the memory stream. */
1088 if (fclose(fmem
) != 0) {
1096 filter_ir_free(ctx
);
1097 filter_parser_ctx_free(ctx
);
1099 if (fclose(fmem
) != 0) {
1107 * Enable event(s) for a channel, possibly with exclusions and a filter.
1108 * If no event name is specified, all events are enabled.
1109 * If no channel name is specified, the default name is used.
1110 * If filter expression is not NULL, the filter is set for the event.
1111 * If exclusion count is not zero, the exclusions are set for the event.
1112 * Returns size of returned session payload data or a negative error code.
1114 int lttng_enable_event_with_exclusions(struct lttng_handle
*handle
,
1115 struct lttng_event
*ev
, const char *channel_name
,
1116 const char *original_filter_expression
,
1117 int exclusion_count
, char **exclusion_list
)
1119 struct lttcomm_session_msg lsm
;
1120 struct lttng_dynamic_buffer send_buffer
;
1121 int ret
= 0, fd_to_send
= -1;
1122 bool send_fd
= false;
1123 unsigned int free_filter_expression
= 0;
1124 struct filter_parser_ctx
*ctx
= NULL
;
1125 size_t bytecode_len
= 0;
1128 * We have either a filter or some exclusions, so we need to set up
1129 * a variable-length memory block from where to send the data.
1131 lttng_dynamic_buffer_init(&send_buffer
);
1134 * Cast as non-const since we may replace the filter expression
1135 * by a dynamically allocated string. Otherwise, the original
1136 * string is not modified.
1138 char *filter_expression
= (char *) original_filter_expression
;
1140 if (handle
== NULL
|| ev
== NULL
) {
1141 ret
= -LTTNG_ERR_INVALID
;
1146 * Empty filter string will always be rejected by the parser
1147 * anyway, so treat this corner-case early to eliminate
1148 * lttng_fmemopen error for 0-byte allocation.
1150 if (filter_expression
&& filter_expression
[0] == '\0') {
1151 ret
= -LTTNG_ERR_INVALID
;
1155 if (ev
->name
[0] == '\0') {
1156 /* Enable all events. */
1157 ret
= lttng_strncpy(ev
->name
, "*", sizeof(ev
->name
));
1161 /* Parse filter expression. */
1162 if (filter_expression
!= NULL
|| handle
->domain
.type
== LTTNG_DOMAIN_JUL
1163 || handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
1164 || handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1165 if (handle
->domain
.type
== LTTNG_DOMAIN_JUL
||
1166 handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
||
1167 handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1170 /* Setup agent filter if needed. */
1171 agent_filter
= set_agent_filter(filter_expression
, ev
);
1172 if (!agent_filter
) {
1173 if (!filter_expression
) {
1175 * No JUL and no filter, just skip
1182 * With an agent filter, the original filter has
1183 * been added to it thus replace the filter
1186 filter_expression
= agent_filter
;
1187 free_filter_expression
= 1;
1191 if (strnlen(filter_expression
, LTTNG_FILTER_MAX_LEN
) ==
1192 LTTNG_FILTER_MAX_LEN
) {
1193 ret
= -LTTNG_ERR_FILTER_INVAL
;
1197 ret
= generate_filter(filter_expression
, &bytecode_len
, &ctx
);
1202 if (bytecode_len
> LTTNG_FILTER_MAX_LEN
) {
1203 ret
= -LTTNG_ERR_FILTER_INVAL
;
1209 ret
= lttng_event_serialize(ev
, exclusion_count
, exclusion_list
,
1210 filter_expression
, bytecode_len
,
1211 ctx
&& (bytecode_len
!= 0) ? &ctx
->bytecode
->b
: NULL
,
1212 &send_buffer
, &fd_to_send
);
1217 if (fd_to_send
>= 0) {
1221 /* Prepare the command header */
1222 memset(&lsm
, 0, sizeof(lsm
));
1223 lsm
.cmd_type
= LTTNG_ENABLE_EVENT
;
1225 /* If no channel name, send empty string. */
1226 ret
= lttng_strncpy(lsm
.u
.enable
.channel_name
, channel_name
?: "",
1227 sizeof(lsm
.u
.enable
.channel_name
));
1229 ret
= -LTTNG_ERR_INVALID
;
1234 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1237 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1238 sizeof(lsm
.session
.name
));
1240 ret
= -LTTNG_ERR_INVALID
;
1244 /* Length of the serialized event */
1245 lsm
.u
.enable
.length
= (uint32_t) send_buffer
.size
;
1247 ret
= lttng_ctl_ask_sessiond_fds_varlen(&lsm
,
1248 send_fd
? &fd_to_send
: NULL
,
1250 send_buffer
.size
? send_buffer
.data
: NULL
,
1251 send_buffer
.size
, NULL
, NULL
, 0);
1253 if (filter_expression
&& ctx
) {
1254 filter_bytecode_free(ctx
);
1255 filter_ir_free(ctx
);
1256 filter_parser_ctx_free(ctx
);
1259 if (free_filter_expression
) {
1261 * The filter expression has been replaced and must be freed as
1262 * it is not the original filter expression received as a
1265 free(filter_expression
);
1268 lttng_dynamic_buffer_reset(&send_buffer
);
1272 int lttng_disable_event_ext(struct lttng_handle
*handle
,
1273 struct lttng_event
*ev
, const char *channel_name
,
1274 const char *original_filter_expression
)
1276 struct lttcomm_session_msg lsm
;
1277 struct lttng_dynamic_buffer buf
;
1279 unsigned int free_filter_expression
= 0;
1280 struct filter_parser_ctx
*ctx
= NULL
;
1281 size_t bytecode_len
= 0;
1282 int fd_to_send
= -1;
1283 bool send_fd
= false;
1285 * Cast as non-const since we may replace the filter expression
1286 * by a dynamically allocated string. Otherwise, the original
1287 * string is not modified.
1289 char *filter_expression
= (char *) original_filter_expression
;
1291 lttng_dynamic_buffer_init(&buf
);
1293 if (handle
== NULL
|| ev
== NULL
) {
1294 ret
= -LTTNG_ERR_INVALID
;
1299 * Empty filter string will always be rejected by the parser
1300 * anyway, so treat this corner-case early to eliminate
1301 * lttng_fmemopen error for 0-byte allocation.
1303 if (filter_expression
&& filter_expression
[0] == '\0') {
1304 ret
= -LTTNG_ERR_INVALID
;
1308 /* Parse filter expression */
1309 if (filter_expression
!= NULL
|| handle
->domain
.type
== LTTNG_DOMAIN_JUL
1310 || handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
1311 || handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1312 if (handle
->domain
.type
== LTTNG_DOMAIN_JUL
||
1313 handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
||
1314 handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1317 /* Setup agent filter if needed. */
1318 agent_filter
= set_agent_filter(filter_expression
, ev
);
1319 if (!agent_filter
) {
1320 if (!filter_expression
) {
1322 * No JUL and no filter, just skip
1329 * With a JUL filter, the original filter has
1330 * been added to it thus replace the filter
1333 filter_expression
= agent_filter
;
1334 free_filter_expression
= 1;
1338 ret
= generate_filter(filter_expression
, &bytecode_len
, &ctx
);
1346 ret
= lttng_event_serialize(ev
, 0, NULL
, filter_expression
,
1348 ctx
&& (bytecode_len
!= 0) ? &ctx
->bytecode
->b
: NULL
,
1355 if (fd_to_send
>= 0) {
1359 /* Prepare command header */
1360 memset(&lsm
, 0, sizeof(lsm
));
1361 lsm
.cmd_type
= LTTNG_DISABLE_EVENT
;
1363 /* If no channel name, send empty string. */
1364 ret
= lttng_strncpy(lsm
.u
.disable
.channel_name
, channel_name
?: "",
1365 sizeof(lsm
.u
.disable
.channel_name
));
1367 ret
= -LTTNG_ERR_INVALID
;
1371 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1374 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1375 sizeof(lsm
.session
.name
));
1377 ret
= -LTTNG_ERR_INVALID
;
1381 /* Length of the serialized event */
1382 lsm
.u
.disable
.length
= (uint32_t) buf
.size
;
1384 ret
= lttng_ctl_ask_sessiond_fds_varlen(&lsm
,
1385 send_fd
? &fd_to_send
: NULL
, send_fd
? 1 : 0,
1386 buf
.size
? buf
.data
: NULL
, buf
.size
, NULL
, NULL
, 0);
1389 if (filter_expression
&& ctx
) {
1390 filter_bytecode_free(ctx
);
1391 filter_ir_free(ctx
);
1392 filter_parser_ctx_free(ctx
);
1395 if (free_filter_expression
) {
1397 * The filter expression has been replaced and must be freed as
1398 * it is not the original filter expression received as a
1401 free(filter_expression
);
1404 lttng_dynamic_buffer_reset(&buf
);
1409 * Disable event(s) of a channel and domain.
1410 * If no event name is specified, all events are disabled.
1411 * If no channel name is specified, the default 'channel0' is used.
1412 * Returns size of returned session payload data or a negative error code.
1414 int lttng_disable_event(struct lttng_handle
*handle
, const char *name
,
1415 const char *channel_name
)
1418 struct lttng_event ev
;
1420 memset(&ev
, 0, sizeof(ev
));
1422 ev
.type
= LTTNG_EVENT_ALL
;
1423 ret
= lttng_strncpy(ev
.name
, name
?: "", sizeof(ev
.name
));
1425 ret
= -LTTNG_ERR_INVALID
;
1429 ret
= lttng_disable_event_ext(handle
, &ev
, channel_name
, NULL
);
1434 struct lttng_channel
*lttng_channel_create(struct lttng_domain
*domain
)
1436 struct lttng_channel
*channel
= NULL
;
1442 /* Validate domain. */
1443 switch (domain
->type
) {
1444 case LTTNG_DOMAIN_UST
:
1445 switch (domain
->buf_type
) {
1446 case LTTNG_BUFFER_PER_UID
:
1447 case LTTNG_BUFFER_PER_PID
:
1453 case LTTNG_DOMAIN_KERNEL
:
1454 if (domain
->buf_type
!= LTTNG_BUFFER_GLOBAL
) {
1462 channel
= lttng_channel_create_internal();
1467 lttng_channel_set_default_attr(domain
, &channel
->attr
);
1472 void lttng_channel_destroy(struct lttng_channel
*channel
)
1478 if (channel
->attr
.extended
.ptr
) {
1479 free(channel
->attr
.extended
.ptr
);
1485 * Enable channel per domain
1486 * Returns size of returned session payload data or a negative error code.
1488 int lttng_enable_channel(struct lttng_handle
*handle
,
1489 struct lttng_channel
*in_chan
)
1491 enum lttng_error_code ret_code
;
1493 struct lttng_dynamic_buffer buffer
;
1494 struct lttcomm_session_msg lsm
;
1495 uint64_t total_buffer_size_needed_per_cpu
= 0;
1496 struct lttng_channel
*channel
= NULL
;
1498 lttng_dynamic_buffer_init(&buffer
);
1500 /* NULL arguments are forbidden. No default values. */
1501 if (handle
== NULL
|| in_chan
== NULL
) {
1502 ret
= -LTTNG_ERR_INVALID
;
1507 * Verify that the amount of memory required to create the requested
1508 * buffer is available on the system at the moment.
1510 if (in_chan
->attr
.num_subbuf
>
1511 UINT64_MAX
/ in_chan
->attr
.subbuf_size
) {
1513 ret
= -LTTNG_ERR_OVERFLOW
;
1517 total_buffer_size_needed_per_cpu
=
1518 in_chan
->attr
.num_subbuf
* in_chan
->attr
.subbuf_size
;
1519 ret_code
= check_enough_available_memory(
1520 total_buffer_size_needed_per_cpu
);
1521 if (ret_code
!= LTTNG_OK
) {
1526 /* Copy the channel for easier manipulation. */
1527 channel
= lttng_channel_copy(in_chan
);
1529 ret
= -LTTNG_ERR_NOMEM
;
1533 /* Populate the channel extended attribute if necessary. */
1534 if (!channel
->attr
.extended
.ptr
) {
1535 struct lttng_channel_extended
*extended
=
1536 zmalloc(sizeof(*extended
));
1539 ret
= -LTTNG_ERR_NOMEM
;
1542 lttng_channel_set_default_extended_attr(
1543 &handle
->domain
, extended
);
1544 channel
->attr
.extended
.ptr
= extended
;
1547 /* Prepare the payload */
1548 memset(&lsm
, 0, sizeof(lsm
));
1550 lsm
.cmd_type
= LTTNG_ENABLE_CHANNEL
;
1551 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1553 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1554 sizeof(lsm
.session
.name
));
1556 ret
= -LTTNG_ERR_INVALID
;
1560 ret
= lttng_channel_serialize(channel
, &buffer
);
1562 ret
= -LTTNG_ERR_FATAL
;
1566 lsm
.u
.channel
.length
= buffer
.size
;
1568 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(
1569 &lsm
, buffer
.data
, buffer
.size
, NULL
);
1571 lttng_channel_destroy(channel
);
1572 lttng_dynamic_buffer_reset(&buffer
);
1577 * All tracing will be stopped for registered events of the channel.
1578 * Returns size of returned session payload data or a negative error code.
1580 int lttng_disable_channel(struct lttng_handle
*handle
, const char *name
)
1583 struct lttcomm_session_msg lsm
;
1585 /* Safety check. Both are mandatory. */
1586 if (handle
== NULL
|| name
== NULL
) {
1587 return -LTTNG_ERR_INVALID
;
1590 memset(&lsm
, 0, sizeof(lsm
));
1592 lsm
.cmd_type
= LTTNG_DISABLE_CHANNEL
;
1594 ret
= lttng_strncpy(lsm
.u
.disable
.channel_name
, name
,
1595 sizeof(lsm
.u
.disable
.channel_name
));
1597 ret
= -LTTNG_ERR_INVALID
;
1601 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1603 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
1604 sizeof(lsm
.session
.name
));
1606 ret
= -LTTNG_ERR_INVALID
;
1610 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1616 * Lists all available tracepoints of domain.
1617 * Sets the contents of the events array.
1618 * Returns the number of lttng_event entries in events;
1619 * on error, returns a negative value.
1621 int lttng_list_tracepoints(struct lttng_handle
*handle
,
1622 struct lttng_event
**events
)
1624 enum lttng_error_code ret_code
;
1625 int ret
, total_payload_received
;
1626 char *reception_buffer
= NULL
;
1627 struct lttcomm_session_msg lsm
;
1628 struct lttcomm_list_command_header
*cmd_header
= NULL
;
1629 size_t cmd_header_len
;
1630 unsigned int nb_events
= 0;
1632 if (handle
== NULL
) {
1633 ret
= -LTTNG_ERR_INVALID
;
1637 memset(&lsm
, 0, sizeof(lsm
));
1638 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINTS
;
1639 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1641 ret
= lttng_ctl_ask_sessiond_fds_varlen(&lsm
, NULL
, 0, NULL
, 0,
1642 (void **) &reception_buffer
, (void **) &cmd_header
,
1647 total_payload_received
= ret
;
1650 ret
= -LTTNG_ERR_UNK
;
1654 if (cmd_header
->count
> INT_MAX
) {
1655 ret
= -LTTNG_ERR_OVERFLOW
;
1659 nb_events
= (unsigned int) cmd_header
->count
;
1662 const struct lttng_buffer_view events_view
=
1663 lttng_buffer_view_init(reception_buffer
, 0,
1664 total_payload_received
);
1666 ret_code
= lttng_events_create_and_flatten_from_buffer(
1667 &events_view
, nb_events
, events
);
1668 if (ret_code
!= LTTNG_OK
) {
1674 ret
= (int) nb_events
;
1678 free(reception_buffer
);
1683 * Lists all available tracepoint fields of domain.
1684 * Sets the contents of the event field array.
1685 * Returns the number of lttng_event_field entries in events;
1686 * on error, returns a negative value.
1688 int lttng_list_tracepoint_fields(struct lttng_handle
*handle
,
1689 struct lttng_event_field
**fields
)
1692 struct lttcomm_session_msg lsm
;
1694 if (handle
== NULL
) {
1695 return -LTTNG_ERR_INVALID
;
1698 memset(&lsm
, 0, sizeof(lsm
));
1699 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINT_FIELDS
;
1700 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
1702 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) fields
);
1707 return ret
/ sizeof(struct lttng_event_field
);
1711 * Lists all available kernel system calls. Allocates and sets the contents of
1714 * Returns the number of lttng_event entries in events; on error, returns a
1717 int lttng_list_syscalls(struct lttng_event
**events
)
1719 enum lttng_error_code ret_code
;
1720 int ret
, total_payload_received
;
1721 char *reception_buffer
= NULL
;
1722 struct lttcomm_session_msg lsm
;
1723 struct lttcomm_list_command_header
*cmd_header
= NULL
;
1724 size_t cmd_header_len
;
1725 uint32_t nb_events
= 0;
1728 ret
= -LTTNG_ERR_INVALID
;
1732 memset(&lsm
, 0, sizeof(lsm
));
1733 lsm
.cmd_type
= LTTNG_LIST_SYSCALLS
;
1734 /* Force kernel domain for system calls. */
1735 lsm
.domain
.type
= LTTNG_DOMAIN_KERNEL
;
1737 ret
= lttng_ctl_ask_sessiond_fds_varlen(&lsm
, NULL
, 0, NULL
, 0,
1738 (void **) &reception_buffer
, (void **) &cmd_header
,
1743 total_payload_received
= ret
;
1746 ret
= -LTTNG_ERR_UNK
;
1750 if (cmd_header
->count
> INT_MAX
) {
1751 ret
= -LTTNG_ERR_OVERFLOW
;
1755 nb_events
= (unsigned int) cmd_header
->count
;
1758 const struct lttng_buffer_view events_view
=
1759 lttng_buffer_view_init(reception_buffer
, 0,
1760 total_payload_received
);
1762 ret_code
= lttng_events_create_and_flatten_from_buffer(
1763 &events_view
, nb_events
, events
);
1764 if (ret_code
!= LTTNG_OK
) {
1770 ret
= (int) nb_events
;
1773 free(reception_buffer
);
1779 * Returns a human readable string describing
1780 * the error code (a negative value).
1782 const char *lttng_strerror(int code
)
1784 return error_get_str(code
);
1787 enum lttng_error_code
lttng_create_session_ext(
1788 struct lttng_session_descriptor
*session_descriptor
)
1790 enum lttng_error_code ret_code
;
1791 struct lttcomm_session_msg lsm
= {
1792 .cmd_type
= LTTNG_CREATE_SESSION_EXT
,
1795 struct lttng_buffer_view reply_view
;
1797 bool sessiond_must_generate_ouput
;
1798 struct lttng_dynamic_buffer payload
;
1800 size_t descriptor_size
;
1801 struct lttng_session_descriptor
*descriptor_reply
= NULL
;
1803 lttng_dynamic_buffer_init(&payload
);
1804 if (!session_descriptor
) {
1805 ret_code
= LTTNG_ERR_INVALID
;
1809 sessiond_must_generate_ouput
=
1810 !lttng_session_descriptor_is_output_destination_initialized(
1811 session_descriptor
);
1812 if (sessiond_must_generate_ouput
) {
1813 const char *home_dir
= utils_get_home_dir();
1814 size_t home_dir_len
= home_dir
? strlen(home_dir
) + 1 : 0;
1816 if (!home_dir
|| home_dir_len
> LTTNG_PATH_MAX
) {
1817 ret_code
= LTTNG_ERR_FATAL
;
1821 lsm
.u
.create_session
.home_dir_size
= (uint16_t) home_dir_len
;
1822 ret
= lttng_dynamic_buffer_append(&payload
, home_dir
,
1825 ret_code
= LTTNG_ERR_NOMEM
;
1830 descriptor_size
= payload
.size
;
1831 ret
= lttng_session_descriptor_serialize(session_descriptor
,
1834 ret_code
= LTTNG_ERR_INVALID
;
1837 descriptor_size
= payload
.size
- descriptor_size
;
1838 lsm
.u
.create_session
.session_descriptor_size
= descriptor_size
;
1840 /* Command returns a session descriptor on success. */
1841 reply_ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, payload
.data
,
1842 payload
.size
, &reply
);
1843 if (reply_ret
< 0) {
1844 ret_code
= -reply_ret
;
1846 } else if (reply_ret
== 0) {
1847 /* Socket unexpectedly closed by the session daemon. */
1848 ret_code
= LTTNG_ERR_FATAL
;
1852 reply_view
= lttng_buffer_view_init(reply
, 0, reply_ret
);
1853 ret
= lttng_session_descriptor_create_from_buffer(&reply_view
,
1856 ret_code
= LTTNG_ERR_FATAL
;
1859 ret_code
= LTTNG_OK
;
1860 lttng_session_descriptor_assign(session_descriptor
, descriptor_reply
);
1863 lttng_dynamic_buffer_reset(&payload
);
1864 lttng_session_descriptor_destroy(descriptor_reply
);
1869 * Create a new session using name and url for destination.
1871 * Return 0 on success else a negative LTTng error code.
1873 int lttng_create_session(const char *name
, const char *url
)
1877 struct lttng_uri
*uris
= NULL
;
1878 struct lttng_session_descriptor
*descriptor
= NULL
;
1879 enum lttng_error_code ret_code
;
1882 ret
= -LTTNG_ERR_INVALID
;
1886 size
= uri_parse_str_urls(url
, NULL
, &uris
);
1888 ret
= -LTTNG_ERR_INVALID
;
1893 descriptor
= lttng_session_descriptor_create(name
);
1896 if (uris
[0].dtype
!= LTTNG_DST_PATH
) {
1897 ret
= -LTTNG_ERR_INVALID
;
1900 descriptor
= lttng_session_descriptor_local_create(name
,
1904 descriptor
= lttng_session_descriptor_network_create(name
, url
,
1908 ret
= -LTTNG_ERR_INVALID
;
1912 ret
= -LTTNG_ERR_INVALID
;
1915 ret_code
= lttng_create_session_ext(descriptor
);
1916 ret
= ret_code
== LTTNG_OK
? 0 : -ret_code
;
1918 lttng_session_descriptor_destroy(descriptor
);
1924 * Create a session exclusively used for snapshot.
1926 * Return 0 on success else a negative LTTng error code.
1928 int lttng_create_session_snapshot(const char *name
, const char *snapshot_url
)
1931 enum lttng_error_code ret_code
;
1933 struct lttng_uri
*uris
= NULL
;
1934 struct lttng_session_descriptor
*descriptor
= NULL
;
1937 ret
= -LTTNG_ERR_INVALID
;
1941 size
= uri_parse_str_urls(snapshot_url
, NULL
, &uris
);
1943 ret
= -LTTNG_ERR_INVALID
;
1947 * If the user does not specify a custom subdir, use the session name.
1949 if (size
> 0 && uris
[0].dtype
!= LTTNG_DST_PATH
&&
1950 strlen(uris
[0].subdir
) == 0) {
1951 ret
= snprintf(uris
[0].subdir
, sizeof(uris
[0].subdir
), "%s",
1954 PERROR("Failed to set session name as network destination sub-directory");
1955 ret
= -LTTNG_ERR_FATAL
;
1957 } else if (ret
>= sizeof(uris
[0].subdir
)) {
1958 /* Truncated output. */
1959 ret
= -LTTNG_ERR_INVALID
;
1966 descriptor
= lttng_session_descriptor_snapshot_create(name
);
1969 if (uris
[0].dtype
!= LTTNG_DST_PATH
) {
1970 ret
= -LTTNG_ERR_INVALID
;
1973 descriptor
= lttng_session_descriptor_snapshot_local_create(
1978 descriptor
= lttng_session_descriptor_snapshot_network_create(
1984 ret
= -LTTNG_ERR_INVALID
;
1988 ret
= -LTTNG_ERR_INVALID
;
1991 ret_code
= lttng_create_session_ext(descriptor
);
1992 ret
= ret_code
== LTTNG_OK
? 0 : -ret_code
;
1994 lttng_session_descriptor_destroy(descriptor
);
2000 * Create a session exclusively used for live.
2002 * Return 0 on success else a negative LTTng error code.
2004 int lttng_create_session_live(const char *name
, const char *url
,
2005 unsigned int timer_interval
)
2008 enum lttng_error_code ret_code
;
2009 struct lttng_session_descriptor
*descriptor
= NULL
;
2012 ret
= -LTTNG_ERR_INVALID
;
2017 descriptor
= lttng_session_descriptor_live_network_create(
2018 name
, url
, NULL
, timer_interval
);
2020 descriptor
= lttng_session_descriptor_live_create(
2021 name
, timer_interval
);
2024 ret
= -LTTNG_ERR_INVALID
;
2027 ret_code
= lttng_create_session_ext(descriptor
);
2028 ret
= ret_code
== LTTNG_OK
? 0 : -ret_code
;
2030 lttng_session_descriptor_destroy(descriptor
);
2035 * Stop the session and wait for the data before destroying it
2037 * Return 0 on success else a negative LTTng error code.
2039 int lttng_destroy_session(const char *session_name
)
2042 enum lttng_error_code ret_code
;
2043 enum lttng_destruction_handle_status status
;
2044 struct lttng_destruction_handle
*handle
= NULL
;
2047 * Stop the tracing and wait for the data to be
2050 ret
= _lttng_stop_tracing(session_name
, 1);
2051 if (ret
&& ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
2055 ret_code
= lttng_destroy_session_ext(session_name
, &handle
);
2056 if (ret_code
!= LTTNG_OK
) {
2057 ret
= (int) -ret_code
;
2062 /* Block until the completion of the destruction of the session. */
2063 status
= lttng_destruction_handle_wait_for_completion(handle
, -1);
2064 if (status
!= LTTNG_DESTRUCTION_HANDLE_STATUS_COMPLETED
) {
2065 ret
= -LTTNG_ERR_UNK
;
2069 status
= lttng_destruction_handle_get_result(handle
, &ret_code
);
2070 if (status
!= LTTNG_DESTRUCTION_HANDLE_STATUS_OK
) {
2071 ret
= -LTTNG_ERR_UNK
;
2074 ret
= ret_code
== LTTNG_OK
? 0 : -ret_code
;
2076 lttng_destruction_handle_destroy(handle
);
2081 * Destroy the session without waiting for the data.
2083 int lttng_destroy_session_no_wait(const char *session_name
)
2085 enum lttng_error_code ret_code
;
2087 ret_code
= lttng_destroy_session_ext(session_name
, NULL
);
2088 return ret_code
== LTTNG_OK
? 0 : -ret_code
;
2092 * Ask the session daemon for all available sessions.
2093 * Sets the contents of the sessions array.
2094 * Returns the number of lttng_session entries in sessions;
2095 * on error, returns a negative value.
2097 int lttng_list_sessions(struct lttng_session
**out_sessions
)
2100 struct lttcomm_session_msg lsm
;
2101 const size_t session_size
= sizeof(struct lttng_session
) +
2102 sizeof(struct lttng_session_extended
);
2103 size_t session_count
, i
;
2104 struct lttng_session_extended
*sessions_extended_begin
;
2105 struct lttng_session
*sessions
= NULL
;
2107 memset(&lsm
, 0, sizeof(lsm
));
2108 lsm
.cmd_type
= LTTNG_LIST_SESSIONS
;
2110 * Initialize out_sessions to NULL so it is initialized when
2111 * lttng_list_sessions returns 0, thus allowing *out_sessions to
2112 * be subsequently freed.
2114 *out_sessions
= NULL
;
2115 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) &sessions
);
2120 ret
= -LTTNG_ERR_FATAL
;
2124 if (ret
% session_size
) {
2125 ret
= -LTTNG_ERR_UNK
;
2129 session_count
= (size_t) ret
/ session_size
;
2130 sessions_extended_begin
= (struct lttng_session_extended
*)
2131 (&sessions
[session_count
]);
2133 /* Set extended session info pointers. */
2134 for (i
= 0; i
< session_count
; i
++) {
2135 struct lttng_session
*session
= &sessions
[i
];
2136 struct lttng_session_extended
*extended
=
2137 &(sessions_extended_begin
[i
]);
2139 session
->extended
.ptr
= extended
;
2142 ret
= (int) session_count
;
2143 *out_sessions
= sessions
;
2148 enum lttng_error_code
lttng_session_get_creation_time(
2149 const struct lttng_session
*session
, uint64_t *creation_time
)
2151 enum lttng_error_code ret
= LTTNG_OK
;
2152 struct lttng_session_extended
*extended
;
2154 if (!session
|| !creation_time
|| !session
->extended
.ptr
) {
2155 ret
= LTTNG_ERR_INVALID
;
2159 extended
= session
->extended
.ptr
;
2160 if (!extended
->creation_time
.is_set
) {
2161 /* Not created on the session daemon yet. */
2162 ret
= LTTNG_ERR_SESSION_NOT_EXIST
;
2165 *creation_time
= extended
->creation_time
.value
;
2170 int lttng_set_session_shm_path(const char *session_name
,
2171 const char *shm_path
)
2174 struct lttcomm_session_msg lsm
;
2176 if (session_name
== NULL
) {
2177 return -LTTNG_ERR_INVALID
;
2180 memset(&lsm
, 0, sizeof(lsm
));
2181 lsm
.cmd_type
= LTTNG_SET_SESSION_SHM_PATH
;
2183 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
2184 sizeof(lsm
.session
.name
));
2186 ret
= -LTTNG_ERR_INVALID
;
2190 ret
= lttng_strncpy(lsm
.u
.set_shm_path
.shm_path
, shm_path
?: "",
2191 sizeof(lsm
.u
.set_shm_path
.shm_path
));
2193 ret
= -LTTNG_ERR_INVALID
;
2197 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
2203 * Ask the session daemon for all available domains of a session.
2204 * Sets the contents of the domains array.
2205 * Returns the number of lttng_domain entries in domains;
2206 * on error, returns a negative value.
2208 int lttng_list_domains(const char *session_name
,
2209 struct lttng_domain
**domains
)
2212 struct lttcomm_session_msg lsm
;
2214 if (session_name
== NULL
) {
2215 ret
= -LTTNG_ERR_INVALID
;
2219 memset(&lsm
, 0, sizeof(lsm
));
2220 lsm
.cmd_type
= LTTNG_LIST_DOMAINS
;
2222 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
2223 sizeof(lsm
.session
.name
));
2225 ret
= -LTTNG_ERR_INVALID
;
2229 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) domains
);
2234 return ret
/ sizeof(struct lttng_domain
);
2240 * Ask the session daemon for all available channels of a session.
2241 * Sets the contents of the channels array.
2242 * Returns the number of lttng_channel entries in channels;
2243 * on error, returns a negative value.
2245 int lttng_list_channels(struct lttng_handle
*handle
,
2246 struct lttng_channel
**channels
)
2248 int ret
, total_payload_received
;
2249 struct lttcomm_session_msg lsm
;
2250 char *reception_buffer
= NULL
;
2251 size_t cmd_header_len
= 0;
2252 struct lttcomm_list_command_header
*cmd_header
= NULL
;
2253 struct lttng_dynamic_buffer tmp_buffer
;
2255 lttng_dynamic_buffer_init(&tmp_buffer
);
2257 if (handle
== NULL
) {
2258 ret
= -LTTNG_ERR_INVALID
;
2262 memset(&lsm
, 0, sizeof(lsm
));
2263 lsm
.cmd_type
= LTTNG_LIST_CHANNELS
;
2264 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
2265 sizeof(lsm
.session
.name
));
2267 ret
= -LTTNG_ERR_INVALID
;
2271 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
2273 ret
= lttng_ctl_ask_sessiond_fds_varlen(&lsm
, NULL
, 0, NULL
, 0,
2274 (void **) &reception_buffer
, (void **) &cmd_header
,
2280 total_payload_received
= ret
;
2282 if (cmd_header_len
!= sizeof(*cmd_header
)) {
2283 ret
= -LTTNG_ERR_FATAL
;
2288 ret
= LTTNG_ERR_UNK
;
2292 if (cmd_header
->count
> INT_MAX
) {
2293 ret
= -LTTNG_ERR_OVERFLOW
;
2298 enum lttng_error_code ret_code
;
2299 const struct lttng_buffer_view events_view
=
2300 lttng_buffer_view_init(reception_buffer
, 0,
2301 total_payload_received
);
2303 ret_code
= lttng_channels_create_and_flatten_from_buffer(
2304 &events_view
, cmd_header
->count
, channels
);
2305 if (ret_code
!= LTTNG_OK
) {
2311 ret
= (int) cmd_header
->count
;
2314 free(reception_buffer
);
2319 * Ask the session daemon for all available events of a session channel.
2320 * Sets the contents of the events array.
2321 * Returns the number of lttng_event entries in events;
2322 * on error, returns a negative value.
2324 int lttng_list_events(struct lttng_handle
*handle
,
2325 const char *channel_name
, struct lttng_event
**events
)
2327 enum lttng_error_code ret_code
;
2329 struct lttcomm_session_msg lsm
;
2330 struct lttcomm_list_command_header
*cmd_header
= NULL
;
2331 size_t cmd_header_len
;
2332 unsigned int nb_events
;
2333 char *reception_buffer
= NULL
;
2334 struct lttng_dynamic_buffer tmp_buffer
;
2335 ssize_t total_payload_received
;
2337 lttng_dynamic_buffer_init(&tmp_buffer
);
2339 /* Safety check. An handle and channel name are mandatory */
2340 if (handle
== NULL
|| channel_name
== NULL
) {
2341 return -LTTNG_ERR_INVALID
;
2344 memset(&lsm
, 0, sizeof(lsm
));
2345 lsm
.cmd_type
= LTTNG_LIST_EVENTS
;
2346 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
2347 sizeof(lsm
.session
.name
));
2349 ret
= -LTTNG_ERR_INVALID
;
2353 ret
= lttng_strncpy(lsm
.u
.list
.channel_name
, channel_name
,
2354 sizeof(lsm
.u
.list
.channel_name
));
2356 ret
= -LTTNG_ERR_INVALID
;
2360 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
2362 ret
= lttng_ctl_ask_sessiond_fds_varlen(&lsm
, NULL
, 0, NULL
, 0,
2363 (void **) &reception_buffer
, (void **) &cmd_header
,
2369 total_payload_received
= ret
;
2372 ret
= -LTTNG_ERR_UNK
;
2376 if (cmd_header
->count
> INT_MAX
) {
2377 ret
= -LTTNG_ERR_OVERFLOW
;
2381 nb_events
= (unsigned int) cmd_header
->count
;
2384 const struct lttng_buffer_view events_view
=
2385 lttng_buffer_view_init(reception_buffer
, 0,
2386 total_payload_received
);
2387 ret_code
= lttng_events_create_and_flatten_from_buffer(
2388 &events_view
, nb_events
, events
);
2389 if (ret_code
!= LTTNG_OK
) {
2395 ret
= (int) nb_events
;
2398 free(reception_buffer
);
2403 * Sets the tracing_group variable with name.
2404 * This function allocates memory pointed to by tracing_group.
2405 * On success, returns 0, on error, returns -1 (null name) or -ENOMEM.
2407 int lttng_set_tracing_group(const char *name
)
2411 return -LTTNG_ERR_INVALID
;
2414 if (asprintf(&new_group
, "%s", name
) < 0) {
2415 return -LTTNG_ERR_FATAL
;
2418 free(tracing_group
);
2419 tracing_group
= new_group
;
2425 int lttng_calibrate(struct lttng_handle
*handle
,
2426 struct lttng_calibrate
*calibrate
)
2429 * This command was removed in LTTng 2.9.
2431 return -LTTNG_ERR_UND
;
2435 * Set default channel attributes.
2436 * If either or both of the arguments are null, attr content is zeroe'd.
2438 void lttng_channel_set_default_attr(struct lttng_domain
*domain
,
2439 struct lttng_channel_attr
*attr
)
2441 struct lttng_channel_extended
*extended
;
2444 if (attr
== NULL
|| domain
== NULL
) {
2448 /* Save the pointer for later use */
2449 extended
= (struct lttng_channel_extended
*) attr
->extended
.ptr
;
2450 memset(attr
, 0, sizeof(struct lttng_channel_attr
));
2452 /* Same for all domains. */
2453 attr
->overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
2454 attr
->tracefile_size
= DEFAULT_CHANNEL_TRACEFILE_SIZE
;
2455 attr
->tracefile_count
= DEFAULT_CHANNEL_TRACEFILE_COUNT
;
2457 switch (domain
->type
) {
2458 case LTTNG_DOMAIN_KERNEL
:
2459 attr
->switch_timer_interval
=
2460 DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER
;
2461 attr
->read_timer_interval
= DEFAULT_KERNEL_CHANNEL_READ_TIMER
;
2462 attr
->subbuf_size
= default_get_kernel_channel_subbuf_size();
2463 attr
->num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
2464 attr
->output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
2466 case LTTNG_DOMAIN_UST
:
2467 switch (domain
->buf_type
) {
2468 case LTTNG_BUFFER_PER_UID
:
2469 attr
->subbuf_size
= default_get_ust_uid_channel_subbuf_size();
2470 attr
->num_subbuf
= DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM
;
2471 attr
->output
= DEFAULT_UST_UID_CHANNEL_OUTPUT
;
2472 attr
->switch_timer_interval
=
2473 DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER
;
2474 attr
->read_timer_interval
=
2475 DEFAULT_UST_UID_CHANNEL_READ_TIMER
;
2477 case LTTNG_BUFFER_PER_PID
:
2479 attr
->subbuf_size
= default_get_ust_pid_channel_subbuf_size();
2480 attr
->num_subbuf
= DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM
;
2481 attr
->output
= DEFAULT_UST_PID_CHANNEL_OUTPUT
;
2482 attr
->switch_timer_interval
=
2483 DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER
;
2484 attr
->read_timer_interval
=
2485 DEFAULT_UST_PID_CHANNEL_READ_TIMER
;
2489 /* Default behavior: leave set to 0. */
2494 lttng_channel_set_default_extended_attr(domain
, extended
);
2497 /* Reassign the extended pointer. */
2498 attr
->extended
.ptr
= extended
;
2501 int lttng_channel_get_discarded_event_count(struct lttng_channel
*channel
,
2502 uint64_t *discarded_events
)
2505 struct lttng_channel_extended
*chan_ext
;
2507 if (!channel
|| !discarded_events
) {
2508 ret
= -LTTNG_ERR_INVALID
;
2512 chan_ext
= channel
->attr
.extended
.ptr
;
2515 * This can happen since the lttng_channel structure is
2516 * used for other tasks where this pointer is never set.
2518 *discarded_events
= 0;
2522 *discarded_events
= chan_ext
->discarded_events
;
2527 int lttng_channel_get_lost_packet_count(struct lttng_channel
*channel
,
2528 uint64_t *lost_packets
)
2531 struct lttng_channel_extended
*chan_ext
;
2533 if (!channel
|| !lost_packets
) {
2534 ret
= -LTTNG_ERR_INVALID
;
2538 chan_ext
= channel
->attr
.extended
.ptr
;
2541 * This can happen since the lttng_channel structure is
2542 * used for other tasks where this pointer is never set.
2548 *lost_packets
= chan_ext
->lost_packets
;
2553 int lttng_channel_get_monitor_timer_interval(struct lttng_channel
*chan
,
2554 uint64_t *monitor_timer_interval
)
2558 if (!chan
|| !monitor_timer_interval
) {
2559 ret
= -LTTNG_ERR_INVALID
;
2563 if (!chan
->attr
.extended
.ptr
) {
2564 ret
= -LTTNG_ERR_INVALID
;
2568 *monitor_timer_interval
= ((struct lttng_channel_extended
*)
2569 chan
->attr
.extended
.ptr
)->monitor_timer_interval
;
2574 int lttng_channel_set_monitor_timer_interval(struct lttng_channel
*chan
,
2575 uint64_t monitor_timer_interval
)
2579 if (!chan
|| !chan
->attr
.extended
.ptr
) {
2580 ret
= -LTTNG_ERR_INVALID
;
2584 ((struct lttng_channel_extended
*)
2585 chan
->attr
.extended
.ptr
)->monitor_timer_interval
=
2586 monitor_timer_interval
;
2591 int lttng_channel_get_blocking_timeout(struct lttng_channel
*chan
,
2592 int64_t *blocking_timeout
)
2596 if (!chan
|| !blocking_timeout
) {
2597 ret
= -LTTNG_ERR_INVALID
;
2601 if (!chan
->attr
.extended
.ptr
) {
2602 ret
= -LTTNG_ERR_INVALID
;
2606 *blocking_timeout
= ((struct lttng_channel_extended
*)
2607 chan
->attr
.extended
.ptr
)->blocking_timeout
;
2612 int lttng_channel_set_blocking_timeout(struct lttng_channel
*chan
,
2613 int64_t blocking_timeout
)
2616 int64_t msec_timeout
;
2618 if (!chan
|| !chan
->attr
.extended
.ptr
) {
2619 ret
= -LTTNG_ERR_INVALID
;
2623 if (blocking_timeout
< 0 && blocking_timeout
!= -1) {
2624 ret
= -LTTNG_ERR_INVALID
;
2629 * LTTng-ust's use of poll() to implement this timeout mechanism forces
2630 * us to accept a narrower range of values (msecs expressed as a signed
2633 msec_timeout
= blocking_timeout
/ 1000;
2634 if (msec_timeout
!= (int32_t) msec_timeout
) {
2635 ret
= -LTTNG_ERR_INVALID
;
2639 ((struct lttng_channel_extended
*)
2640 chan
->attr
.extended
.ptr
)->blocking_timeout
=
2647 * Check if session daemon is alive.
2649 * Return 1 if alive or 0 if not.
2650 * On error returns a negative value.
2652 int lttng_session_daemon_alive(void)
2656 ret
= set_session_daemon_path();
2662 if (*sessiond_sock_path
== '\0') {
2664 * No socket path set. Weird error which means the constructor
2670 ret
= try_connect_sessiond(sessiond_sock_path
);
2681 * Set URL for a consumer for a session and domain.
2683 * Return 0 on success, else a negative value.
2685 int lttng_set_consumer_url(struct lttng_handle
*handle
,
2686 const char *control_url
, const char *data_url
)
2690 struct lttcomm_session_msg lsm
;
2691 struct lttng_uri
*uris
= NULL
;
2693 if (handle
== NULL
|| (control_url
== NULL
&& data_url
== NULL
)) {
2694 ret
= -LTTNG_ERR_INVALID
;
2698 memset(&lsm
, 0, sizeof(lsm
));
2700 lsm
.cmd_type
= LTTNG_SET_CONSUMER_URI
;
2702 ret
= lttng_strncpy(lsm
.session
.name
, handle
->session_name
,
2703 sizeof(lsm
.session
.name
));
2705 ret
= -LTTNG_ERR_INVALID
;
2709 COPY_DOMAIN_PACKED(lsm
.domain
, handle
->domain
);
2711 size
= uri_parse_str_urls(control_url
, data_url
, &uris
);
2713 ret
= -LTTNG_ERR_INVALID
;
2717 lsm
.u
.uri
.size
= size
;
2719 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
2720 sizeof(struct lttng_uri
) * size
, NULL
);
2730 int lttng_enable_consumer(struct lttng_handle
*handle
);
2731 int lttng_enable_consumer(struct lttng_handle
*handle
)
2739 int lttng_disable_consumer(struct lttng_handle
*handle
);
2740 int lttng_disable_consumer(struct lttng_handle
*handle
)
2748 int _lttng_create_session_ext(const char *name
, const char *url
,
2749 const char *datetime
);
2750 int _lttng_create_session_ext(const char *name
, const char *url
,
2751 const char *datetime
)
2757 * For a given session name, this call checks if the data is ready to be read
2758 * or is still being extracted by the consumer(s) hence not ready to be used by
2761 int lttng_data_pending(const char *session_name
)
2764 struct lttcomm_session_msg lsm
;
2765 uint8_t *pending
= NULL
;
2767 if (session_name
== NULL
) {
2768 return -LTTNG_ERR_INVALID
;
2771 memset(&lsm
, 0, sizeof(lsm
));
2772 lsm
.cmd_type
= LTTNG_DATA_PENDING
;
2774 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
2775 sizeof(lsm
.session
.name
));
2777 ret
= -LTTNG_ERR_INVALID
;
2781 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) &pending
);
2784 } else if (ret
!= 1) {
2785 /* Unexpected payload size */
2786 ret
= -LTTNG_ERR_INVALID
;
2788 } else if (!pending
) {
2789 /* Internal error. */
2790 ret
= -LTTNG_ERR_UNK
;
2794 ret
= (int) *pending
;
2801 * Regenerate the metadata for a session.
2802 * Return 0 on success, a negative error code on error.
2804 int lttng_regenerate_metadata(const char *session_name
)
2807 struct lttcomm_session_msg lsm
;
2809 if (!session_name
) {
2810 ret
= -LTTNG_ERR_INVALID
;
2814 memset(&lsm
, 0, sizeof(lsm
));
2815 lsm
.cmd_type
= LTTNG_REGENERATE_METADATA
;
2817 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
2818 sizeof(lsm
.session
.name
));
2820 ret
= -LTTNG_ERR_INVALID
;
2824 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
2835 * Deprecated, replaced by lttng_regenerate_metadata.
2837 int lttng_metadata_regenerate(const char *session_name
)
2839 return lttng_regenerate_metadata(session_name
);
2843 * Regenerate the statedump of a session.
2844 * Return 0 on success, a negative error code on error.
2846 int lttng_regenerate_statedump(const char *session_name
)
2849 struct lttcomm_session_msg lsm
;
2851 if (!session_name
) {
2852 ret
= -LTTNG_ERR_INVALID
;
2856 memset(&lsm
, 0, sizeof(lsm
));
2857 lsm
.cmd_type
= LTTNG_REGENERATE_STATEDUMP
;
2859 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
2860 sizeof(lsm
.session
.name
));
2862 ret
= -LTTNG_ERR_INVALID
;
2866 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
2876 int lttng_register_trigger(struct lttng_trigger
*trigger
)
2879 struct lttcomm_session_msg lsm
;
2880 struct lttng_dynamic_buffer buffer
;
2882 lttng_dynamic_buffer_init(&buffer
);
2884 ret
= -LTTNG_ERR_INVALID
;
2888 if (!lttng_trigger_validate(trigger
)) {
2889 ret
= -LTTNG_ERR_INVALID_TRIGGER
;
2893 ret
= lttng_trigger_serialize(trigger
, &buffer
);
2895 ret
= -LTTNG_ERR_UNK
;
2899 memset(&lsm
, 0, sizeof(lsm
));
2900 lsm
.cmd_type
= LTTNG_REGISTER_TRIGGER
;
2901 lsm
.u
.trigger
.length
= (uint32_t) buffer
.size
;
2902 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, buffer
.data
,
2905 lttng_dynamic_buffer_reset(&buffer
);
2909 int lttng_unregister_trigger(struct lttng_trigger
*trigger
)
2912 struct lttcomm_session_msg lsm
;
2913 struct lttng_dynamic_buffer buffer
;
2915 lttng_dynamic_buffer_init(&buffer
);
2917 ret
= -LTTNG_ERR_INVALID
;
2921 if (!lttng_trigger_validate(trigger
)) {
2922 ret
= -LTTNG_ERR_INVALID_TRIGGER
;
2926 ret
= lttng_trigger_serialize(trigger
, &buffer
);
2928 ret
= -LTTNG_ERR_UNK
;
2932 memset(&lsm
, 0, sizeof(lsm
));
2933 lsm
.cmd_type
= LTTNG_UNREGISTER_TRIGGER
;
2934 lsm
.u
.trigger
.length
= (uint32_t) buffer
.size
;
2935 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, buffer
.data
,
2938 lttng_dynamic_buffer_reset(&buffer
);
2945 static void __attribute__((constructor
)) init(void)
2947 /* Set default session group */
2948 lttng_set_tracing_group(DEFAULT_TRACING_GROUP
);
2954 static void __attribute__((destructor
)) lttng_ctl_exit(void)
2956 free(tracing_group
);