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 * This library is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License, version 2.1 only,
11 * as published by the Free Software Foundation.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this library; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 #include <common/common.h>
33 #include <common/compat/string.h>
34 #include <common/defaults.h>
35 #include <common/sessiond-comm/sessiond-comm.h>
36 #include <common/uri.h>
37 #include <common/utils.h>
38 #include <common/dynamic-buffer.h>
39 #include <lttng/lttng.h>
40 #include <lttng/health-internal.h>
41 #include <lttng/trigger/trigger-internal.h>
42 #include <lttng/endpoint.h>
43 #include <lttng/channel-internal.h>
44 #include <lttng/event-internal.h>
45 #include <lttng/userspace-probe-internal.h>
47 #include "filter/filter-ast.h"
48 #include "filter/filter-parser.h"
49 #include "filter/filter-bytecode.h"
50 #include "filter/memstream.h"
51 #include "lttng-ctl-helper.h"
54 static const int print_xml
= 1;
55 #define dbg_printf(fmt, args...) \
56 printf("[debug liblttng-ctl] " fmt, ## args)
58 static const int print_xml
= 0;
59 #define dbg_printf(fmt, args...) \
61 /* do nothing but check printf format */ \
63 printf("[debug liblttnctl] " fmt, ## args); \
68 /* Socket to session daemon for communication */
69 static int sessiond_socket
;
70 static char sessiond_sock_path
[PATH_MAX
];
73 static char *tracing_group
;
79 * Those two variables are used by error.h to silent or control the verbosity of
80 * error message. They are global to the library so application linking with it
81 * are able to compile correctly and also control verbosity of the library.
84 int lttng_opt_verbose
;
88 * Copy string from src to dst and enforce null terminated byte.
91 void lttng_ctl_copy_string(char *dst
, const char *src
, size_t len
)
94 strncpy(dst
, src
, len
);
95 /* Enforce the NULL terminated byte */
103 * Copy domain to lttcomm_session_msg domain.
105 * If domain is unknown, default domain will be the kernel.
108 void lttng_ctl_copy_lttng_domain(struct lttng_domain
*dst
,
109 struct lttng_domain
*src
)
113 case LTTNG_DOMAIN_KERNEL
:
114 case LTTNG_DOMAIN_UST
:
115 case LTTNG_DOMAIN_JUL
:
116 case LTTNG_DOMAIN_LOG4J
:
117 case LTTNG_DOMAIN_PYTHON
:
118 memcpy(dst
, src
, sizeof(struct lttng_domain
));
121 memset(dst
, 0, sizeof(struct lttng_domain
));
128 * Send lttcomm_session_msg to the session daemon.
130 * On success, returns the number of bytes sent (>=0)
131 * On error, returns -1
133 static int send_session_msg(struct lttcomm_session_msg
*lsm
)
138 ret
= -LTTNG_ERR_NO_SESSIOND
;
142 DBG("LSM cmd type : %d", lsm
->cmd_type
);
144 ret
= lttcomm_send_creds_unix_sock(sessiond_socket
, lsm
,
145 sizeof(struct lttcomm_session_msg
));
147 ret
= -LTTNG_ERR_FATAL
;
155 * Send var len data to the session daemon.
157 * On success, returns the number of bytes sent (>=0)
158 * On error, returns -1
160 static int send_session_varlen(const void *data
, size_t len
)
165 ret
= -LTTNG_ERR_NO_SESSIOND
;
174 ret
= lttcomm_send_unix_sock(sessiond_socket
, data
, len
);
176 ret
= -LTTNG_ERR_FATAL
;
184 * Send file descriptors to the session daemon.
186 * On success, returns the number of bytes sent (>=0)
187 * On error, returns -1
189 static int send_session_fds(const int *fds
, size_t nb_fd
)
194 ret
= -LTTNG_ERR_NO_SESSIOND
;
198 if (!fds
|| !nb_fd
) {
203 ret
= lttcomm_send_fds_unix_sock(sessiond_socket
, fds
, nb_fd
);
205 ret
= -LTTNG_ERR_FATAL
;
213 * Receive data from the sessiond socket.
215 * On success, returns the number of bytes received (>=0)
216 * On error, returns -1 (recvmsg() error) or -ENOTCONN
218 static int recv_data_sessiond(void *buf
, size_t len
)
223 ret
= -LTTNG_ERR_NO_SESSIOND
;
227 ret
= lttcomm_recv_unix_sock(sessiond_socket
, buf
, len
);
229 ret
= -LTTNG_ERR_FATAL
;
237 * Check if we are in the specified group.
239 * If yes return 1, else return -1.
242 int lttng_check_tracing_group(void)
244 struct group
*grp_tracing
; /* no free(). See getgrnam(3) */
246 int grp_list_size
, grp_id
, i
;
248 const char *grp_name
= tracing_group
;
250 /* Get GID of group 'tracing' */
251 grp_tracing
= getgrnam(grp_name
);
253 /* If grp_tracing is NULL, the group does not exist. */
257 /* Get number of supplementary group IDs */
258 grp_list_size
= getgroups(0, NULL
);
259 if (grp_list_size
< 0) {
264 /* Alloc group list of the right size */
265 grp_list
= zmalloc(grp_list_size
* sizeof(gid_t
));
270 grp_id
= getgroups(grp_list_size
, grp_list
);
276 for (i
= 0; i
< grp_list_size
; i
++) {
277 if (grp_list
[i
] == grp_tracing
->gr_gid
) {
291 * Try connect to session daemon with sock_path.
293 * Return 0 on success, else -1
295 static int try_connect_sessiond(const char *sock_path
)
299 /* If socket exist, we check if the daemon listens for connect. */
300 ret
= access(sock_path
, F_OK
);
306 ret
= lttcomm_connect_unix_sock(sock_path
);
312 ret
= lttcomm_close_unix_sock(ret
);
314 PERROR("lttcomm_close_unix_sock");
324 * Set sessiond socket path by putting it in the global sessiond_sock_path
327 * Returns 0 on success, negative value on failure (the sessiond socket path
328 * is somehow too long or ENOMEM).
330 static int set_session_daemon_path(void)
332 int in_tgroup
= 0; /* In tracing group. */
338 /* Are we in the tracing group ? */
339 in_tgroup
= lttng_check_tracing_group();
342 if ((uid
== 0) || in_tgroup
) {
343 lttng_ctl_copy_string(sessiond_sock_path
,
344 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
, sizeof(sessiond_sock_path
));
352 ret
= try_connect_sessiond(sessiond_sock_path
);
356 /* Global session daemon not available... */
358 /* ...or not in tracing group (and not root), default */
361 * With GNU C < 2.1, snprintf returns -1 if the target buffer
363 * With GNU C >= 2.1, snprintf returns the required size
364 * (excluding closing null)
366 ret
= snprintf(sessiond_sock_path
, sizeof(sessiond_sock_path
),
367 DEFAULT_HOME_CLIENT_UNIX_SOCK
, utils_get_home_dir());
368 if ((ret
< 0) || (ret
>= sizeof(sessiond_sock_path
))) {
380 * Connect to the LTTng session daemon.
382 * On success, return 0. On error, return -1.
384 static int connect_sessiond(void)
388 /* Don't try to connect if already connected. */
393 ret
= set_session_daemon_path();
398 /* Connect to the sesssion daemon. */
399 ret
= lttcomm_connect_unix_sock(sessiond_sock_path
);
404 sessiond_socket
= ret
;
414 * Clean disconnect from the session daemon.
416 * On success, return 0. On error, return -1.
418 static int disconnect_sessiond(void)
423 ret
= lttcomm_close_unix_sock(sessiond_socket
);
431 static int recv_sessiond_optional_data(size_t len
, void **user_buf
,
439 ret
= -LTTNG_ERR_INVALID
;
449 ret
= recv_data_sessiond(buf
, len
);
455 ret
= -LTTNG_ERR_INVALID
;
459 /* Move ownership of command header buffer to user. */
464 /* No command header. */
480 * Ask the session daemon a specific command and put the data into buf.
481 * Takes extra var. len. data and file descriptors as input to send to the
484 * Return size of data (only payload, not header) or a negative error code.
487 int lttng_ctl_ask_sessiond_fds_varlen(struct lttcomm_session_msg
*lsm
,
488 const int *fds
, size_t nb_fd
, const void *vardata
,
489 size_t vardata_len
, void **user_payload_buf
,
490 void **user_cmd_header_buf
, size_t *user_cmd_header_len
)
494 struct lttcomm_lttng_msg llm
;
496 ret
= connect_sessiond();
498 ret
= -LTTNG_ERR_NO_SESSIOND
;
502 /* Send command to session daemon */
503 ret
= send_session_msg(lsm
);
505 /* Ret value is a valid lttng error code. */
508 /* Send var len data */
509 ret
= send_session_varlen(vardata
, vardata_len
);
511 /* Ret value is a valid lttng error code. */
516 ret
= send_session_fds(fds
, nb_fd
);
518 /* Ret value is a valid lttng error code. */
522 /* Get header from data transmission */
523 ret
= recv_data_sessiond(&llm
, sizeof(llm
));
525 /* Ret value is a valid lttng error code. */
529 /* Check error code if OK */
530 if (llm
.ret_code
!= LTTNG_OK
) {
535 /* Get command header from data transmission */
536 ret
= recv_sessiond_optional_data(llm
.cmd_header_size
,
537 user_cmd_header_buf
, user_cmd_header_len
);
542 /* Get payload from data transmission */
543 ret
= recv_sessiond_optional_data(llm
.data_size
, user_payload_buf
,
552 disconnect_sessiond();
557 * Create lttng handle and return pointer.
559 * The returned pointer will be NULL in case of malloc() error.
561 struct lttng_handle
*lttng_create_handle(const char *session_name
,
562 struct lttng_domain
*domain
)
564 struct lttng_handle
*handle
= NULL
;
566 handle
= zmalloc(sizeof(struct lttng_handle
));
567 if (handle
== NULL
) {
568 PERROR("malloc handle");
572 /* Copy session name */
573 lttng_ctl_copy_string(handle
->session_name
, session_name
,
574 sizeof(handle
->session_name
));
576 /* Copy lttng domain or leave initialized to 0. */
578 lttng_ctl_copy_lttng_domain(&handle
->domain
, domain
);
586 * Destroy handle by free(3) the pointer.
588 void lttng_destroy_handle(struct lttng_handle
*handle
)
594 * Register an outside consumer.
596 * Returns size of returned session payload data or a negative error code.
598 int lttng_register_consumer(struct lttng_handle
*handle
,
599 const char *socket_path
)
601 struct lttcomm_session_msg lsm
;
603 if (handle
== NULL
|| socket_path
== NULL
) {
604 return -LTTNG_ERR_INVALID
;
607 memset(&lsm
, 0, sizeof(lsm
));
608 lsm
.cmd_type
= LTTNG_REGISTER_CONSUMER
;
609 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
610 sizeof(lsm
.session
.name
));
611 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
613 lttng_ctl_copy_string(lsm
.u
.reg
.path
, socket_path
,
614 sizeof(lsm
.u
.reg
.path
));
616 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
620 * Start tracing for all traces of the session.
622 * Returns size of returned session payload data or a negative error code.
624 int lttng_start_tracing(const char *session_name
)
626 struct lttcomm_session_msg lsm
;
628 if (session_name
== NULL
) {
629 return -LTTNG_ERR_INVALID
;
632 memset(&lsm
, 0, sizeof(lsm
));
633 lsm
.cmd_type
= LTTNG_START_TRACE
;
635 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
636 sizeof(lsm
.session
.name
));
638 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
642 * Stop tracing for all traces of the session.
644 static int _lttng_stop_tracing(const char *session_name
, int wait
)
647 struct lttcomm_session_msg lsm
;
649 if (session_name
== NULL
) {
650 return -LTTNG_ERR_INVALID
;
653 memset(&lsm
, 0, sizeof(lsm
));
654 lsm
.cmd_type
= LTTNG_STOP_TRACE
;
656 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
657 sizeof(lsm
.session
.name
));
659 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
660 if (ret
< 0 && ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
668 /* Check for data availability */
670 data_ret
= lttng_data_pending(session_name
);
672 /* Return the data available call error. */
678 * Data sleep time before retrying (in usec). Don't sleep if the
679 * call returned value indicates availability.
682 usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME
);
684 } while (data_ret
!= 0);
692 * Stop tracing and wait for data availability.
694 int lttng_stop_tracing(const char *session_name
)
696 return _lttng_stop_tracing(session_name
, 1);
700 * Stop tracing but _don't_ wait for data availability.
702 int lttng_stop_tracing_no_wait(const char *session_name
)
704 return _lttng_stop_tracing(session_name
, 0);
708 * Add context to a channel.
710 * If the given channel is NULL, add the contexts to all channels.
711 * The event_name param is ignored.
713 * Returns the size of the returned payload data or a negative error code.
715 int lttng_add_context(struct lttng_handle
*handle
,
716 struct lttng_event_context
*ctx
, const char *event_name
,
717 const char *channel_name
)
722 struct lttcomm_session_msg lsm
;
724 /* Safety check. Both are mandatory. */
725 if (handle
== NULL
|| ctx
== NULL
) {
726 ret
= -LTTNG_ERR_INVALID
;
730 memset(&lsm
, 0, sizeof(lsm
));
731 lsm
.cmd_type
= LTTNG_ADD_CONTEXT
;
733 /* If no channel name, send empty string. */
734 if (channel_name
== NULL
) {
735 lttng_ctl_copy_string(lsm
.u
.context
.channel_name
, "",
736 sizeof(lsm
.u
.context
.channel_name
));
738 lttng_ctl_copy_string(lsm
.u
.context
.channel_name
, channel_name
,
739 sizeof(lsm
.u
.context
.channel_name
));
742 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
743 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
744 sizeof(lsm
.session
.name
));
746 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
747 size_t provider_len
, ctx_len
;
748 const char *provider_name
= ctx
->u
.app_ctx
.provider_name
;
749 const char *ctx_name
= ctx
->u
.app_ctx
.ctx_name
;
751 if (!provider_name
|| !ctx_name
) {
752 ret
= -LTTNG_ERR_INVALID
;
756 provider_len
= strlen(provider_name
);
757 if (provider_len
== 0) {
758 ret
= -LTTNG_ERR_INVALID
;
761 lsm
.u
.context
.provider_name_len
= provider_len
;
763 ctx_len
= strlen(ctx_name
);
765 ret
= -LTTNG_ERR_INVALID
;
768 lsm
.u
.context
.context_name_len
= ctx_len
;
770 len
= provider_len
+ ctx_len
;
773 ret
= -LTTNG_ERR_NOMEM
;
777 memcpy(buf
, provider_name
, provider_len
);
778 memcpy(buf
+ provider_len
, ctx_name
, ctx_len
);
780 memcpy(&lsm
.u
.context
.ctx
, ctx
, sizeof(struct lttng_event_context
));
782 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
784 * Don't leak application addresses to the sessiond.
785 * This is only necessary when ctx is for an app ctx otherwise
786 * the values inside the union (type & config) are overwritten.
788 lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
= NULL
;
789 lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
= NULL
;
792 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, buf
, len
, NULL
);
799 * Enable event(s) for a channel.
801 * If no event name is specified, all events are enabled.
802 * If no channel name is specified, the default 'channel0' is used.
804 * Returns size of returned session payload data or a negative error code.
806 int lttng_enable_event(struct lttng_handle
*handle
,
807 struct lttng_event
*ev
, const char *channel_name
)
809 return lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
814 * Create or enable an event with a filter expression.
816 * Return negative error value on error.
817 * Return size of returned session payload data if OK.
819 int lttng_enable_event_with_filter(struct lttng_handle
*handle
,
820 struct lttng_event
*event
, const char *channel_name
,
821 const char *filter_expression
)
823 return lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
824 filter_expression
, 0, NULL
);
828 * Depending on the event, return a newly allocated agent filter expression or
829 * NULL if not applicable.
831 * An event with NO loglevel and the name is * will return NULL.
833 static char *set_agent_filter(const char *filter
, struct lttng_event
*ev
)
836 char *agent_filter
= NULL
;
840 /* Don't add filter for the '*' event. */
841 if (strcmp(ev
->name
, "*") != 0) {
843 err
= asprintf(&agent_filter
, "(%s) && (logger_name == \"%s\")", filter
,
846 err
= asprintf(&agent_filter
, "logger_name == \"%s\"", ev
->name
);
854 /* Add loglevel filtering if any for the JUL domain. */
855 if (ev
->loglevel_type
!= LTTNG_EVENT_LOGLEVEL_ALL
) {
858 if (ev
->loglevel_type
== LTTNG_EVENT_LOGLEVEL_RANGE
) {
864 if (filter
|| agent_filter
) {
867 err
= asprintf(&new_filter
, "(%s) && (int_loglevel %s %d)",
868 agent_filter
? agent_filter
: filter
, op
,
873 agent_filter
= new_filter
;
875 err
= asprintf(&agent_filter
, "int_loglevel %s %d", op
,
891 * Generate the filter bytecode from a given filter expression string. Put the
892 * newly allocated parser context in ctxp and populate the lsm object with the
895 * Return 0 on success else a LTTNG_ERR_* code and ctxp is untouched.
897 static int generate_filter(char *filter_expression
,
898 struct lttcomm_session_msg
*lsm
, struct filter_parser_ctx
**ctxp
)
901 struct filter_parser_ctx
*ctx
= NULL
;
904 assert(filter_expression
);
909 * Casting const to non-const, as the underlying function will use it in
912 fmem
= lttng_fmemopen((void *) filter_expression
,
913 strlen(filter_expression
), "r");
915 fprintf(stderr
, "Error opening memory as stream\n");
916 ret
= -LTTNG_ERR_FILTER_NOMEM
;
919 ctx
= filter_parser_ctx_alloc(fmem
);
921 fprintf(stderr
, "Error allocating parser\n");
922 ret
= -LTTNG_ERR_FILTER_NOMEM
;
923 goto filter_alloc_error
;
925 ret
= filter_parser_ctx_append_ast(ctx
);
927 fprintf(stderr
, "Parse error\n");
928 ret
= -LTTNG_ERR_FILTER_INVAL
;
932 ret
= filter_visitor_print_xml(ctx
, stdout
, 0);
935 fprintf(stderr
, "XML print error\n");
936 ret
= -LTTNG_ERR_FILTER_INVAL
;
941 dbg_printf("Generating IR... ");
943 ret
= filter_visitor_ir_generate(ctx
);
945 fprintf(stderr
, "Generate IR error\n");
946 ret
= -LTTNG_ERR_FILTER_INVAL
;
949 dbg_printf("done\n");
951 dbg_printf("Validating IR... ");
953 ret
= filter_visitor_ir_check_binary_op_nesting(ctx
);
955 ret
= -LTTNG_ERR_FILTER_INVAL
;
959 /* Normalize globbing patterns in the expression. */
960 ret
= filter_visitor_ir_normalize_glob_patterns(ctx
);
962 ret
= -LTTNG_ERR_FILTER_INVAL
;
966 /* Validate strings used as literals in the expression. */
967 ret
= filter_visitor_ir_validate_string(ctx
);
969 ret
= -LTTNG_ERR_FILTER_INVAL
;
973 /* Validate globbing patterns in the expression. */
974 ret
= filter_visitor_ir_validate_globbing(ctx
);
976 ret
= -LTTNG_ERR_FILTER_INVAL
;
980 dbg_printf("done\n");
982 dbg_printf("Generating bytecode... ");
984 ret
= filter_visitor_bytecode_generate(ctx
);
986 fprintf(stderr
, "Generate bytecode error\n");
987 ret
= -LTTNG_ERR_FILTER_INVAL
;
990 dbg_printf("done\n");
991 dbg_printf("Size of bytecode generated: %u bytes.\n",
992 bytecode_get_len(&ctx
->bytecode
->b
));
994 lsm
->u
.enable
.bytecode_len
= sizeof(ctx
->bytecode
->b
)
995 + bytecode_get_len(&ctx
->bytecode
->b
);
996 lsm
->u
.enable
.expression_len
= strlen(filter_expression
) + 1;
998 /* No need to keep the memory stream. */
999 if (fclose(fmem
) != 0) {
1007 filter_ir_free(ctx
);
1008 filter_parser_ctx_free(ctx
);
1010 if (fclose(fmem
) != 0) {
1018 * Enable event(s) for a channel, possibly with exclusions and a filter.
1019 * If no event name is specified, all events are enabled.
1020 * If no channel name is specified, the default name is used.
1021 * If filter expression is not NULL, the filter is set for the event.
1022 * If exclusion count is not zero, the exclusions are set for the event.
1023 * Returns size of returned session payload data or a negative error code.
1025 int lttng_enable_event_with_exclusions(struct lttng_handle
*handle
,
1026 struct lttng_event
*ev
, const char *channel_name
,
1027 const char *original_filter_expression
,
1028 int exclusion_count
, char **exclusion_list
)
1030 struct lttcomm_session_msg lsm
;
1031 struct lttng_dynamic_buffer send_buffer
;
1032 int ret
= 0, i
, fd_to_send
= -1;
1033 bool send_fd
= false;
1034 unsigned int free_filter_expression
= 0;
1035 struct filter_parser_ctx
*ctx
= NULL
;
1037 memset(&send_buffer
, 0, sizeof(send_buffer
));
1040 * Cast as non-const since we may replace the filter expression
1041 * by a dynamically allocated string. Otherwise, the original
1042 * string is not modified.
1044 char *filter_expression
= (char *) original_filter_expression
;
1046 if (handle
== NULL
|| ev
== NULL
) {
1047 ret
= -LTTNG_ERR_INVALID
;
1052 * Empty filter string will always be rejected by the parser
1053 * anyway, so treat this corner-case early to eliminate
1054 * lttng_fmemopen error for 0-byte allocation.
1056 if (filter_expression
&& filter_expression
[0] == '\0') {
1057 ret
= -LTTNG_ERR_INVALID
;
1061 memset(&lsm
, 0, sizeof(lsm
));
1063 /* If no channel name, send empty string. */
1064 if (channel_name
== NULL
) {
1065 lttng_ctl_copy_string(lsm
.u
.enable
.channel_name
, "",
1066 sizeof(lsm
.u
.enable
.channel_name
));
1068 lttng_ctl_copy_string(lsm
.u
.enable
.channel_name
, channel_name
,
1069 sizeof(lsm
.u
.enable
.channel_name
));
1072 lsm
.cmd_type
= LTTNG_ENABLE_EVENT
;
1073 if (ev
->name
[0] == '\0') {
1074 /* Enable all events */
1075 lttng_ctl_copy_string(ev
->name
, "*", sizeof(ev
->name
));
1078 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1079 /* FIXME: copying non-packed struct to packed struct. */
1080 memcpy(&lsm
.u
.enable
.event
, ev
, sizeof(lsm
.u
.enable
.event
));
1082 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1083 sizeof(lsm
.session
.name
));
1084 lsm
.u
.enable
.exclusion_count
= exclusion_count
;
1085 lsm
.u
.enable
.bytecode_len
= 0;
1088 * We have either a filter or some exclusions, so we need to set up
1089 * a variable-length memory block from where to send the data.
1091 lttng_dynamic_buffer_init(&send_buffer
);
1093 /* Parse filter expression. */
1094 if (filter_expression
!= NULL
|| handle
->domain
.type
== LTTNG_DOMAIN_JUL
1095 || handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
1096 || handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1097 if (handle
->domain
.type
== LTTNG_DOMAIN_JUL
||
1098 handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
||
1099 handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1102 /* Setup JUL filter if needed. */
1103 agent_filter
= set_agent_filter(filter_expression
, ev
);
1104 if (!agent_filter
) {
1105 if (!filter_expression
) {
1107 * No JUL and no filter, just skip
1114 * With an agent filter, the original filter has
1115 * been added to it thus replace the filter
1118 filter_expression
= agent_filter
;
1119 free_filter_expression
= 1;
1123 ret
= generate_filter(filter_expression
, &lsm
, &ctx
);
1129 ret
= lttng_dynamic_buffer_set_capacity(&send_buffer
,
1130 lsm
.u
.enable
.bytecode_len
1131 + lsm
.u
.enable
.expression_len
1132 + LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
1134 ret
= -LTTNG_ERR_EXCLUSION_NOMEM
;
1138 /* Put exclusion names first in the data. */
1139 for (i
= 0; i
< exclusion_count
; i
++) {
1140 size_t exclusion_len
;
1142 exclusion_len
= lttng_strnlen(*(exclusion_list
+ i
),
1143 LTTNG_SYMBOL_NAME_LEN
);
1144 if (exclusion_len
== LTTNG_SYMBOL_NAME_LEN
) {
1145 /* Exclusion is not NULL-terminated. */
1146 ret
= -LTTNG_ERR_INVALID
;
1150 ret
= lttng_dynamic_buffer_append(&send_buffer
,
1151 *(exclusion_list
+ i
),
1152 LTTNG_SYMBOL_NAME_LEN
);
1158 /* Add filter expression next. */
1159 if (filter_expression
) {
1160 ret
= lttng_dynamic_buffer_append(&send_buffer
,
1161 filter_expression
, lsm
.u
.enable
.expression_len
);
1166 /* Add filter bytecode next. */
1167 if (ctx
&& lsm
.u
.enable
.bytecode_len
!= 0) {
1168 ret
= lttng_dynamic_buffer_append(&send_buffer
,
1169 &ctx
->bytecode
->b
, lsm
.u
.enable
.bytecode_len
);
1174 if (ev
->extended
.ptr
) {
1175 struct lttng_event_extended
*ev_ext
=
1176 (struct lttng_event_extended
*) ev
->extended
.ptr
;
1178 if (ev_ext
->probe_location
) {
1180 * lttng_userspace_probe_location_serialize returns the
1181 * number of bytes that was appended to the buffer.
1183 ret
= lttng_userspace_probe_location_serialize(
1184 ev_ext
->probe_location
, &send_buffer
,
1190 send_fd
= fd_to_send
>= 0;
1192 * Set the size of the userspace probe location element
1193 * of the buffer so that the receiving side knows where
1196 lsm
.u
.enable
.userspace_probe_location_len
= ret
;
1200 ret
= lttng_ctl_ask_sessiond_fds_varlen(&lsm
,
1201 send_fd
? &fd_to_send
: NULL
,
1203 send_buffer
.size
? send_buffer
.data
: NULL
,
1204 send_buffer
.size
, NULL
, NULL
, 0);
1207 if (filter_expression
&& ctx
) {
1208 filter_bytecode_free(ctx
);
1209 filter_ir_free(ctx
);
1210 filter_parser_ctx_free(ctx
);
1213 if (free_filter_expression
) {
1215 * The filter expression has been replaced and must be freed as
1216 * it is not the original filter expression received as a
1219 free(filter_expression
);
1223 * Return directly to the caller and don't ask the sessiond since
1224 * something went wrong in the parsing of data above.
1226 lttng_dynamic_buffer_reset(&send_buffer
);
1230 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1234 int lttng_disable_event_ext(struct lttng_handle
*handle
,
1235 struct lttng_event
*ev
, const char *channel_name
,
1236 const char *original_filter_expression
)
1238 struct lttcomm_session_msg lsm
;
1241 unsigned int free_filter_expression
= 0;
1242 struct filter_parser_ctx
*ctx
= NULL
;
1244 * Cast as non-const since we may replace the filter expression
1245 * by a dynamically allocated string. Otherwise, the original
1246 * string is not modified.
1248 char *filter_expression
= (char *) original_filter_expression
;
1250 if (handle
== NULL
|| ev
== NULL
) {
1251 ret
= -LTTNG_ERR_INVALID
;
1256 * Empty filter string will always be rejected by the parser
1257 * anyway, so treat this corner-case early to eliminate
1258 * lttng_fmemopen error for 0-byte allocation.
1260 if (filter_expression
&& filter_expression
[0] == '\0') {
1261 ret
= -LTTNG_ERR_INVALID
;
1265 memset(&lsm
, 0, sizeof(lsm
));
1267 /* If no channel name, send empty string. */
1268 if (channel_name
== NULL
) {
1269 lttng_ctl_copy_string(lsm
.u
.disable
.channel_name
, "",
1270 sizeof(lsm
.u
.disable
.channel_name
));
1272 lttng_ctl_copy_string(lsm
.u
.disable
.channel_name
, channel_name
,
1273 sizeof(lsm
.u
.disable
.channel_name
));
1276 lsm
.cmd_type
= LTTNG_DISABLE_EVENT
;
1278 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1279 /* FIXME: copying non-packed struct to packed struct. */
1280 memcpy(&lsm
.u
.disable
.event
, ev
, sizeof(lsm
.u
.disable
.event
));
1282 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1283 sizeof(lsm
.session
.name
));
1284 lsm
.u
.disable
.bytecode_len
= 0;
1287 * For the JUL domain, a filter is enforced except for the
1288 * disable all event. This is done to avoid having the event in
1289 * all sessions thus filtering by logger name.
1291 if (filter_expression
== NULL
&&
1292 (handle
->domain
.type
!= LTTNG_DOMAIN_JUL
&&
1293 handle
->domain
.type
!= LTTNG_DOMAIN_LOG4J
&&
1294 handle
->domain
.type
!= LTTNG_DOMAIN_PYTHON
)) {
1299 * We have a filter, so we need to set up a variable-length
1300 * memory block from where to send the data.
1303 /* Parse filter expression */
1304 if (filter_expression
!= NULL
|| handle
->domain
.type
== LTTNG_DOMAIN_JUL
1305 || handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
1306 || handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1307 if (handle
->domain
.type
== LTTNG_DOMAIN_JUL
||
1308 handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
||
1309 handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1312 /* Setup JUL filter if needed. */
1313 agent_filter
= set_agent_filter(filter_expression
, ev
);
1314 if (!agent_filter
) {
1315 if (!filter_expression
) {
1317 * No JUL and no filter, just skip
1324 * With a JUL filter, the original filter has
1325 * been added to it thus replace the filter
1328 filter_expression
= agent_filter
;
1329 free_filter_expression
= 1;
1333 ret
= generate_filter(filter_expression
, &lsm
, &ctx
);
1339 varlen_data
= zmalloc(lsm
.u
.disable
.bytecode_len
1340 + lsm
.u
.disable
.expression_len
);
1342 ret
= -LTTNG_ERR_EXCLUSION_NOMEM
;
1346 /* Add filter expression. */
1347 if (lsm
.u
.disable
.expression_len
!= 0) {
1350 lsm
.u
.disable
.expression_len
);
1352 /* Add filter bytecode next. */
1353 if (ctx
&& lsm
.u
.disable
.bytecode_len
!= 0) {
1355 + lsm
.u
.disable
.expression_len
,
1357 lsm
.u
.disable
.bytecode_len
);
1360 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, varlen_data
,
1361 lsm
.u
.disable
.bytecode_len
+ lsm
.u
.disable
.expression_len
, NULL
);
1365 if (filter_expression
&& ctx
) {
1366 filter_bytecode_free(ctx
);
1367 filter_ir_free(ctx
);
1368 filter_parser_ctx_free(ctx
);
1371 if (free_filter_expression
) {
1373 * The filter expression has been replaced and must be freed as
1374 * it is not the original filter expression received as a
1377 free(filter_expression
);
1381 * Return directly to the caller and don't ask the sessiond since
1382 * something went wrong in the parsing of data above.
1387 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1392 * Disable event(s) of a channel and domain.
1393 * If no event name is specified, all events are disabled.
1394 * If no channel name is specified, the default 'channel0' is used.
1395 * Returns size of returned session payload data or a negative error code.
1397 int lttng_disable_event(struct lttng_handle
*handle
, const char *name
,
1398 const char *channel_name
)
1400 struct lttng_event ev
;
1402 memset(&ev
, 0, sizeof(ev
));
1404 ev
.type
= LTTNG_EVENT_ALL
;
1405 lttng_ctl_copy_string(ev
.name
, name
, sizeof(ev
.name
));
1406 return lttng_disable_event_ext(handle
, &ev
, channel_name
, NULL
);
1409 struct lttng_channel
*lttng_channel_create(struct lttng_domain
*domain
)
1411 struct lttng_channel
*channel
= NULL
;
1412 struct lttng_channel_extended
*extended
= NULL
;
1418 /* Validate domain. */
1419 switch (domain
->type
) {
1420 case LTTNG_DOMAIN_UST
:
1421 switch (domain
->buf_type
) {
1422 case LTTNG_BUFFER_PER_UID
:
1423 case LTTNG_BUFFER_PER_PID
:
1429 case LTTNG_DOMAIN_KERNEL
:
1430 if (domain
->buf_type
!= LTTNG_BUFFER_GLOBAL
) {
1438 channel
= zmalloc(sizeof(*channel
));
1443 extended
= zmalloc(sizeof(*extended
));
1448 channel
->attr
.extended
.ptr
= extended
;
1450 lttng_channel_set_default_attr(domain
, &channel
->attr
);
1458 void lttng_channel_destroy(struct lttng_channel
*channel
)
1464 if (channel
->attr
.extended
.ptr
) {
1465 free(channel
->attr
.extended
.ptr
);
1471 * Enable channel per domain
1472 * Returns size of returned session payload data or a negative error code.
1474 int lttng_enable_channel(struct lttng_handle
*handle
,
1475 struct lttng_channel
*in_chan
)
1477 struct lttcomm_session_msg lsm
;
1479 /* NULL arguments are forbidden. No default values. */
1480 if (handle
== NULL
|| in_chan
== NULL
) {
1481 return -LTTNG_ERR_INVALID
;
1484 memset(&lsm
, 0, sizeof(lsm
));
1485 memcpy(&lsm
.u
.channel
.chan
, in_chan
, sizeof(lsm
.u
.channel
.chan
));
1486 lsm
.u
.channel
.chan
.attr
.extended
.ptr
= NULL
;
1488 if (!in_chan
->attr
.extended
.ptr
) {
1489 struct lttng_channel
*channel
;
1490 struct lttng_channel_extended
*extended
;
1492 channel
= lttng_channel_create(&handle
->domain
);
1494 return -LTTNG_ERR_NOMEM
;
1498 * Create a new channel in order to use default extended
1501 extended
= (struct lttng_channel_extended
*)
1502 channel
->attr
.extended
.ptr
;
1503 memcpy(&lsm
.u
.channel
.extended
, extended
, sizeof(*extended
));
1504 lttng_channel_destroy(channel
);
1506 struct lttng_channel_extended
*extended
;
1508 extended
= (struct lttng_channel_extended
*)
1509 in_chan
->attr
.extended
.ptr
;
1510 memcpy(&lsm
.u
.channel
.extended
, extended
, sizeof(*extended
));
1513 lsm
.cmd_type
= LTTNG_ENABLE_CHANNEL
;
1514 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1516 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1517 sizeof(lsm
.session
.name
));
1519 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1523 * All tracing will be stopped for registered events of the channel.
1524 * Returns size of returned session payload data or a negative error code.
1526 int lttng_disable_channel(struct lttng_handle
*handle
, const char *name
)
1528 struct lttcomm_session_msg lsm
;
1530 /* Safety check. Both are mandatory. */
1531 if (handle
== NULL
|| name
== NULL
) {
1532 return -LTTNG_ERR_INVALID
;
1535 memset(&lsm
, 0, sizeof(lsm
));
1537 lsm
.cmd_type
= LTTNG_DISABLE_CHANNEL
;
1539 lttng_ctl_copy_string(lsm
.u
.disable
.channel_name
, name
,
1540 sizeof(lsm
.u
.disable
.channel_name
));
1542 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1544 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1545 sizeof(lsm
.session
.name
));
1547 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1551 * Add PID to session tracker.
1552 * Return 0 on success else a negative LTTng error code.
1554 int lttng_track_pid(struct lttng_handle
*handle
, int pid
)
1556 struct lttcomm_session_msg lsm
;
1558 /* NULL arguments are forbidden. No default values. */
1559 if (handle
== NULL
) {
1560 return -LTTNG_ERR_INVALID
;
1563 memset(&lsm
, 0, sizeof(lsm
));
1565 lsm
.cmd_type
= LTTNG_TRACK_PID
;
1566 lsm
.u
.pid_tracker
.pid
= pid
;
1568 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1570 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1571 sizeof(lsm
.session
.name
));
1573 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1577 * Remove PID from session tracker.
1578 * Return 0 on success else a negative LTTng error code.
1580 int lttng_untrack_pid(struct lttng_handle
*handle
, int pid
)
1582 struct lttcomm_session_msg lsm
;
1584 /* NULL arguments are forbidden. No default values. */
1585 if (handle
== NULL
) {
1586 return -LTTNG_ERR_INVALID
;
1589 memset(&lsm
, 0, sizeof(lsm
));
1591 lsm
.cmd_type
= LTTNG_UNTRACK_PID
;
1592 lsm
.u
.pid_tracker
.pid
= pid
;
1594 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1596 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1597 sizeof(lsm
.session
.name
));
1599 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1603 * Lists all available tracepoints of domain.
1604 * Sets the contents of the events array.
1605 * Returns the number of lttng_event entries in events;
1606 * on error, returns a negative value.
1608 int lttng_list_tracepoints(struct lttng_handle
*handle
,
1609 struct lttng_event
**events
)
1612 struct lttcomm_session_msg lsm
;
1614 if (handle
== NULL
) {
1615 return -LTTNG_ERR_INVALID
;
1618 memset(&lsm
, 0, sizeof(lsm
));
1619 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINTS
;
1620 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1622 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) events
);
1627 return ret
/ sizeof(struct lttng_event
);
1631 * Lists all available tracepoint fields of domain.
1632 * Sets the contents of the event field array.
1633 * Returns the number of lttng_event_field entries in events;
1634 * on error, returns a negative value.
1636 int lttng_list_tracepoint_fields(struct lttng_handle
*handle
,
1637 struct lttng_event_field
**fields
)
1640 struct lttcomm_session_msg lsm
;
1642 if (handle
== NULL
) {
1643 return -LTTNG_ERR_INVALID
;
1646 memset(&lsm
, 0, sizeof(lsm
));
1647 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINT_FIELDS
;
1648 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1650 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) fields
);
1655 return ret
/ sizeof(struct lttng_event_field
);
1659 * Lists all available kernel system calls. Allocates and sets the contents of
1662 * Returns the number of lttng_event entries in events; on error, returns a
1665 int lttng_list_syscalls(struct lttng_event
**events
)
1668 struct lttcomm_session_msg lsm
;
1671 return -LTTNG_ERR_INVALID
;
1674 memset(&lsm
, 0, sizeof(lsm
));
1675 lsm
.cmd_type
= LTTNG_LIST_SYSCALLS
;
1676 /* Force kernel domain for system calls. */
1677 lsm
.domain
.type
= LTTNG_DOMAIN_KERNEL
;
1679 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) events
);
1684 return ret
/ sizeof(struct lttng_event
);
1688 * Returns a human readable string describing
1689 * the error code (a negative value).
1691 const char *lttng_strerror(int code
)
1693 return error_get_str(code
);
1697 * Create a brand new session using name and url for destination.
1699 * Returns LTTNG_OK on success or a negative error code.
1701 int lttng_create_session(const char *name
, const char *url
)
1705 struct lttcomm_session_msg lsm
;
1706 struct lttng_uri
*uris
= NULL
;
1709 return -LTTNG_ERR_INVALID
;
1712 memset(&lsm
, 0, sizeof(lsm
));
1714 lsm
.cmd_type
= LTTNG_CREATE_SESSION
;
1715 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
1717 /* There should never be a data URL */
1718 size
= uri_parse_str_urls(url
, NULL
, &uris
);
1720 return -LTTNG_ERR_INVALID
;
1723 lsm
.u
.uri
.size
= size
;
1725 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
1726 sizeof(struct lttng_uri
) * size
, NULL
);
1733 * Destroy session using name.
1734 * Returns size of returned session payload data or a negative error code.
1737 int _lttng_destroy_session(const char *session_name
)
1739 struct lttcomm_session_msg lsm
;
1741 if (session_name
== NULL
) {
1742 return -LTTNG_ERR_INVALID
;
1745 memset(&lsm
, 0, sizeof(lsm
));
1746 lsm
.cmd_type
= LTTNG_DESTROY_SESSION
;
1748 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
1749 sizeof(lsm
.session
.name
));
1751 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1755 * Stop the session and wait for the data before destroying it
1757 int lttng_destroy_session(const char *session_name
)
1762 * Stop the tracing and wait for the data.
1764 ret
= _lttng_stop_tracing(session_name
, 1);
1765 if (ret
&& ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
1769 ret
= _lttng_destroy_session(session_name
);
1775 * Destroy the session without waiting for the data.
1777 int lttng_destroy_session_no_wait(const char *session_name
)
1782 * Stop the tracing without waiting for the data.
1783 * The session might already have been stopped, so just
1786 ret
= _lttng_stop_tracing(session_name
, 0);
1787 if (ret
&& ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
1791 ret
= _lttng_destroy_session(session_name
);
1797 * Ask the session daemon for all available sessions.
1798 * Sets the contents of the sessions array.
1799 * Returns the number of lttng_session entries in sessions;
1800 * on error, returns a negative value.
1802 int lttng_list_sessions(struct lttng_session
**sessions
)
1805 struct lttcomm_session_msg lsm
;
1807 memset(&lsm
, 0, sizeof(lsm
));
1808 lsm
.cmd_type
= LTTNG_LIST_SESSIONS
;
1809 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) sessions
);
1814 return ret
/ sizeof(struct lttng_session
);
1817 int lttng_set_session_shm_path(const char *session_name
,
1818 const char *shm_path
)
1820 struct lttcomm_session_msg lsm
;
1822 if (session_name
== NULL
) {
1823 return -LTTNG_ERR_INVALID
;
1826 memset(&lsm
, 0, sizeof(lsm
));
1827 lsm
.cmd_type
= LTTNG_SET_SESSION_SHM_PATH
;
1829 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
1830 sizeof(lsm
.session
.name
));
1831 lttng_ctl_copy_string(lsm
.u
.set_shm_path
.shm_path
, shm_path
,
1832 sizeof(lsm
.u
.set_shm_path
.shm_path
));
1834 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1838 * Ask the session daemon for all available domains of a session.
1839 * Sets the contents of the domains array.
1840 * Returns the number of lttng_domain entries in domains;
1841 * on error, returns a negative value.
1843 int lttng_list_domains(const char *session_name
,
1844 struct lttng_domain
**domains
)
1847 struct lttcomm_session_msg lsm
;
1849 if (session_name
== NULL
) {
1850 return -LTTNG_ERR_INVALID
;
1853 memset(&lsm
, 0, sizeof(lsm
));
1854 lsm
.cmd_type
= LTTNG_LIST_DOMAINS
;
1856 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
1857 sizeof(lsm
.session
.name
));
1859 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) domains
);
1864 return ret
/ sizeof(struct lttng_domain
);
1868 * Ask the session daemon for all available channels of a session.
1869 * Sets the contents of the channels array.
1870 * Returns the number of lttng_channel entries in channels;
1871 * on error, returns a negative value.
1873 int lttng_list_channels(struct lttng_handle
*handle
,
1874 struct lttng_channel
**channels
)
1877 size_t channel_count
, i
;
1878 const size_t channel_size
= sizeof(struct lttng_channel
) +
1879 sizeof(struct lttng_channel_extended
);
1880 struct lttcomm_session_msg lsm
;
1883 if (handle
== NULL
) {
1884 ret
= -LTTNG_ERR_INVALID
;
1888 memset(&lsm
, 0, sizeof(lsm
));
1889 lsm
.cmd_type
= LTTNG_LIST_CHANNELS
;
1890 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1891 sizeof(lsm
.session
.name
));
1893 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1895 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) channels
);
1900 if (ret
% channel_size
) {
1901 ret
= -LTTNG_ERR_UNK
;
1906 channel_count
= (size_t) ret
/ channel_size
;
1908 /* Set extended info pointers */
1909 extended_at
= ((void *) *channels
) +
1910 channel_count
* sizeof(struct lttng_channel
);
1911 for (i
= 0; i
< channel_count
; i
++) {
1912 struct lttng_channel
*chan
= &(*channels
)[i
];
1914 chan
->attr
.extended
.ptr
= extended_at
;
1915 extended_at
+= sizeof(struct lttng_channel_extended
);
1918 ret
= (int) channel_count
;
1924 * Ask the session daemon for all available events of a session channel.
1925 * Sets the contents of the events array.
1926 * Returns the number of lttng_event entries in events;
1927 * on error, returns a negative value.
1929 int lttng_list_events(struct lttng_handle
*handle
,
1930 const char *channel_name
, struct lttng_event
**events
)
1933 struct lttcomm_session_msg lsm
;
1934 struct lttcomm_event_command_header
*cmd_header
= NULL
;
1935 size_t cmd_header_len
;
1936 uint32_t nb_events
, i
;
1938 char *reception_buffer
= NULL
;
1939 struct lttng_dynamic_buffer listing
;
1942 /* Safety check. An handle and channel name are mandatory */
1943 if (handle
== NULL
|| channel_name
== NULL
) {
1944 return -LTTNG_ERR_INVALID
;
1947 memset(&lsm
, 0, sizeof(lsm
));
1948 lsm
.cmd_type
= LTTNG_LIST_EVENTS
;
1949 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1950 sizeof(lsm
.session
.name
));
1951 lttng_ctl_copy_string(lsm
.u
.list
.channel_name
, channel_name
,
1952 sizeof(lsm
.u
.list
.channel_name
));
1953 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1955 ret
= lttng_ctl_ask_sessiond_fds_varlen(&lsm
, NULL
, 0, NULL
, 0,
1956 (void **) &reception_buffer
, (void **) &cmd_header
,
1962 /* Set number of events and free command header */
1963 nb_events
= cmd_header
->nb_events
;
1964 if (nb_events
> INT_MAX
) {
1972 * The buffer that is returned must contain a "flat" version of
1973 * the events that are returned. In other words, all pointers
1974 * within an lttng_event must point to a location within the returned
1975 * buffer so that the user may free everything by simply calling free()
1976 * on the returned buffer. This is needed in order to maintain API
1979 * A first pass is performed to compute the size of the buffer that
1980 * must be allocated. A second pass is then performed to setup
1981 * the returned events so that their members always point within the
1984 * The layout of the returned buffer is as follows:
1985 * - struct lttng_event[nb_events],
1986 * - nb_events times the following:
1987 * - struct lttng_event_extended,
1988 * - flattened version of userspace_probe_location
1989 * - filter_expression
1991 * - padding to align to 64-bits
1993 comm_ext_at
= reception_buffer
+
1994 (nb_events
* sizeof(struct lttng_event
));
1995 storage_req
= nb_events
* sizeof(struct lttng_event
);
1997 for (i
= 0; i
< nb_events
; i
++) {
1998 struct lttcomm_event_extended_header
*ext_comm
=
1999 (struct lttcomm_event_extended_header
*) comm_ext_at
;
2000 int probe_storage_req
= 0;
2002 comm_ext_at
+= sizeof(*ext_comm
);
2003 comm_ext_at
+= ext_comm
->filter_len
;
2005 ext_comm
->nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
;
2007 if (ext_comm
->userspace_probe_location_len
) {
2008 struct lttng_userspace_probe_location
*probe_location
= NULL
;
2009 struct lttng_buffer_view probe_location_view
;
2011 probe_location_view
= lttng_buffer_view_init(
2013 ext_comm
->userspace_probe_location_len
);
2016 * Create a temporary userspace probe location to
2017 * determine the size needed by a "flattened" version
2018 * of that same probe location.
2020 ret
= lttng_userspace_probe_location_create_from_buffer(
2021 &probe_location_view
, &probe_location
);
2023 ret
= -LTTNG_ERR_PROBE_LOCATION_INVAL
;
2027 ret
= lttng_userspace_probe_location_flatten(
2028 probe_location
, NULL
);
2029 lttng_userspace_probe_location_destroy(probe_location
);
2031 ret
= -LTTNG_ERR_PROBE_LOCATION_INVAL
;
2035 probe_storage_req
= ret
;
2036 comm_ext_at
+= ext_comm
->userspace_probe_location_len
;
2040 storage_req
+= sizeof(struct lttng_event_extended
);
2041 storage_req
+= ext_comm
->filter_len
;
2042 storage_req
+= ext_comm
->nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
;
2043 /* Padding to ensure the flat probe is aligned. */
2044 storage_req
= ALIGN_TO(storage_req
, sizeof(uint64_t));
2045 storage_req
+= probe_storage_req
;
2048 lttng_dynamic_buffer_init(&listing
);
2050 * We must ensure that "listing" is never resized so as to preserve
2051 * the validity of the flattened objects.
2053 ret
= lttng_dynamic_buffer_set_capacity(&listing
, storage_req
);
2055 ret
= -LTTNG_ERR_NOMEM
;
2059 ret
= lttng_dynamic_buffer_append(&listing
, reception_buffer
,
2060 nb_events
* sizeof(struct lttng_event
));
2062 ret
= -LTTNG_ERR_NOMEM
;
2063 goto free_dynamic_buffer
;
2066 comm_ext_at
= reception_buffer
+
2067 (nb_events
* sizeof(struct lttng_event
));
2068 for (i
= 0; i
< nb_events
; i
++) {
2069 struct lttng_event
*event
= (struct lttng_event
*)
2070 (listing
.data
+ (sizeof(struct lttng_event
) * i
));
2071 struct lttcomm_event_extended_header
*ext_comm
=
2072 (struct lttcomm_event_extended_header
*) comm_ext_at
;
2073 struct lttng_event_extended
*event_extended
=
2074 (struct lttng_event_extended
*)
2075 (listing
.data
+ listing
.size
);
2077 /* Insert struct lttng_event_extended. */
2078 ret
= lttng_dynamic_buffer_set_size(&listing
,
2079 listing
.size
+ sizeof(*event_extended
));
2081 ret
= -LTTNG_ERR_NOMEM
;
2082 goto free_dynamic_buffer
;
2084 event
->extended
.ptr
= event_extended
;
2086 comm_ext_at
+= sizeof(*ext_comm
);
2088 /* Insert filter expression. */
2089 if (ext_comm
->filter_len
) {
2090 event_extended
->filter_expression
= listing
.data
+
2092 ret
= lttng_dynamic_buffer_append(&listing
, comm_ext_at
,
2093 ext_comm
->filter_len
);
2095 ret
= -LTTNG_ERR_NOMEM
;
2096 goto free_dynamic_buffer
;
2098 comm_ext_at
+= ext_comm
->filter_len
;
2101 /* Insert exclusions. */
2102 if (ext_comm
->nb_exclusions
) {
2103 event_extended
->exclusions
.count
=
2104 ext_comm
->nb_exclusions
;
2105 event_extended
->exclusions
.strings
=
2106 listing
.data
+ listing
.size
;
2108 ret
= lttng_dynamic_buffer_append(&listing
,
2110 ext_comm
->nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
);
2112 ret
= -LTTNG_ERR_NOMEM
;
2114 comm_ext_at
+= ext_comm
->nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
;
2117 /* Insert padding to align to 64-bits. */
2118 ret
= lttng_dynamic_buffer_set_size(&listing
,
2119 ALIGN_TO(listing
.size
, sizeof(uint64_t)));
2121 ret
= -LTTNG_ERR_NOMEM
;
2122 goto free_dynamic_buffer
;
2125 /* Insert flattened userspace probe location. */
2126 if (ext_comm
->userspace_probe_location_len
) {
2127 struct lttng_userspace_probe_location
*probe_location
= NULL
;
2128 struct lttng_buffer_view probe_location_view
;
2130 probe_location_view
= lttng_buffer_view_init(
2132 ext_comm
->userspace_probe_location_len
);
2134 ret
= lttng_userspace_probe_location_create_from_buffer(
2135 &probe_location_view
, &probe_location
);
2137 ret
= -LTTNG_ERR_PROBE_LOCATION_INVAL
;
2138 goto free_dynamic_buffer
;
2141 event_extended
->probe_location
= (struct lttng_userspace_probe_location
*)
2142 (listing
.data
+ listing
.size
);
2143 ret
= lttng_userspace_probe_location_flatten(
2144 probe_location
, &listing
);
2145 lttng_userspace_probe_location_destroy(probe_location
);
2147 ret
= -LTTNG_ERR_PROBE_LOCATION_INVAL
;
2148 goto free_dynamic_buffer
;
2151 comm_ext_at
+= ext_comm
->userspace_probe_location_len
;
2155 /* Don't reset listing buffer as we return its content. */
2156 *events
= (struct lttng_event
*) listing
.data
;
2157 lttng_dynamic_buffer_init(&listing
);
2158 ret
= (int) nb_events
;
2159 free_dynamic_buffer
:
2160 lttng_dynamic_buffer_reset(&listing
);
2163 free(reception_buffer
);
2168 * Sets the tracing_group variable with name.
2169 * This function allocates memory pointed to by tracing_group.
2170 * On success, returns 0, on error, returns -1 (null name) or -ENOMEM.
2172 int lttng_set_tracing_group(const char *name
)
2175 return -LTTNG_ERR_INVALID
;
2178 if (asprintf(&tracing_group
, "%s", name
) < 0) {
2179 return -LTTNG_ERR_FATAL
;
2185 int lttng_calibrate(struct lttng_handle
*handle
,
2186 struct lttng_calibrate
*calibrate
)
2189 * This command was removed in LTTng 2.9.
2191 return -LTTNG_ERR_UND
;
2195 * Set default channel attributes.
2196 * If either or both of the arguments are null, attr content is zeroe'd.
2198 void lttng_channel_set_default_attr(struct lttng_domain
*domain
,
2199 struct lttng_channel_attr
*attr
)
2201 struct lttng_channel_extended
*extended
;
2204 if (attr
== NULL
|| domain
== NULL
) {
2208 extended
= (struct lttng_channel_extended
*) attr
->extended
.ptr
;
2209 memset(attr
, 0, sizeof(struct lttng_channel_attr
));
2211 /* Same for all domains. */
2212 attr
->overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
2213 attr
->tracefile_size
= DEFAULT_CHANNEL_TRACEFILE_SIZE
;
2214 attr
->tracefile_count
= DEFAULT_CHANNEL_TRACEFILE_COUNT
;
2216 switch (domain
->type
) {
2217 case LTTNG_DOMAIN_KERNEL
:
2218 attr
->switch_timer_interval
=
2219 DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER
;
2220 attr
->read_timer_interval
= DEFAULT_KERNEL_CHANNEL_READ_TIMER
;
2221 attr
->subbuf_size
= default_get_kernel_channel_subbuf_size();
2222 attr
->num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
2223 attr
->output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
2225 extended
->monitor_timer_interval
=
2226 DEFAULT_KERNEL_CHANNEL_MONITOR_TIMER
;
2227 extended
->blocking_timeout
=
2228 DEFAULT_KERNEL_CHANNEL_BLOCKING_TIMEOUT
;
2231 case LTTNG_DOMAIN_UST
:
2232 switch (domain
->buf_type
) {
2233 case LTTNG_BUFFER_PER_UID
:
2234 attr
->subbuf_size
= default_get_ust_uid_channel_subbuf_size();
2235 attr
->num_subbuf
= DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM
;
2236 attr
->output
= DEFAULT_UST_UID_CHANNEL_OUTPUT
;
2237 attr
->switch_timer_interval
=
2238 DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER
;
2239 attr
->read_timer_interval
=
2240 DEFAULT_UST_UID_CHANNEL_READ_TIMER
;
2242 extended
->monitor_timer_interval
=
2243 DEFAULT_UST_UID_CHANNEL_MONITOR_TIMER
;
2244 extended
->blocking_timeout
=
2245 DEFAULT_UST_UID_CHANNEL_BLOCKING_TIMEOUT
;
2248 case LTTNG_BUFFER_PER_PID
:
2250 attr
->subbuf_size
= default_get_ust_pid_channel_subbuf_size();
2251 attr
->num_subbuf
= DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM
;
2252 attr
->output
= DEFAULT_UST_PID_CHANNEL_OUTPUT
;
2253 attr
->switch_timer_interval
=
2254 DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER
;
2255 attr
->read_timer_interval
=
2256 DEFAULT_UST_PID_CHANNEL_READ_TIMER
;
2258 extended
->monitor_timer_interval
=
2259 DEFAULT_UST_PID_CHANNEL_MONITOR_TIMER
;
2260 extended
->blocking_timeout
=
2261 DEFAULT_UST_PID_CHANNEL_BLOCKING_TIMEOUT
;
2266 /* Default behavior: leave set to 0. */
2270 attr
->extended
.ptr
= extended
;
2273 int lttng_channel_get_discarded_event_count(struct lttng_channel
*channel
,
2274 uint64_t *discarded_events
)
2277 struct lttng_channel_extended
*chan_ext
;
2279 if (!channel
|| !discarded_events
) {
2280 ret
= -LTTNG_ERR_INVALID
;
2284 chan_ext
= channel
->attr
.extended
.ptr
;
2287 * This can happen since the lttng_channel structure is
2288 * used for other tasks where this pointer is never set.
2290 *discarded_events
= 0;
2294 *discarded_events
= chan_ext
->discarded_events
;
2299 int lttng_channel_get_lost_packet_count(struct lttng_channel
*channel
,
2300 uint64_t *lost_packets
)
2303 struct lttng_channel_extended
*chan_ext
;
2305 if (!channel
|| !lost_packets
) {
2306 ret
= -LTTNG_ERR_INVALID
;
2310 chan_ext
= channel
->attr
.extended
.ptr
;
2313 * This can happen since the lttng_channel structure is
2314 * used for other tasks where this pointer is never set.
2320 *lost_packets
= chan_ext
->lost_packets
;
2325 int lttng_channel_get_monitor_timer_interval(struct lttng_channel
*chan
,
2326 uint64_t *monitor_timer_interval
)
2330 if (!chan
|| !monitor_timer_interval
) {
2331 ret
= -LTTNG_ERR_INVALID
;
2335 if (!chan
->attr
.extended
.ptr
) {
2336 ret
= -LTTNG_ERR_INVALID
;
2340 *monitor_timer_interval
= ((struct lttng_channel_extended
*)
2341 chan
->attr
.extended
.ptr
)->monitor_timer_interval
;
2346 int lttng_channel_set_monitor_timer_interval(struct lttng_channel
*chan
,
2347 uint64_t monitor_timer_interval
)
2351 if (!chan
|| !chan
->attr
.extended
.ptr
) {
2352 ret
= -LTTNG_ERR_INVALID
;
2356 ((struct lttng_channel_extended
*)
2357 chan
->attr
.extended
.ptr
)->monitor_timer_interval
=
2358 monitor_timer_interval
;
2363 int lttng_channel_get_blocking_timeout(struct lttng_channel
*chan
,
2364 int64_t *blocking_timeout
)
2368 if (!chan
|| !blocking_timeout
) {
2369 ret
= -LTTNG_ERR_INVALID
;
2373 if (!chan
->attr
.extended
.ptr
) {
2374 ret
= -LTTNG_ERR_INVALID
;
2378 *blocking_timeout
= ((struct lttng_channel_extended
*)
2379 chan
->attr
.extended
.ptr
)->blocking_timeout
;
2384 int lttng_channel_set_blocking_timeout(struct lttng_channel
*chan
,
2385 int64_t blocking_timeout
)
2388 int64_t msec_timeout
;
2390 if (!chan
|| !chan
->attr
.extended
.ptr
) {
2391 ret
= -LTTNG_ERR_INVALID
;
2395 if (blocking_timeout
< 0 && blocking_timeout
!= -1) {
2396 ret
= -LTTNG_ERR_INVALID
;
2401 * LTTng-ust's use of poll() to implement this timeout mechanism forces
2402 * us to accept a narrower range of values (msecs expressed as a signed
2405 msec_timeout
= blocking_timeout
/ 1000;
2406 if (msec_timeout
!= (int32_t) msec_timeout
) {
2407 ret
= -LTTNG_ERR_INVALID
;
2411 ((struct lttng_channel_extended
*)
2412 chan
->attr
.extended
.ptr
)->blocking_timeout
=
2419 * Check if session daemon is alive.
2421 * Return 1 if alive or 0 if not.
2422 * On error returns a negative value.
2424 int lttng_session_daemon_alive(void)
2428 ret
= set_session_daemon_path();
2434 if (*sessiond_sock_path
== '\0') {
2436 * No socket path set. Weird error which means the constructor
2442 ret
= try_connect_sessiond(sessiond_sock_path
);
2453 * Set URL for a consumer for a session and domain.
2455 * Return 0 on success, else a negative value.
2457 int lttng_set_consumer_url(struct lttng_handle
*handle
,
2458 const char *control_url
, const char *data_url
)
2462 struct lttcomm_session_msg lsm
;
2463 struct lttng_uri
*uris
= NULL
;
2465 if (handle
== NULL
|| (control_url
== NULL
&& data_url
== NULL
)) {
2466 return -LTTNG_ERR_INVALID
;
2469 memset(&lsm
, 0, sizeof(lsm
));
2471 lsm
.cmd_type
= LTTNG_SET_CONSUMER_URI
;
2473 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
2474 sizeof(lsm
.session
.name
));
2475 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
2477 size
= uri_parse_str_urls(control_url
, data_url
, &uris
);
2479 return -LTTNG_ERR_INVALID
;
2482 lsm
.u
.uri
.size
= size
;
2484 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
2485 sizeof(struct lttng_uri
) * size
, NULL
);
2494 int lttng_enable_consumer(struct lttng_handle
*handle
)
2502 int lttng_disable_consumer(struct lttng_handle
*handle
)
2508 * This is an extension of create session that is ONLY and SHOULD only be used
2509 * by the lttng command line program. It exists to avoid using URI parsing in
2512 * We need the date and time for the trace path subdirectory for the case where
2513 * the user does NOT define one using either -o or -U. Using the normal
2514 * lttng_create_session API call, we have no clue on the session daemon side if
2515 * the URL was generated automatically by the client or define by the user.
2517 * So this function "wrapper" is hidden from the public API, takes the datetime
2518 * string and appends it if necessary to the URI subdirectory before sending it
2519 * to the session daemon.
2521 * With this extra function, the lttng_create_session call behavior is not
2522 * changed and the timestamp is appended to the URI on the session daemon side
2525 int _lttng_create_session_ext(const char *name
, const char *url
,
2526 const char *datetime
)
2530 struct lttcomm_session_msg lsm
;
2531 struct lttng_uri
*uris
= NULL
;
2533 if (name
== NULL
|| datetime
== NULL
) {
2534 return -LTTNG_ERR_INVALID
;
2537 memset(&lsm
, 0, sizeof(lsm
));
2539 lsm
.cmd_type
= LTTNG_CREATE_SESSION
;
2540 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
2542 /* There should never be a data URL. */
2543 size
= uri_parse_str_urls(url
, NULL
, &uris
);
2545 ret
= -LTTNG_ERR_INVALID
;
2549 lsm
.u
.uri
.size
= size
;
2551 if (size
> 0 && uris
[0].dtype
!= LTTNG_DST_PATH
&& strlen(uris
[0].subdir
) == 0) {
2552 /* Don't append datetime if the name was automatically created. */
2553 if (strncmp(name
, DEFAULT_SESSION_NAME
"-",
2554 strlen(DEFAULT_SESSION_NAME
) + 1)) {
2555 ret
= snprintf(uris
[0].subdir
, sizeof(uris
[0].subdir
), "%s-%s",
2558 ret
= snprintf(uris
[0].subdir
, sizeof(uris
[0].subdir
), "%s", name
);
2561 PERROR("snprintf uri subdir");
2562 ret
= -LTTNG_ERR_FATAL
;
2567 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
2568 sizeof(struct lttng_uri
) * size
, NULL
);
2576 * For a given session name, this call checks if the data is ready to be read
2577 * or is still being extracted by the consumer(s) hence not ready to be used by
2580 int lttng_data_pending(const char *session_name
)
2583 struct lttcomm_session_msg lsm
;
2584 uint8_t *pending
= NULL
;
2586 if (session_name
== NULL
) {
2587 return -LTTNG_ERR_INVALID
;
2590 memset(&lsm
, 0, sizeof(lsm
));
2591 lsm
.cmd_type
= LTTNG_DATA_PENDING
;
2593 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
2594 sizeof(lsm
.session
.name
));
2596 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) &pending
);
2599 } else if (ret
!= 1) {
2600 /* Unexpected payload size */
2601 ret
= -LTTNG_ERR_INVALID
;
2605 ret
= (int) *pending
;
2612 * Create a session exclusively used for snapshot.
2614 * Returns LTTNG_OK on success or a negative error code.
2616 int lttng_create_session_snapshot(const char *name
, const char *snapshot_url
)
2620 struct lttcomm_session_msg lsm
;
2621 struct lttng_uri
*uris
= NULL
;
2624 return -LTTNG_ERR_INVALID
;
2627 memset(&lsm
, 0, sizeof(lsm
));
2629 lsm
.cmd_type
= LTTNG_CREATE_SESSION_SNAPSHOT
;
2630 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
2632 size
= uri_parse_str_urls(snapshot_url
, NULL
, &uris
);
2634 return -LTTNG_ERR_INVALID
;
2637 lsm
.u
.uri
.size
= size
;
2640 * If the user does not specify a custom subdir, use the session name.
2642 if (size
> 0 && uris
[0].dtype
!= LTTNG_DST_PATH
&& strlen(uris
[0].subdir
) == 0) {
2643 ret
= snprintf(uris
[0].subdir
, sizeof(uris
[0].subdir
), "%s", name
);
2645 PERROR("snprintf uri subdir");
2646 ret
= -LTTNG_ERR_FATAL
;
2651 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
2652 sizeof(struct lttng_uri
) * size
, NULL
);
2660 * Create a session exclusively used for live.
2662 * Returns LTTNG_OK on success or a negative error code.
2664 int lttng_create_session_live(const char *name
, const char *url
,
2665 unsigned int timer_interval
)
2669 struct lttcomm_session_msg lsm
;
2670 struct lttng_uri
*uris
= NULL
;
2672 if (name
== NULL
|| timer_interval
== 0) {
2673 return -LTTNG_ERR_INVALID
;
2676 memset(&lsm
, 0, sizeof(lsm
));
2678 lsm
.cmd_type
= LTTNG_CREATE_SESSION_LIVE
;
2679 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
2682 size
= uri_parse_str_urls(url
, NULL
, &uris
);
2684 ret
= -LTTNG_ERR_INVALID
;
2688 /* file:// is not accepted for live session. */
2689 if (uris
[0].dtype
== LTTNG_DST_PATH
) {
2690 ret
= -LTTNG_ERR_INVALID
;
2697 lsm
.u
.session_live
.nb_uri
= size
;
2698 lsm
.u
.session_live
.timer_interval
= timer_interval
;
2700 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
2701 sizeof(struct lttng_uri
) * size
, NULL
);
2709 * List PIDs in the tracker.
2711 * enabled is set to whether the PID tracker is enabled.
2712 * pids is set to an allocated array of PIDs currently tracked. On
2713 * success, pids must be freed by the caller.
2714 * nr_pids is set to the number of entries contained by the pids array.
2716 * Returns 0 on success, else a negative LTTng error code.
2718 int lttng_list_tracker_pids(struct lttng_handle
*handle
,
2719 int *_enabled
, int32_t **_pids
, size_t *_nr_pids
)
2723 struct lttcomm_session_msg lsm
;
2725 int32_t *pids
= NULL
;
2727 if (handle
== NULL
) {
2728 return -LTTNG_ERR_INVALID
;
2731 memset(&lsm
, 0, sizeof(lsm
));
2732 lsm
.cmd_type
= LTTNG_LIST_TRACKER_PIDS
;
2733 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
2734 sizeof(lsm
.session
.name
));
2735 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
2737 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) &pids
);
2741 nr_pids
= ret
/ sizeof(int32_t);
2742 if (nr_pids
== 1 && pids
[0] == -1) {
2748 *_enabled
= enabled
;
2750 *_nr_pids
= nr_pids
;
2755 * Regenerate the metadata for a session.
2756 * Return 0 on success, a negative error code on error.
2758 int lttng_regenerate_metadata(const char *session_name
)
2761 struct lttcomm_session_msg lsm
;
2763 if (!session_name
) {
2764 ret
= -LTTNG_ERR_INVALID
;
2768 memset(&lsm
, 0, sizeof(lsm
));
2769 lsm
.cmd_type
= LTTNG_REGENERATE_METADATA
;
2771 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
2772 sizeof(lsm
.session
.name
));
2774 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
2785 * Deprecated, replaced by lttng_regenerate_metadata.
2787 int lttng_metadata_regenerate(const char *session_name
)
2789 return lttng_regenerate_metadata(session_name
);
2793 * Regenerate the statedump of a session.
2794 * Return 0 on success, a negative error code on error.
2796 int lttng_regenerate_statedump(const char *session_name
)
2799 struct lttcomm_session_msg lsm
;
2801 if (!session_name
) {
2802 ret
= -LTTNG_ERR_INVALID
;
2806 memset(&lsm
, 0, sizeof(lsm
));
2807 lsm
.cmd_type
= LTTNG_REGENERATE_STATEDUMP
;
2809 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
2810 sizeof(lsm
.session
.name
));
2812 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
2822 int lttng_register_trigger(struct lttng_trigger
*trigger
)
2825 struct lttcomm_session_msg lsm
;
2826 struct lttng_dynamic_buffer buffer
;
2828 lttng_dynamic_buffer_init(&buffer
);
2830 ret
= -LTTNG_ERR_INVALID
;
2834 if (!lttng_trigger_validate(trigger
)) {
2835 ret
= -LTTNG_ERR_INVALID_TRIGGER
;
2839 ret
= lttng_trigger_serialize(trigger
, &buffer
);
2841 ret
= -LTTNG_ERR_UNK
;
2845 memset(&lsm
, 0, sizeof(lsm
));
2846 lsm
.cmd_type
= LTTNG_REGISTER_TRIGGER
;
2847 lsm
.u
.trigger
.length
= (uint32_t) buffer
.size
;
2848 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, buffer
.data
,
2851 lttng_dynamic_buffer_reset(&buffer
);
2855 int lttng_unregister_trigger(struct lttng_trigger
*trigger
)
2858 struct lttcomm_session_msg lsm
;
2859 struct lttng_dynamic_buffer buffer
;
2861 lttng_dynamic_buffer_init(&buffer
);
2863 ret
= -LTTNG_ERR_INVALID
;
2867 if (!lttng_trigger_validate(trigger
)) {
2868 ret
= -LTTNG_ERR_INVALID_TRIGGER
;
2872 ret
= lttng_trigger_serialize(trigger
, &buffer
);
2874 ret
= -LTTNG_ERR_UNK
;
2878 memset(&lsm
, 0, sizeof(lsm
));
2879 lsm
.cmd_type
= LTTNG_UNREGISTER_TRIGGER
;
2880 lsm
.u
.trigger
.length
= (uint32_t) buffer
.size
;
2881 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, buffer
.data
,
2884 lttng_dynamic_buffer_reset(&buffer
);
2888 int lttng_session_get_current_archive_location(const char *session_name
,
2891 struct lttcomm_session_msg lsm
;
2892 struct lttng_session_get_current_output_return
*output_return
= NULL
;
2896 memset(&lsm
, 0, sizeof(lsm
));
2897 lsm
.cmd_type
= LTTNG_SESSION_GET_CURRENT_OUTPUT
;
2898 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
2899 sizeof(lsm
.session
.name
));
2901 ret
= -LTTNG_ERR_INVALID
;
2905 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) &output_return
);
2911 path_len
= lttng_strnlen(output_return
->path
,
2912 sizeof(output_return
->path
));
2913 if (path_len
== 0 || path_len
== sizeof(output_return
->path
)) {
2914 ret
= -LTTNG_ERR_NO_SESSION_OUTPUT
;
2918 *chunk_path
= zmalloc(path_len
+ 1);
2923 memcpy(*chunk_path
, output_return
->path
, path_len
);
2928 free(output_return
);
2935 static void __attribute__((constructor
)) init(void)
2937 /* Set default session group */
2938 lttng_set_tracing_group(DEFAULT_TRACING_GROUP
);
2944 static void __attribute__((destructor
)) lttng_ctl_exit(void)
2946 free(tracing_group
);