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/defaults.h>
34 #include <common/sessiond-comm/sessiond-comm.h>
35 #include <common/uri.h>
36 #include <common/utils.h>
37 #include <common/dynamic-buffer.h>
38 #include <lttng/lttng.h>
39 #include <lttng/health-internal.h>
40 #include <lttng/trigger/trigger-internal.h>
41 #include <lttng/endpoint.h>
42 #include <lttng/channel-internal.h>
43 #include <lttng/event-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); \
66 /* Socket to session daemon for communication */
67 static int sessiond_socket
;
68 static char sessiond_sock_path
[PATH_MAX
];
71 static char *tracing_group
;
77 * Those two variables are used by error.h to silent or control the verbosity of
78 * error message. They are global to the library so application linking with it
79 * are able to compile correctly and also control verbosity of the library.
82 int lttng_opt_verbose
;
86 * Copy string from src to dst and enforce null terminated byte.
89 void lttng_ctl_copy_string(char *dst
, const char *src
, size_t len
)
92 strncpy(dst
, src
, len
);
93 /* Enforce the NULL terminated byte */
101 * Copy domain to lttcomm_session_msg domain.
103 * If domain is unknown, default domain will be the kernel.
106 void lttng_ctl_copy_lttng_domain(struct lttng_domain
*dst
,
107 struct lttng_domain
*src
)
111 case LTTNG_DOMAIN_KERNEL
:
112 case LTTNG_DOMAIN_UST
:
113 case LTTNG_DOMAIN_JUL
:
114 case LTTNG_DOMAIN_LOG4J
:
115 case LTTNG_DOMAIN_PYTHON
:
116 memcpy(dst
, src
, sizeof(struct lttng_domain
));
119 memset(dst
, 0, sizeof(struct lttng_domain
));
126 * Send lttcomm_session_msg to the session daemon.
128 * On success, returns the number of bytes sent (>=0)
129 * On error, returns -1
131 static int send_session_msg(struct lttcomm_session_msg
*lsm
)
136 ret
= -LTTNG_ERR_NO_SESSIOND
;
140 DBG("LSM cmd type : %d", lsm
->cmd_type
);
142 ret
= lttcomm_send_creds_unix_sock(sessiond_socket
, lsm
,
143 sizeof(struct lttcomm_session_msg
));
145 ret
= -LTTNG_ERR_FATAL
;
153 * Send var len data to the session daemon.
155 * On success, returns the number of bytes sent (>=0)
156 * On error, returns -1
158 static int send_session_varlen(const void *data
, size_t len
)
163 ret
= -LTTNG_ERR_NO_SESSIOND
;
172 ret
= lttcomm_send_unix_sock(sessiond_socket
, data
, len
);
174 ret
= -LTTNG_ERR_FATAL
;
182 * Send file descriptors to the session daemon.
184 * On success, returns the number of bytes sent (>=0)
185 * On error, returns -1
187 static int send_session_fds(const int *fds
, size_t nb_fd
)
192 ret
= -LTTNG_ERR_NO_SESSIOND
;
196 if (!fds
|| !nb_fd
) {
201 ret
= lttcomm_send_fds_unix_sock(sessiond_socket
, fds
, nb_fd
);
203 ret
= -LTTNG_ERR_FATAL
;
211 * Receive data from the sessiond socket.
213 * On success, returns the number of bytes received (>=0)
214 * On error, returns -1 (recvmsg() error) or -ENOTCONN
216 static int recv_data_sessiond(void *buf
, size_t len
)
221 ret
= -LTTNG_ERR_NO_SESSIOND
;
225 ret
= lttcomm_recv_unix_sock(sessiond_socket
, buf
, len
);
227 ret
= -LTTNG_ERR_FATAL
;
235 * Check if we are in the specified group.
237 * If yes return 1, else return -1.
240 int lttng_check_tracing_group(void)
242 struct group
*grp_tracing
; /* no free(). See getgrnam(3) */
244 int grp_list_size
, grp_id
, i
;
246 const char *grp_name
= tracing_group
;
248 /* Get GID of group 'tracing' */
249 grp_tracing
= getgrnam(grp_name
);
251 /* If grp_tracing is NULL, the group does not exist. */
255 /* Get number of supplementary group IDs */
256 grp_list_size
= getgroups(0, NULL
);
257 if (grp_list_size
< 0) {
262 /* Alloc group list of the right size */
263 grp_list
= zmalloc(grp_list_size
* sizeof(gid_t
));
268 grp_id
= getgroups(grp_list_size
, grp_list
);
274 for (i
= 0; i
< grp_list_size
; i
++) {
275 if (grp_list
[i
] == grp_tracing
->gr_gid
) {
289 * Try connect to session daemon with sock_path.
291 * Return 0 on success, else -1
293 static int try_connect_sessiond(const char *sock_path
)
297 /* If socket exist, we check if the daemon listens for connect. */
298 ret
= access(sock_path
, F_OK
);
304 ret
= lttcomm_connect_unix_sock(sock_path
);
310 ret
= lttcomm_close_unix_sock(ret
);
312 PERROR("lttcomm_close_unix_sock");
322 * Set sessiond socket path by putting it in the global sessiond_sock_path
325 * Returns 0 on success, negative value on failure (the sessiond socket path
326 * is somehow too long or ENOMEM).
328 static int set_session_daemon_path(void)
330 int in_tgroup
= 0; /* In tracing group. */
336 /* Are we in the tracing group ? */
337 in_tgroup
= lttng_check_tracing_group();
340 if ((uid
== 0) || in_tgroup
) {
341 lttng_ctl_copy_string(sessiond_sock_path
,
342 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
, sizeof(sessiond_sock_path
));
350 ret
= try_connect_sessiond(sessiond_sock_path
);
354 /* Global session daemon not available... */
356 /* ...or not in tracing group (and not root), default */
359 * With GNU C < 2.1, snprintf returns -1 if the target buffer
361 * With GNU C >= 2.1, snprintf returns the required size
362 * (excluding closing null)
364 ret
= snprintf(sessiond_sock_path
, sizeof(sessiond_sock_path
),
365 DEFAULT_HOME_CLIENT_UNIX_SOCK
, utils_get_home_dir());
366 if ((ret
< 0) || (ret
>= sizeof(sessiond_sock_path
))) {
378 * Connect to the LTTng session daemon.
380 * On success, return 0. On error, return -1.
382 static int connect_sessiond(void)
386 /* Don't try to connect if already connected. */
391 ret
= set_session_daemon_path();
396 /* Connect to the sesssion daemon. */
397 ret
= lttcomm_connect_unix_sock(sessiond_sock_path
);
402 sessiond_socket
= ret
;
412 * Clean disconnect from the session daemon.
414 * On success, return 0. On error, return -1.
416 static int disconnect_sessiond(void)
421 ret
= lttcomm_close_unix_sock(sessiond_socket
);
429 static int recv_sessiond_optional_data(size_t len
, void **user_buf
,
437 ret
= -LTTNG_ERR_INVALID
;
447 ret
= recv_data_sessiond(buf
, len
);
453 ret
= -LTTNG_ERR_INVALID
;
457 /* Move ownership of command header buffer to user. */
462 /* No command header. */
478 * Ask the session daemon a specific command and put the data into buf.
479 * Takes extra var. len. data and file descriptors as input to send to the
482 * Return size of data (only payload, not header) or a negative error code.
485 int lttng_ctl_ask_sessiond_fds_varlen(struct lttcomm_session_msg
*lsm
,
486 const int *fds
, size_t nb_fd
, const void *vardata
,
487 size_t vardata_len
, void **user_payload_buf
,
488 void **user_cmd_header_buf
, size_t *user_cmd_header_len
)
492 struct lttcomm_lttng_msg llm
;
494 ret
= connect_sessiond();
496 ret
= -LTTNG_ERR_NO_SESSIOND
;
500 /* Send command to session daemon */
501 ret
= send_session_msg(lsm
);
503 /* Ret value is a valid lttng error code. */
506 /* Send var len data */
507 ret
= send_session_varlen(vardata
, vardata_len
);
509 /* Ret value is a valid lttng error code. */
514 ret
= send_session_fds(fds
, nb_fd
);
516 /* Ret value is a valid lttng error code. */
520 /* Get header from data transmission */
521 ret
= recv_data_sessiond(&llm
, sizeof(llm
));
523 /* Ret value is a valid lttng error code. */
527 /* Check error code if OK */
528 if (llm
.ret_code
!= LTTNG_OK
) {
533 /* Get command header from data transmission */
534 ret
= recv_sessiond_optional_data(llm
.cmd_header_size
,
535 user_cmd_header_buf
, user_cmd_header_len
);
540 /* Get payload from data transmission */
541 ret
= recv_sessiond_optional_data(llm
.data_size
, user_payload_buf
,
550 disconnect_sessiond();
555 * Create lttng handle and return pointer.
557 * The returned pointer will be NULL in case of malloc() error.
559 struct lttng_handle
*lttng_create_handle(const char *session_name
,
560 struct lttng_domain
*domain
)
562 struct lttng_handle
*handle
= NULL
;
564 handle
= zmalloc(sizeof(struct lttng_handle
));
565 if (handle
== NULL
) {
566 PERROR("malloc handle");
570 /* Copy session name */
571 lttng_ctl_copy_string(handle
->session_name
, session_name
,
572 sizeof(handle
->session_name
));
574 /* Copy lttng domain or leave initialized to 0. */
576 lttng_ctl_copy_lttng_domain(&handle
->domain
, domain
);
584 * Destroy handle by free(3) the pointer.
586 void lttng_destroy_handle(struct lttng_handle
*handle
)
592 * Register an outside consumer.
594 * Returns size of returned session payload data or a negative error code.
596 int lttng_register_consumer(struct lttng_handle
*handle
,
597 const char *socket_path
)
599 struct lttcomm_session_msg lsm
;
601 if (handle
== NULL
|| socket_path
== NULL
) {
602 return -LTTNG_ERR_INVALID
;
605 memset(&lsm
, 0, sizeof(lsm
));
606 lsm
.cmd_type
= LTTNG_REGISTER_CONSUMER
;
607 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
608 sizeof(lsm
.session
.name
));
609 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
611 lttng_ctl_copy_string(lsm
.u
.reg
.path
, socket_path
,
612 sizeof(lsm
.u
.reg
.path
));
614 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
618 * Start tracing for all traces of the session.
620 * Returns size of returned session payload data or a negative error code.
622 int lttng_start_tracing(const char *session_name
)
624 struct lttcomm_session_msg lsm
;
626 if (session_name
== NULL
) {
627 return -LTTNG_ERR_INVALID
;
630 memset(&lsm
, 0, sizeof(lsm
));
631 lsm
.cmd_type
= LTTNG_START_TRACE
;
633 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
634 sizeof(lsm
.session
.name
));
636 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
640 * Stop tracing for all traces of the session.
642 static int _lttng_stop_tracing(const char *session_name
, int wait
)
645 struct lttcomm_session_msg lsm
;
647 if (session_name
== NULL
) {
648 return -LTTNG_ERR_INVALID
;
651 memset(&lsm
, 0, sizeof(lsm
));
652 lsm
.cmd_type
= LTTNG_STOP_TRACE
;
654 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
655 sizeof(lsm
.session
.name
));
657 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
658 if (ret
< 0 && ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
666 /* Check for data availability */
668 data_ret
= lttng_data_pending(session_name
);
670 /* Return the data available call error. */
676 * Data sleep time before retrying (in usec). Don't sleep if the
677 * call returned value indicates availability.
680 usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME
);
682 } while (data_ret
!= 0);
690 * Stop tracing and wait for data availability.
692 int lttng_stop_tracing(const char *session_name
)
694 return _lttng_stop_tracing(session_name
, 1);
698 * Stop tracing but _don't_ wait for data availability.
700 int lttng_stop_tracing_no_wait(const char *session_name
)
702 return _lttng_stop_tracing(session_name
, 0);
706 * Add context to a channel.
708 * If the given channel is NULL, add the contexts to all channels.
709 * The event_name param is ignored.
711 * Returns the size of the returned payload data or a negative error code.
713 int lttng_add_context(struct lttng_handle
*handle
,
714 struct lttng_event_context
*ctx
, const char *event_name
,
715 const char *channel_name
)
720 struct lttcomm_session_msg lsm
;
722 /* Safety check. Both are mandatory. */
723 if (handle
== NULL
|| ctx
== NULL
) {
724 ret
= -LTTNG_ERR_INVALID
;
728 memset(&lsm
, 0, sizeof(lsm
));
729 lsm
.cmd_type
= LTTNG_ADD_CONTEXT
;
731 /* If no channel name, send empty string. */
732 if (channel_name
== NULL
) {
733 lttng_ctl_copy_string(lsm
.u
.context
.channel_name
, "",
734 sizeof(lsm
.u
.context
.channel_name
));
736 lttng_ctl_copy_string(lsm
.u
.context
.channel_name
, channel_name
,
737 sizeof(lsm
.u
.context
.channel_name
));
740 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
741 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
742 sizeof(lsm
.session
.name
));
744 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
745 size_t provider_len
, ctx_len
;
746 const char *provider_name
= ctx
->u
.app_ctx
.provider_name
;
747 const char *ctx_name
= ctx
->u
.app_ctx
.ctx_name
;
749 if (!provider_name
|| !ctx_name
) {
750 ret
= -LTTNG_ERR_INVALID
;
754 provider_len
= strlen(provider_name
);
755 if (provider_len
== 0) {
756 ret
= -LTTNG_ERR_INVALID
;
759 lsm
.u
.context
.provider_name_len
= provider_len
;
761 ctx_len
= strlen(ctx_name
);
763 ret
= -LTTNG_ERR_INVALID
;
766 lsm
.u
.context
.context_name_len
= ctx_len
;
768 len
= provider_len
+ ctx_len
;
771 ret
= -LTTNG_ERR_NOMEM
;
775 memcpy(buf
, provider_name
, provider_len
);
776 memcpy(buf
+ provider_len
, ctx_name
, ctx_len
);
778 memcpy(&lsm
.u
.context
.ctx
, ctx
, sizeof(struct lttng_event_context
));
780 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
782 * Don't leak application addresses to the sessiond.
783 * This is only necessary when ctx is for an app ctx otherwise
784 * the values inside the union (type & config) are overwritten.
786 lsm
.u
.context
.ctx
.u
.app_ctx
.provider_name
= NULL
;
787 lsm
.u
.context
.ctx
.u
.app_ctx
.ctx_name
= NULL
;
790 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, buf
, len
, NULL
);
797 * Enable event(s) for a channel.
799 * If no event name is specified, all events are enabled.
800 * If no channel name is specified, the default 'channel0' is used.
802 * Returns size of returned session payload data or a negative error code.
804 int lttng_enable_event(struct lttng_handle
*handle
,
805 struct lttng_event
*ev
, const char *channel_name
)
807 return lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
812 * Create or enable an event with a filter expression.
814 * Return negative error value on error.
815 * Return size of returned session payload data if OK.
817 int lttng_enable_event_with_filter(struct lttng_handle
*handle
,
818 struct lttng_event
*event
, const char *channel_name
,
819 const char *filter_expression
)
821 return lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
822 filter_expression
, 0, NULL
);
826 * Depending on the event, return a newly allocated agent filter expression or
827 * NULL if not applicable.
829 * An event with NO loglevel and the name is * will return NULL.
831 static char *set_agent_filter(const char *filter
, struct lttng_event
*ev
)
834 char *agent_filter
= NULL
;
838 /* Don't add filter for the '*' event. */
839 if (strcmp(ev
->name
, "*") != 0) {
841 err
= asprintf(&agent_filter
, "(%s) && (logger_name == \"%s\")", filter
,
844 err
= asprintf(&agent_filter
, "logger_name == \"%s\"", ev
->name
);
852 /* Add loglevel filtering if any for the JUL domain. */
853 if (ev
->loglevel_type
!= LTTNG_EVENT_LOGLEVEL_ALL
) {
856 if (ev
->loglevel_type
== LTTNG_EVENT_LOGLEVEL_RANGE
) {
862 if (filter
|| agent_filter
) {
865 err
= asprintf(&new_filter
, "(%s) && (int_loglevel %s %d)",
866 agent_filter
? agent_filter
: filter
, op
,
871 agent_filter
= new_filter
;
873 err
= asprintf(&agent_filter
, "int_loglevel %s %d", op
,
889 * Generate the filter bytecode from a given filter expression string. Put the
890 * newly allocated parser context in ctxp and populate the lsm object with the
893 * Return 0 on success else a LTTNG_ERR_* code and ctxp is untouched.
895 static int generate_filter(char *filter_expression
,
896 struct lttcomm_session_msg
*lsm
, struct filter_parser_ctx
**ctxp
)
899 struct filter_parser_ctx
*ctx
= NULL
;
902 assert(filter_expression
);
907 * Casting const to non-const, as the underlying function will use it in
910 fmem
= lttng_fmemopen((void *) filter_expression
,
911 strlen(filter_expression
), "r");
913 fprintf(stderr
, "Error opening memory as stream\n");
914 ret
= -LTTNG_ERR_FILTER_NOMEM
;
917 ctx
= filter_parser_ctx_alloc(fmem
);
919 fprintf(stderr
, "Error allocating parser\n");
920 ret
= -LTTNG_ERR_FILTER_NOMEM
;
921 goto filter_alloc_error
;
923 ret
= filter_parser_ctx_append_ast(ctx
);
925 fprintf(stderr
, "Parse error\n");
926 ret
= -LTTNG_ERR_FILTER_INVAL
;
930 ret
= filter_visitor_print_xml(ctx
, stdout
, 0);
933 fprintf(stderr
, "XML print error\n");
934 ret
= -LTTNG_ERR_FILTER_INVAL
;
939 dbg_printf("Generating IR... ");
941 ret
= filter_visitor_ir_generate(ctx
);
943 fprintf(stderr
, "Generate IR error\n");
944 ret
= -LTTNG_ERR_FILTER_INVAL
;
947 dbg_printf("done\n");
949 dbg_printf("Validating IR... ");
951 ret
= filter_visitor_ir_check_binary_op_nesting(ctx
);
953 ret
= -LTTNG_ERR_FILTER_INVAL
;
957 /* Normalize globbing patterns in the expression. */
958 ret
= filter_visitor_ir_normalize_glob_patterns(ctx
);
960 ret
= -LTTNG_ERR_FILTER_INVAL
;
964 /* Validate strings used as literals in the expression. */
965 ret
= filter_visitor_ir_validate_string(ctx
);
967 ret
= -LTTNG_ERR_FILTER_INVAL
;
971 /* Validate globbing patterns in the expression. */
972 ret
= filter_visitor_ir_validate_globbing(ctx
);
974 ret
= -LTTNG_ERR_FILTER_INVAL
;
978 dbg_printf("done\n");
980 dbg_printf("Generating bytecode... ");
982 ret
= filter_visitor_bytecode_generate(ctx
);
984 fprintf(stderr
, "Generate bytecode error\n");
985 ret
= -LTTNG_ERR_FILTER_INVAL
;
988 dbg_printf("done\n");
989 dbg_printf("Size of bytecode generated: %u bytes.\n",
990 bytecode_get_len(&ctx
->bytecode
->b
));
992 lsm
->u
.enable
.bytecode_len
= sizeof(ctx
->bytecode
->b
)
993 + bytecode_get_len(&ctx
->bytecode
->b
);
994 lsm
->u
.enable
.expression_len
= strlen(filter_expression
) + 1;
996 /* No need to keep the memory stream. */
997 if (fclose(fmem
) != 0) {
1005 filter_ir_free(ctx
);
1006 filter_parser_ctx_free(ctx
);
1008 if (fclose(fmem
) != 0) {
1016 * Enable event(s) for a channel, possibly with exclusions and a filter.
1017 * If no event name is specified, all events are enabled.
1018 * If no channel name is specified, the default name is used.
1019 * If filter expression is not NULL, the filter is set for the event.
1020 * If exclusion count is not zero, the exclusions are set for the event.
1021 * Returns size of returned session payload data or a negative error code.
1023 int lttng_enable_event_with_exclusions(struct lttng_handle
*handle
,
1024 struct lttng_event
*ev
, const char *channel_name
,
1025 const char *original_filter_expression
,
1026 int exclusion_count
, char **exclusion_list
)
1028 struct lttcomm_session_msg lsm
;
1031 unsigned int free_filter_expression
= 0;
1032 struct filter_parser_ctx
*ctx
= NULL
;
1034 * Cast as non-const since we may replace the filter expression
1035 * by a dynamically allocated string. Otherwise, the original
1036 * string is not modified.
1038 char *filter_expression
= (char *) original_filter_expression
;
1040 if (handle
== NULL
|| ev
== NULL
) {
1041 ret
= -LTTNG_ERR_INVALID
;
1046 * Empty filter string will always be rejected by the parser
1047 * anyway, so treat this corner-case early to eliminate
1048 * lttng_fmemopen error for 0-byte allocation.
1050 if (filter_expression
&& filter_expression
[0] == '\0') {
1051 ret
= -LTTNG_ERR_INVALID
;
1055 memset(&lsm
, 0, sizeof(lsm
));
1057 /* If no channel name, send empty string. */
1058 if (channel_name
== NULL
) {
1059 lttng_ctl_copy_string(lsm
.u
.enable
.channel_name
, "",
1060 sizeof(lsm
.u
.enable
.channel_name
));
1062 lttng_ctl_copy_string(lsm
.u
.enable
.channel_name
, channel_name
,
1063 sizeof(lsm
.u
.enable
.channel_name
));
1066 lsm
.cmd_type
= LTTNG_ENABLE_EVENT
;
1067 if (ev
->name
[0] == '\0') {
1068 /* Enable all events */
1069 lttng_ctl_copy_string(ev
->name
, "*", sizeof(ev
->name
));
1072 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1073 /* FIXME: copying non-packed struct to packed struct. */
1074 memcpy(&lsm
.u
.enable
.event
, ev
, sizeof(lsm
.u
.enable
.event
));
1076 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1077 sizeof(lsm
.session
.name
));
1078 lsm
.u
.enable
.exclusion_count
= exclusion_count
;
1079 lsm
.u
.enable
.bytecode_len
= 0;
1082 * For the JUL domain, a filter is enforced except for the enable all
1083 * event. This is done to avoid having the event in all sessions thus
1084 * filtering by logger name.
1086 if (exclusion_count
== 0 && filter_expression
== NULL
&&
1087 (handle
->domain
.type
!= LTTNG_DOMAIN_JUL
&&
1088 handle
->domain
.type
!= LTTNG_DOMAIN_LOG4J
&&
1089 handle
->domain
.type
!= LTTNG_DOMAIN_PYTHON
)) {
1094 * We have either a filter or some exclusions, so we need to set up
1095 * a variable-length memory block from where to send the data.
1098 /* Parse filter expression. */
1099 if (filter_expression
!= NULL
|| handle
->domain
.type
== LTTNG_DOMAIN_JUL
1100 || handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
1101 || handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1102 if (handle
->domain
.type
== LTTNG_DOMAIN_JUL
||
1103 handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
||
1104 handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1107 /* Setup JUL filter if needed. */
1108 agent_filter
= set_agent_filter(filter_expression
, ev
);
1109 if (!agent_filter
) {
1110 if (!filter_expression
) {
1112 * No JUL and no filter, just skip
1119 * With an agent filter, the original filter has
1120 * been added to it thus replace the filter
1123 filter_expression
= agent_filter
;
1124 free_filter_expression
= 1;
1128 ret
= generate_filter(filter_expression
, &lsm
, &ctx
);
1134 varlen_data
= zmalloc(lsm
.u
.enable
.bytecode_len
1135 + lsm
.u
.enable
.expression_len
1136 + LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
1138 ret
= -LTTNG_ERR_EXCLUSION_NOMEM
;
1142 /* Put exclusion names first in the data. */
1143 while (exclusion_count
--) {
1144 strncpy(varlen_data
+ LTTNG_SYMBOL_NAME_LEN
* exclusion_count
,
1145 *(exclusion_list
+ exclusion_count
),
1146 LTTNG_SYMBOL_NAME_LEN
- 1);
1148 /* Add filter expression next. */
1149 if (lsm
.u
.enable
.expression_len
!= 0) {
1151 + LTTNG_SYMBOL_NAME_LEN
* lsm
.u
.enable
.exclusion_count
,
1153 lsm
.u
.enable
.expression_len
);
1155 /* Add filter bytecode next. */
1156 if (ctx
&& lsm
.u
.enable
.bytecode_len
!= 0) {
1158 + LTTNG_SYMBOL_NAME_LEN
* lsm
.u
.enable
.exclusion_count
1159 + lsm
.u
.enable
.expression_len
,
1161 lsm
.u
.enable
.bytecode_len
);
1164 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, varlen_data
,
1165 (LTTNG_SYMBOL_NAME_LEN
* lsm
.u
.enable
.exclusion_count
) +
1166 lsm
.u
.enable
.bytecode_len
+ lsm
.u
.enable
.expression_len
,
1171 if (filter_expression
&& ctx
) {
1172 filter_bytecode_free(ctx
);
1173 filter_ir_free(ctx
);
1174 filter_parser_ctx_free(ctx
);
1177 if (free_filter_expression
) {
1179 * The filter expression has been replaced and must be freed as
1180 * it is not the original filter expression received as a
1183 free(filter_expression
);
1187 * Return directly to the caller and don't ask the sessiond since
1188 * something went wrong in the parsing of data above.
1193 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1197 int lttng_disable_event_ext(struct lttng_handle
*handle
,
1198 struct lttng_event
*ev
, const char *channel_name
,
1199 const char *original_filter_expression
)
1201 struct lttcomm_session_msg lsm
;
1204 unsigned int free_filter_expression
= 0;
1205 struct filter_parser_ctx
*ctx
= NULL
;
1207 * Cast as non-const since we may replace the filter expression
1208 * by a dynamically allocated string. Otherwise, the original
1209 * string is not modified.
1211 char *filter_expression
= (char *) original_filter_expression
;
1213 if (handle
== NULL
|| ev
== NULL
) {
1214 ret
= -LTTNG_ERR_INVALID
;
1219 * Empty filter string will always be rejected by the parser
1220 * anyway, so treat this corner-case early to eliminate
1221 * lttng_fmemopen error for 0-byte allocation.
1223 if (filter_expression
&& filter_expression
[0] == '\0') {
1224 ret
= -LTTNG_ERR_INVALID
;
1228 memset(&lsm
, 0, sizeof(lsm
));
1230 /* If no channel name, send empty string. */
1231 if (channel_name
== NULL
) {
1232 lttng_ctl_copy_string(lsm
.u
.disable
.channel_name
, "",
1233 sizeof(lsm
.u
.disable
.channel_name
));
1235 lttng_ctl_copy_string(lsm
.u
.disable
.channel_name
, channel_name
,
1236 sizeof(lsm
.u
.disable
.channel_name
));
1239 lsm
.cmd_type
= LTTNG_DISABLE_EVENT
;
1241 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1242 /* FIXME: copying non-packed struct to packed struct. */
1243 memcpy(&lsm
.u
.disable
.event
, ev
, sizeof(lsm
.u
.disable
.event
));
1245 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1246 sizeof(lsm
.session
.name
));
1247 lsm
.u
.disable
.bytecode_len
= 0;
1250 * For the JUL domain, a filter is enforced except for the
1251 * disable all event. This is done to avoid having the event in
1252 * all sessions thus filtering by logger name.
1254 if (filter_expression
== NULL
&&
1255 (handle
->domain
.type
!= LTTNG_DOMAIN_JUL
&&
1256 handle
->domain
.type
!= LTTNG_DOMAIN_LOG4J
&&
1257 handle
->domain
.type
!= LTTNG_DOMAIN_PYTHON
)) {
1262 * We have a filter, so we need to set up a variable-length
1263 * memory block from where to send the data.
1266 /* Parse filter expression */
1267 if (filter_expression
!= NULL
|| handle
->domain
.type
== LTTNG_DOMAIN_JUL
1268 || handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
1269 || handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1270 if (handle
->domain
.type
== LTTNG_DOMAIN_JUL
||
1271 handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
||
1272 handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1275 /* Setup JUL filter if needed. */
1276 agent_filter
= set_agent_filter(filter_expression
, ev
);
1277 if (!agent_filter
) {
1278 if (!filter_expression
) {
1280 * No JUL and no filter, just skip
1287 * With a JUL filter, the original filter has
1288 * been added to it thus replace the filter
1291 filter_expression
= agent_filter
;
1292 free_filter_expression
= 1;
1296 ret
= generate_filter(filter_expression
, &lsm
, &ctx
);
1302 varlen_data
= zmalloc(lsm
.u
.disable
.bytecode_len
1303 + lsm
.u
.disable
.expression_len
);
1305 ret
= -LTTNG_ERR_EXCLUSION_NOMEM
;
1309 /* Add filter expression. */
1310 if (lsm
.u
.disable
.expression_len
!= 0) {
1313 lsm
.u
.disable
.expression_len
);
1315 /* Add filter bytecode next. */
1316 if (ctx
&& lsm
.u
.disable
.bytecode_len
!= 0) {
1318 + lsm
.u
.disable
.expression_len
,
1320 lsm
.u
.disable
.bytecode_len
);
1323 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, varlen_data
,
1324 lsm
.u
.disable
.bytecode_len
+ lsm
.u
.disable
.expression_len
, NULL
);
1328 if (filter_expression
&& ctx
) {
1329 filter_bytecode_free(ctx
);
1330 filter_ir_free(ctx
);
1331 filter_parser_ctx_free(ctx
);
1334 if (free_filter_expression
) {
1336 * The filter expression has been replaced and must be freed as
1337 * it is not the original filter expression received as a
1340 free(filter_expression
);
1344 * Return directly to the caller and don't ask the sessiond since
1345 * something went wrong in the parsing of data above.
1350 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1355 * Disable event(s) of a channel and domain.
1356 * If no event name is specified, all events are disabled.
1357 * If no channel name is specified, the default 'channel0' is used.
1358 * Returns size of returned session payload data or a negative error code.
1360 int lttng_disable_event(struct lttng_handle
*handle
, const char *name
,
1361 const char *channel_name
)
1363 struct lttng_event ev
;
1365 memset(&ev
, 0, sizeof(ev
));
1367 ev
.type
= LTTNG_EVENT_ALL
;
1368 lttng_ctl_copy_string(ev
.name
, name
, sizeof(ev
.name
));
1369 return lttng_disable_event_ext(handle
, &ev
, channel_name
, NULL
);
1372 struct lttng_channel
*lttng_channel_create(struct lttng_domain
*domain
)
1374 struct lttng_channel
*channel
= NULL
;
1375 struct lttng_channel_extended
*extended
= NULL
;
1381 /* Validate domain. */
1382 switch (domain
->type
) {
1383 case LTTNG_DOMAIN_UST
:
1384 switch (domain
->buf_type
) {
1385 case LTTNG_BUFFER_PER_UID
:
1386 case LTTNG_BUFFER_PER_PID
:
1392 case LTTNG_DOMAIN_KERNEL
:
1393 if (domain
->buf_type
!= LTTNG_BUFFER_GLOBAL
) {
1401 channel
= zmalloc(sizeof(*channel
));
1406 extended
= zmalloc(sizeof(*extended
));
1411 channel
->attr
.extended
.ptr
= extended
;
1413 lttng_channel_set_default_attr(domain
, &channel
->attr
);
1421 void lttng_channel_destroy(struct lttng_channel
*channel
)
1427 if (channel
->attr
.extended
.ptr
) {
1428 free(channel
->attr
.extended
.ptr
);
1434 * Enable channel per domain
1435 * Returns size of returned session payload data or a negative error code.
1437 int lttng_enable_channel(struct lttng_handle
*handle
,
1438 struct lttng_channel
*in_chan
)
1440 struct lttcomm_session_msg lsm
;
1442 /* NULL arguments are forbidden. No default values. */
1443 if (handle
== NULL
|| in_chan
== NULL
) {
1444 return -LTTNG_ERR_INVALID
;
1447 memset(&lsm
, 0, sizeof(lsm
));
1448 memcpy(&lsm
.u
.channel
.chan
, in_chan
, sizeof(lsm
.u
.channel
.chan
));
1449 lsm
.u
.channel
.chan
.attr
.extended
.ptr
= NULL
;
1451 if (!in_chan
->attr
.extended
.ptr
) {
1452 struct lttng_channel
*channel
;
1453 struct lttng_channel_extended
*extended
;
1455 channel
= lttng_channel_create(&handle
->domain
);
1457 return -LTTNG_ERR_NOMEM
;
1461 * Create a new channel in order to use default extended
1464 extended
= (struct lttng_channel_extended
*)
1465 channel
->attr
.extended
.ptr
;
1466 memcpy(&lsm
.u
.channel
.extended
, extended
, sizeof(*extended
));
1467 lttng_channel_destroy(channel
);
1469 struct lttng_channel_extended
*extended
;
1471 extended
= (struct lttng_channel_extended
*)
1472 in_chan
->attr
.extended
.ptr
;
1473 memcpy(&lsm
.u
.channel
.extended
, extended
, sizeof(*extended
));
1476 lsm
.cmd_type
= LTTNG_ENABLE_CHANNEL
;
1477 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1479 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1480 sizeof(lsm
.session
.name
));
1482 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1486 * All tracing will be stopped for registered events of the channel.
1487 * Returns size of returned session payload data or a negative error code.
1489 int lttng_disable_channel(struct lttng_handle
*handle
, const char *name
)
1491 struct lttcomm_session_msg lsm
;
1493 /* Safety check. Both are mandatory. */
1494 if (handle
== NULL
|| name
== NULL
) {
1495 return -LTTNG_ERR_INVALID
;
1498 memset(&lsm
, 0, sizeof(lsm
));
1500 lsm
.cmd_type
= LTTNG_DISABLE_CHANNEL
;
1502 lttng_ctl_copy_string(lsm
.u
.disable
.channel_name
, name
,
1503 sizeof(lsm
.u
.disable
.channel_name
));
1505 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1507 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1508 sizeof(lsm
.session
.name
));
1510 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1514 * Add PID to session tracker.
1515 * Return 0 on success else a negative LTTng error code.
1517 int lttng_track_pid(struct lttng_handle
*handle
, int pid
)
1519 struct lttcomm_session_msg lsm
;
1521 /* NULL arguments are forbidden. No default values. */
1522 if (handle
== NULL
) {
1523 return -LTTNG_ERR_INVALID
;
1526 memset(&lsm
, 0, sizeof(lsm
));
1528 lsm
.cmd_type
= LTTNG_TRACK_PID
;
1529 lsm
.u
.pid_tracker
.pid
= pid
;
1531 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1533 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1534 sizeof(lsm
.session
.name
));
1536 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1540 * Remove PID from session tracker.
1541 * Return 0 on success else a negative LTTng error code.
1543 int lttng_untrack_pid(struct lttng_handle
*handle
, int pid
)
1545 struct lttcomm_session_msg lsm
;
1547 /* NULL arguments are forbidden. No default values. */
1548 if (handle
== NULL
) {
1549 return -LTTNG_ERR_INVALID
;
1552 memset(&lsm
, 0, sizeof(lsm
));
1554 lsm
.cmd_type
= LTTNG_UNTRACK_PID
;
1555 lsm
.u
.pid_tracker
.pid
= pid
;
1557 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1559 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1560 sizeof(lsm
.session
.name
));
1562 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1566 * Lists all available tracepoints of domain.
1567 * Sets the contents of the events array.
1568 * Returns the number of lttng_event entries in events;
1569 * on error, returns a negative value.
1571 int lttng_list_tracepoints(struct lttng_handle
*handle
,
1572 struct lttng_event
**events
)
1575 struct lttcomm_session_msg lsm
;
1577 if (handle
== NULL
) {
1578 return -LTTNG_ERR_INVALID
;
1581 memset(&lsm
, 0, sizeof(lsm
));
1582 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINTS
;
1583 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1585 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) events
);
1590 return ret
/ sizeof(struct lttng_event
);
1594 * Lists all available tracepoint fields of domain.
1595 * Sets the contents of the event field array.
1596 * Returns the number of lttng_event_field entries in events;
1597 * on error, returns a negative value.
1599 int lttng_list_tracepoint_fields(struct lttng_handle
*handle
,
1600 struct lttng_event_field
**fields
)
1603 struct lttcomm_session_msg lsm
;
1605 if (handle
== NULL
) {
1606 return -LTTNG_ERR_INVALID
;
1609 memset(&lsm
, 0, sizeof(lsm
));
1610 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINT_FIELDS
;
1611 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1613 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) fields
);
1618 return ret
/ sizeof(struct lttng_event_field
);
1622 * Lists all available kernel system calls. Allocates and sets the contents of
1625 * Returns the number of lttng_event entries in events; on error, returns a
1628 int lttng_list_syscalls(struct lttng_event
**events
)
1631 struct lttcomm_session_msg lsm
;
1634 return -LTTNG_ERR_INVALID
;
1637 memset(&lsm
, 0, sizeof(lsm
));
1638 lsm
.cmd_type
= LTTNG_LIST_SYSCALLS
;
1639 /* Force kernel domain for system calls. */
1640 lsm
.domain
.type
= LTTNG_DOMAIN_KERNEL
;
1642 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) events
);
1647 return ret
/ sizeof(struct lttng_event
);
1651 * Returns a human readable string describing
1652 * the error code (a negative value).
1654 const char *lttng_strerror(int code
)
1656 return error_get_str(code
);
1660 * Create a brand new session using name and url for destination.
1662 * Returns LTTNG_OK on success or a negative error code.
1664 int lttng_create_session(const char *name
, const char *url
)
1668 struct lttcomm_session_msg lsm
;
1669 struct lttng_uri
*uris
= NULL
;
1672 return -LTTNG_ERR_INVALID
;
1675 memset(&lsm
, 0, sizeof(lsm
));
1677 lsm
.cmd_type
= LTTNG_CREATE_SESSION
;
1678 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
1680 /* There should never be a data URL */
1681 size
= uri_parse_str_urls(url
, NULL
, &uris
);
1683 return -LTTNG_ERR_INVALID
;
1686 lsm
.u
.uri
.size
= size
;
1688 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
1689 sizeof(struct lttng_uri
) * size
, NULL
);
1696 * Destroy session using name.
1697 * Returns size of returned session payload data or a negative error code.
1700 int _lttng_destroy_session(const char *session_name
)
1702 struct lttcomm_session_msg lsm
;
1704 if (session_name
== NULL
) {
1705 return -LTTNG_ERR_INVALID
;
1708 memset(&lsm
, 0, sizeof(lsm
));
1709 lsm
.cmd_type
= LTTNG_DESTROY_SESSION
;
1711 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
1712 sizeof(lsm
.session
.name
));
1714 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1718 * Stop the session and wait for the data before destroying it
1720 int lttng_destroy_session(const char *session_name
)
1725 * Stop the tracing and wait for the data.
1727 ret
= _lttng_stop_tracing(session_name
, 1);
1728 if (ret
&& ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
1732 ret
= _lttng_destroy_session(session_name
);
1738 * Destroy the session without waiting for the data.
1740 int lttng_destroy_session_no_wait(const char *session_name
)
1745 * Stop the tracing without waiting for the data.
1746 * The session might already have been stopped, so just
1749 ret
= _lttng_stop_tracing(session_name
, 0);
1750 if (ret
&& ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
1754 ret
= _lttng_destroy_session(session_name
);
1760 * Ask the session daemon for all available sessions.
1761 * Sets the contents of the sessions array.
1762 * Returns the number of lttng_session entries in sessions;
1763 * on error, returns a negative value.
1765 int lttng_list_sessions(struct lttng_session
**sessions
)
1768 struct lttcomm_session_msg lsm
;
1770 memset(&lsm
, 0, sizeof(lsm
));
1771 lsm
.cmd_type
= LTTNG_LIST_SESSIONS
;
1772 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) sessions
);
1777 return ret
/ sizeof(struct lttng_session
);
1780 int lttng_set_session_shm_path(const char *session_name
,
1781 const char *shm_path
)
1783 struct lttcomm_session_msg lsm
;
1785 if (session_name
== NULL
) {
1786 return -LTTNG_ERR_INVALID
;
1789 memset(&lsm
, 0, sizeof(lsm
));
1790 lsm
.cmd_type
= LTTNG_SET_SESSION_SHM_PATH
;
1792 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
1793 sizeof(lsm
.session
.name
));
1794 lttng_ctl_copy_string(lsm
.u
.set_shm_path
.shm_path
, shm_path
,
1795 sizeof(lsm
.u
.set_shm_path
.shm_path
));
1797 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1801 * Ask the session daemon for all available domains of a session.
1802 * Sets the contents of the domains array.
1803 * Returns the number of lttng_domain entries in domains;
1804 * on error, returns a negative value.
1806 int lttng_list_domains(const char *session_name
,
1807 struct lttng_domain
**domains
)
1810 struct lttcomm_session_msg lsm
;
1812 if (session_name
== NULL
) {
1813 return -LTTNG_ERR_INVALID
;
1816 memset(&lsm
, 0, sizeof(lsm
));
1817 lsm
.cmd_type
= LTTNG_LIST_DOMAINS
;
1819 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
1820 sizeof(lsm
.session
.name
));
1822 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) domains
);
1827 return ret
/ sizeof(struct lttng_domain
);
1831 * Ask the session daemon for all available channels of a session.
1832 * Sets the contents of the channels array.
1833 * Returns the number of lttng_channel entries in channels;
1834 * on error, returns a negative value.
1836 int lttng_list_channels(struct lttng_handle
*handle
,
1837 struct lttng_channel
**channels
)
1840 size_t channel_count
, i
;
1841 const size_t channel_size
= sizeof(struct lttng_channel
) +
1842 sizeof(struct lttng_channel_extended
);
1843 struct lttcomm_session_msg lsm
;
1846 if (handle
== NULL
) {
1847 ret
= -LTTNG_ERR_INVALID
;
1851 memset(&lsm
, 0, sizeof(lsm
));
1852 lsm
.cmd_type
= LTTNG_LIST_CHANNELS
;
1853 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1854 sizeof(lsm
.session
.name
));
1856 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1858 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) channels
);
1863 if (ret
% channel_size
) {
1864 ret
= -LTTNG_ERR_UNK
;
1869 channel_count
= (size_t) ret
/ channel_size
;
1871 /* Set extended info pointers */
1872 extended_at
= ((void *) *channels
) +
1873 channel_count
* sizeof(struct lttng_channel
);
1874 for (i
= 0; i
< channel_count
; i
++) {
1875 struct lttng_channel
*chan
= &(*channels
)[i
];
1877 chan
->attr
.extended
.ptr
= extended_at
;
1878 extended_at
+= sizeof(struct lttng_channel_extended
);
1881 ret
= (int) channel_count
;
1887 * Ask the session daemon for all available events of a session channel.
1888 * Sets the contents of the events array.
1889 * Returns the number of lttng_event entries in events;
1890 * on error, returns a negative value.
1892 int lttng_list_events(struct lttng_handle
*handle
,
1893 const char *channel_name
, struct lttng_event
**events
)
1896 struct lttcomm_session_msg lsm
;
1897 struct lttcomm_event_command_header
*cmd_header
= NULL
;
1898 size_t cmd_header_len
;
1899 uint32_t nb_events
, i
;
1902 char *reception_buffer
= NULL
;
1903 char *listing
= NULL
;
1906 /* Safety check. An handle and channel name are mandatory */
1907 if (handle
== NULL
|| channel_name
== NULL
) {
1908 return -LTTNG_ERR_INVALID
;
1911 memset(&lsm
, 0, sizeof(lsm
));
1912 lsm
.cmd_type
= LTTNG_LIST_EVENTS
;
1913 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1914 sizeof(lsm
.session
.name
));
1915 lttng_ctl_copy_string(lsm
.u
.list
.channel_name
, channel_name
,
1916 sizeof(lsm
.u
.list
.channel_name
));
1917 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1919 ret
= lttng_ctl_ask_sessiond_fds_varlen(&lsm
, NULL
, 0, NULL
, 0,
1920 (void **) &reception_buffer
, (void **) &cmd_header
,
1926 /* Set number of events and free command header */
1927 nb_events
= cmd_header
->nb_events
;
1928 if (nb_events
> INT_MAX
) {
1936 * The buffer that is returned must contain a "flat" version of
1937 * the events that are returned. In other words, all pointers
1938 * within an lttng_event must point to a location within the returned
1939 * buffer so that the user may free by simply calling free() on the
1940 * returned buffer. This is needed in order to maintain API
1943 * A first pass is performed to figure the size of the buffer that
1944 * must be returned. A second pass is then performed to setup
1945 * the returned events so that their members always point within the
1948 * The layout of the returned buffer is as follows:
1949 * - struct lttng_event[nb_events],
1950 * - nb_events times the following:
1951 * - struct lttng_event_extended,
1952 * - flattened version of userspace_probe_location
1953 * - filter_expression
1955 * - padding to align to 64-bits
1957 comm_ext_at
= reception_buffer
+
1958 (nb_events
* sizeof(struct lttng_event
));
1959 storage_req
= nb_events
* sizeof(struct lttng_event
);
1961 for (i
= 0; i
< nb_events
; i
++) {
1962 struct lttcomm_event_extended_header
*ext_comm
=
1963 (struct lttcomm_event_extended_header
*) comm_ext_at
;
1965 comm_ext_at
+= sizeof(*ext_comm
);
1966 comm_ext_at
+= ext_comm
->filter_len
;
1968 ext_comm
->nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
;
1970 storage_req
+= sizeof(struct lttng_event_extended
);
1971 /* TODO: missing size of flat userspace probe. */
1972 storage_req
+= ext_comm
->filter_len
;
1973 storage_req
+= ext_comm
->nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
;
1974 storage_req
+= storage_req
% 8;
1977 listing
= zmalloc(storage_req
);
1981 memcpy(listing
, reception_buffer
,
1982 nb_events
* sizeof(struct lttng_event
));
1984 comm_ext_at
= reception_buffer
+
1985 (nb_events
* sizeof(struct lttng_event
));
1986 listing_at
= listing
+
1987 (nb_events
* sizeof(struct lttng_event
));
1988 for (i
= 0; i
< nb_events
; i
++) {
1989 struct lttng_event
*event
= (struct lttng_event
*)
1990 (listing
+ (sizeof(struct lttng_event
) * i
));
1991 struct lttcomm_event_extended_header
*ext_comm
=
1992 (struct lttcomm_event_extended_header
*) comm_ext_at
;
1993 struct lttng_event_extended
*event_extended
=
1994 (struct lttng_event_extended
*) listing_at
;
1996 event
->extended
.ptr
= event_extended
;
1997 listing_at
+= sizeof(*event_extended
);
1998 comm_ext_at
+= sizeof(*ext_comm
);
2000 /* Copy filter expression. */
2001 memcpy(listing_at
, comm_ext_at
, ext_comm
->filter_len
);
2002 event_extended
->filter_expression
= listing_at
;
2003 comm_ext_at
+= ext_comm
->filter_len
;
2004 listing_at
+= ext_comm
->filter_len
;
2006 /* Copy exclusions. */
2007 event_extended
->exclusions
.count
= ext_comm
->nb_exclusions
;
2008 event_extended
->exclusions
.strings
= listing_at
;
2009 memcpy(listing_at
, comm_ext_at
,
2010 ext_comm
->nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
);
2011 listing_at
+= ext_comm
->nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
;
2012 comm_ext_at
+= ext_comm
->nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
;
2014 listing_at
+= ((uintptr_t) listing_at
) % 8;
2017 *events
= (struct lttng_event
*) listing
;
2019 ret
= (int) nb_events
;
2022 free(reception_buffer
);
2028 * Sets the tracing_group variable with name.
2029 * This function allocates memory pointed to by tracing_group.
2030 * On success, returns 0, on error, returns -1 (null name) or -ENOMEM.
2032 int lttng_set_tracing_group(const char *name
)
2035 return -LTTNG_ERR_INVALID
;
2038 if (asprintf(&tracing_group
, "%s", name
) < 0) {
2039 return -LTTNG_ERR_FATAL
;
2045 int lttng_calibrate(struct lttng_handle
*handle
,
2046 struct lttng_calibrate
*calibrate
)
2049 * This command was removed in LTTng 2.9.
2051 return -LTTNG_ERR_UND
;
2055 * Set default channel attributes.
2056 * If either or both of the arguments are null, attr content is zeroe'd.
2058 void lttng_channel_set_default_attr(struct lttng_domain
*domain
,
2059 struct lttng_channel_attr
*attr
)
2061 struct lttng_channel_extended
*extended
;
2064 if (attr
== NULL
|| domain
== NULL
) {
2068 extended
= (struct lttng_channel_extended
*) attr
->extended
.ptr
;
2069 memset(attr
, 0, sizeof(struct lttng_channel_attr
));
2071 /* Same for all domains. */
2072 attr
->overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
2073 attr
->tracefile_size
= DEFAULT_CHANNEL_TRACEFILE_SIZE
;
2074 attr
->tracefile_count
= DEFAULT_CHANNEL_TRACEFILE_COUNT
;
2076 switch (domain
->type
) {
2077 case LTTNG_DOMAIN_KERNEL
:
2078 attr
->switch_timer_interval
=
2079 DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER
;
2080 attr
->read_timer_interval
= DEFAULT_KERNEL_CHANNEL_READ_TIMER
;
2081 attr
->subbuf_size
= default_get_kernel_channel_subbuf_size();
2082 attr
->num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
2083 attr
->output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
2085 extended
->monitor_timer_interval
=
2086 DEFAULT_KERNEL_CHANNEL_MONITOR_TIMER
;
2087 extended
->blocking_timeout
=
2088 DEFAULT_KERNEL_CHANNEL_BLOCKING_TIMEOUT
;
2091 case LTTNG_DOMAIN_UST
:
2092 switch (domain
->buf_type
) {
2093 case LTTNG_BUFFER_PER_UID
:
2094 attr
->subbuf_size
= default_get_ust_uid_channel_subbuf_size();
2095 attr
->num_subbuf
= DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM
;
2096 attr
->output
= DEFAULT_UST_UID_CHANNEL_OUTPUT
;
2097 attr
->switch_timer_interval
=
2098 DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER
;
2099 attr
->read_timer_interval
=
2100 DEFAULT_UST_UID_CHANNEL_READ_TIMER
;
2102 extended
->monitor_timer_interval
=
2103 DEFAULT_UST_UID_CHANNEL_MONITOR_TIMER
;
2104 extended
->blocking_timeout
=
2105 DEFAULT_UST_UID_CHANNEL_BLOCKING_TIMEOUT
;
2108 case LTTNG_BUFFER_PER_PID
:
2110 attr
->subbuf_size
= default_get_ust_pid_channel_subbuf_size();
2111 attr
->num_subbuf
= DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM
;
2112 attr
->output
= DEFAULT_UST_PID_CHANNEL_OUTPUT
;
2113 attr
->switch_timer_interval
=
2114 DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER
;
2115 attr
->read_timer_interval
=
2116 DEFAULT_UST_PID_CHANNEL_READ_TIMER
;
2118 extended
->monitor_timer_interval
=
2119 DEFAULT_UST_PID_CHANNEL_MONITOR_TIMER
;
2120 extended
->blocking_timeout
=
2121 DEFAULT_UST_PID_CHANNEL_BLOCKING_TIMEOUT
;
2126 /* Default behavior: leave set to 0. */
2130 attr
->extended
.ptr
= extended
;
2133 int lttng_channel_get_discarded_event_count(struct lttng_channel
*channel
,
2134 uint64_t *discarded_events
)
2137 struct lttng_channel_extended
*chan_ext
;
2139 if (!channel
|| !discarded_events
) {
2140 ret
= -LTTNG_ERR_INVALID
;
2144 chan_ext
= channel
->attr
.extended
.ptr
;
2147 * This can happen since the lttng_channel structure is
2148 * used for other tasks where this pointer is never set.
2150 *discarded_events
= 0;
2154 *discarded_events
= chan_ext
->discarded_events
;
2159 int lttng_channel_get_lost_packet_count(struct lttng_channel
*channel
,
2160 uint64_t *lost_packets
)
2163 struct lttng_channel_extended
*chan_ext
;
2165 if (!channel
|| !lost_packets
) {
2166 ret
= -LTTNG_ERR_INVALID
;
2170 chan_ext
= channel
->attr
.extended
.ptr
;
2173 * This can happen since the lttng_channel structure is
2174 * used for other tasks where this pointer is never set.
2180 *lost_packets
= chan_ext
->lost_packets
;
2185 int lttng_channel_get_monitor_timer_interval(struct lttng_channel
*chan
,
2186 uint64_t *monitor_timer_interval
)
2190 if (!chan
|| !monitor_timer_interval
) {
2191 ret
= -LTTNG_ERR_INVALID
;
2195 if (!chan
->attr
.extended
.ptr
) {
2196 ret
= -LTTNG_ERR_INVALID
;
2200 *monitor_timer_interval
= ((struct lttng_channel_extended
*)
2201 chan
->attr
.extended
.ptr
)->monitor_timer_interval
;
2206 int lttng_channel_set_monitor_timer_interval(struct lttng_channel
*chan
,
2207 uint64_t monitor_timer_interval
)
2211 if (!chan
|| !chan
->attr
.extended
.ptr
) {
2212 ret
= -LTTNG_ERR_INVALID
;
2216 ((struct lttng_channel_extended
*)
2217 chan
->attr
.extended
.ptr
)->monitor_timer_interval
=
2218 monitor_timer_interval
;
2223 int lttng_channel_get_blocking_timeout(struct lttng_channel
*chan
,
2224 int64_t *blocking_timeout
)
2228 if (!chan
|| !blocking_timeout
) {
2229 ret
= -LTTNG_ERR_INVALID
;
2233 if (!chan
->attr
.extended
.ptr
) {
2234 ret
= -LTTNG_ERR_INVALID
;
2238 *blocking_timeout
= ((struct lttng_channel_extended
*)
2239 chan
->attr
.extended
.ptr
)->blocking_timeout
;
2244 int lttng_channel_set_blocking_timeout(struct lttng_channel
*chan
,
2245 int64_t blocking_timeout
)
2248 int64_t msec_timeout
;
2250 if (!chan
|| !chan
->attr
.extended
.ptr
) {
2251 ret
= -LTTNG_ERR_INVALID
;
2255 if (blocking_timeout
< 0 && blocking_timeout
!= -1) {
2256 ret
= -LTTNG_ERR_INVALID
;
2261 * LTTng-ust's use of poll() to implement this timeout mechanism forces
2262 * us to accept a narrower range of values (msecs expressed as a signed
2265 msec_timeout
= blocking_timeout
/ 1000;
2266 if (msec_timeout
!= (int32_t) msec_timeout
) {
2267 ret
= -LTTNG_ERR_INVALID
;
2271 ((struct lttng_channel_extended
*)
2272 chan
->attr
.extended
.ptr
)->blocking_timeout
=
2279 * Check if session daemon is alive.
2281 * Return 1 if alive or 0 if not.
2282 * On error returns a negative value.
2284 int lttng_session_daemon_alive(void)
2288 ret
= set_session_daemon_path();
2294 if (*sessiond_sock_path
== '\0') {
2296 * No socket path set. Weird error which means the constructor
2302 ret
= try_connect_sessiond(sessiond_sock_path
);
2313 * Set URL for a consumer for a session and domain.
2315 * Return 0 on success, else a negative value.
2317 int lttng_set_consumer_url(struct lttng_handle
*handle
,
2318 const char *control_url
, const char *data_url
)
2322 struct lttcomm_session_msg lsm
;
2323 struct lttng_uri
*uris
= NULL
;
2325 if (handle
== NULL
|| (control_url
== NULL
&& data_url
== NULL
)) {
2326 return -LTTNG_ERR_INVALID
;
2329 memset(&lsm
, 0, sizeof(lsm
));
2331 lsm
.cmd_type
= LTTNG_SET_CONSUMER_URI
;
2333 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
2334 sizeof(lsm
.session
.name
));
2335 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
2337 size
= uri_parse_str_urls(control_url
, data_url
, &uris
);
2339 return -LTTNG_ERR_INVALID
;
2342 lsm
.u
.uri
.size
= size
;
2344 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
2345 sizeof(struct lttng_uri
) * size
, NULL
);
2354 int lttng_enable_consumer(struct lttng_handle
*handle
)
2362 int lttng_disable_consumer(struct lttng_handle
*handle
)
2368 * This is an extension of create session that is ONLY and SHOULD only be used
2369 * by the lttng command line program. It exists to avoid using URI parsing in
2372 * We need the date and time for the trace path subdirectory for the case where
2373 * the user does NOT define one using either -o or -U. Using the normal
2374 * lttng_create_session API call, we have no clue on the session daemon side if
2375 * the URL was generated automatically by the client or define by the user.
2377 * So this function "wrapper" is hidden from the public API, takes the datetime
2378 * string and appends it if necessary to the URI subdirectory before sending it
2379 * to the session daemon.
2381 * With this extra function, the lttng_create_session call behavior is not
2382 * changed and the timestamp is appended to the URI on the session daemon side
2385 int _lttng_create_session_ext(const char *name
, const char *url
,
2386 const char *datetime
)
2390 struct lttcomm_session_msg lsm
;
2391 struct lttng_uri
*uris
= NULL
;
2393 if (name
== NULL
|| datetime
== NULL
) {
2394 return -LTTNG_ERR_INVALID
;
2397 memset(&lsm
, 0, sizeof(lsm
));
2399 lsm
.cmd_type
= LTTNG_CREATE_SESSION
;
2400 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
2402 /* There should never be a data URL. */
2403 size
= uri_parse_str_urls(url
, NULL
, &uris
);
2405 ret
= -LTTNG_ERR_INVALID
;
2409 lsm
.u
.uri
.size
= size
;
2411 if (size
> 0 && uris
[0].dtype
!= LTTNG_DST_PATH
&& strlen(uris
[0].subdir
) == 0) {
2412 /* Don't append datetime if the name was automatically created. */
2413 if (strncmp(name
, DEFAULT_SESSION_NAME
"-",
2414 strlen(DEFAULT_SESSION_NAME
) + 1)) {
2415 ret
= snprintf(uris
[0].subdir
, sizeof(uris
[0].subdir
), "%s-%s",
2418 ret
= snprintf(uris
[0].subdir
, sizeof(uris
[0].subdir
), "%s", name
);
2421 PERROR("snprintf uri subdir");
2422 ret
= -LTTNG_ERR_FATAL
;
2427 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
2428 sizeof(struct lttng_uri
) * size
, NULL
);
2436 * For a given session name, this call checks if the data is ready to be read
2437 * or is still being extracted by the consumer(s) hence not ready to be used by
2440 int lttng_data_pending(const char *session_name
)
2443 struct lttcomm_session_msg lsm
;
2444 uint8_t *pending
= NULL
;
2446 if (session_name
== NULL
) {
2447 return -LTTNG_ERR_INVALID
;
2450 memset(&lsm
, 0, sizeof(lsm
));
2451 lsm
.cmd_type
= LTTNG_DATA_PENDING
;
2453 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
2454 sizeof(lsm
.session
.name
));
2456 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) &pending
);
2459 } else if (ret
!= 1) {
2460 /* Unexpected payload size */
2461 ret
= -LTTNG_ERR_INVALID
;
2465 ret
= (int) *pending
;
2472 * Create a session exclusively used for snapshot.
2474 * Returns LTTNG_OK on success or a negative error code.
2476 int lttng_create_session_snapshot(const char *name
, const char *snapshot_url
)
2480 struct lttcomm_session_msg lsm
;
2481 struct lttng_uri
*uris
= NULL
;
2484 return -LTTNG_ERR_INVALID
;
2487 memset(&lsm
, 0, sizeof(lsm
));
2489 lsm
.cmd_type
= LTTNG_CREATE_SESSION_SNAPSHOT
;
2490 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
2492 size
= uri_parse_str_urls(snapshot_url
, NULL
, &uris
);
2494 return -LTTNG_ERR_INVALID
;
2497 lsm
.u
.uri
.size
= size
;
2500 * If the user does not specify a custom subdir, use the session name.
2502 if (size
> 0 && uris
[0].dtype
!= LTTNG_DST_PATH
&& strlen(uris
[0].subdir
) == 0) {
2503 ret
= snprintf(uris
[0].subdir
, sizeof(uris
[0].subdir
), "%s", name
);
2505 PERROR("snprintf uri subdir");
2506 ret
= -LTTNG_ERR_FATAL
;
2511 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
2512 sizeof(struct lttng_uri
) * size
, NULL
);
2520 * Create a session exclusively used for live.
2522 * Returns LTTNG_OK on success or a negative error code.
2524 int lttng_create_session_live(const char *name
, const char *url
,
2525 unsigned int timer_interval
)
2529 struct lttcomm_session_msg lsm
;
2530 struct lttng_uri
*uris
= NULL
;
2532 if (name
== NULL
|| timer_interval
== 0) {
2533 return -LTTNG_ERR_INVALID
;
2536 memset(&lsm
, 0, sizeof(lsm
));
2538 lsm
.cmd_type
= LTTNG_CREATE_SESSION_LIVE
;
2539 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
2542 size
= uri_parse_str_urls(url
, NULL
, &uris
);
2544 ret
= -LTTNG_ERR_INVALID
;
2548 /* file:// is not accepted for live session. */
2549 if (uris
[0].dtype
== LTTNG_DST_PATH
) {
2550 ret
= -LTTNG_ERR_INVALID
;
2557 lsm
.u
.session_live
.nb_uri
= size
;
2558 lsm
.u
.session_live
.timer_interval
= timer_interval
;
2560 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, uris
,
2561 sizeof(struct lttng_uri
) * size
, NULL
);
2569 * List PIDs in the tracker.
2571 * enabled is set to whether the PID tracker is enabled.
2572 * pids is set to an allocated array of PIDs currently tracked. On
2573 * success, pids must be freed by the caller.
2574 * nr_pids is set to the number of entries contained by the pids array.
2576 * Returns 0 on success, else a negative LTTng error code.
2578 int lttng_list_tracker_pids(struct lttng_handle
*handle
,
2579 int *_enabled
, int32_t **_pids
, size_t *_nr_pids
)
2583 struct lttcomm_session_msg lsm
;
2587 if (handle
== NULL
) {
2588 return -LTTNG_ERR_INVALID
;
2591 memset(&lsm
, 0, sizeof(lsm
));
2592 lsm
.cmd_type
= LTTNG_LIST_TRACKER_PIDS
;
2593 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
2594 sizeof(lsm
.session
.name
));
2595 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
2597 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) &pids
);
2601 nr_pids
= ret
/ sizeof(int32_t);
2602 if (nr_pids
== 1 && pids
[0] == -1) {
2608 *_enabled
= enabled
;
2610 *_nr_pids
= nr_pids
;
2615 * Regenerate the metadata for a session.
2616 * Return 0 on success, a negative error code on error.
2618 int lttng_regenerate_metadata(const char *session_name
)
2621 struct lttcomm_session_msg lsm
;
2623 if (!session_name
) {
2624 ret
= -LTTNG_ERR_INVALID
;
2628 memset(&lsm
, 0, sizeof(lsm
));
2629 lsm
.cmd_type
= LTTNG_REGENERATE_METADATA
;
2631 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
2632 sizeof(lsm
.session
.name
));
2634 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
2645 * Deprecated, replaced by lttng_regenerate_metadata.
2647 int lttng_metadata_regenerate(const char *session_name
)
2649 return lttng_regenerate_metadata(session_name
);
2653 * Regenerate the statedump of a session.
2654 * Return 0 on success, a negative error code on error.
2656 int lttng_regenerate_statedump(const char *session_name
)
2659 struct lttcomm_session_msg lsm
;
2661 if (!session_name
) {
2662 ret
= -LTTNG_ERR_INVALID
;
2666 memset(&lsm
, 0, sizeof(lsm
));
2667 lsm
.cmd_type
= LTTNG_REGENERATE_STATEDUMP
;
2669 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
2670 sizeof(lsm
.session
.name
));
2672 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
2682 int lttng_register_trigger(struct lttng_trigger
*trigger
)
2685 struct lttcomm_session_msg lsm
;
2686 struct lttng_dynamic_buffer buffer
;
2688 lttng_dynamic_buffer_init(&buffer
);
2690 ret
= -LTTNG_ERR_INVALID
;
2694 if (!lttng_trigger_validate(trigger
)) {
2695 ret
= -LTTNG_ERR_INVALID_TRIGGER
;
2699 ret
= lttng_trigger_serialize(trigger
, &buffer
);
2701 ret
= -LTTNG_ERR_UNK
;
2705 memset(&lsm
, 0, sizeof(lsm
));
2706 lsm
.cmd_type
= LTTNG_REGISTER_TRIGGER
;
2707 lsm
.u
.trigger
.length
= (uint32_t) buffer
.size
;
2708 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, buffer
.data
,
2711 lttng_dynamic_buffer_reset(&buffer
);
2715 int lttng_unregister_trigger(struct lttng_trigger
*trigger
)
2718 struct lttcomm_session_msg lsm
;
2719 struct lttng_dynamic_buffer buffer
;
2721 lttng_dynamic_buffer_init(&buffer
);
2723 ret
= -LTTNG_ERR_INVALID
;
2727 if (!lttng_trigger_validate(trigger
)) {
2728 ret
= -LTTNG_ERR_INVALID_TRIGGER
;
2732 ret
= lttng_trigger_serialize(trigger
, &buffer
);
2734 ret
= -LTTNG_ERR_UNK
;
2738 memset(&lsm
, 0, sizeof(lsm
));
2739 lsm
.cmd_type
= LTTNG_UNREGISTER_TRIGGER
;
2740 lsm
.u
.trigger
.length
= (uint32_t) buffer
.size
;
2741 ret
= lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm
, buffer
.data
,
2744 lttng_dynamic_buffer_reset(&buffer
);
2748 int lttng_session_get_current_archive_location(const char *session_name
,
2751 struct lttcomm_session_msg lsm
;
2752 struct lttng_session_get_current_output_return
*output_return
= NULL
;
2756 memset(&lsm
, 0, sizeof(lsm
));
2757 lsm
.cmd_type
= LTTNG_SESSION_GET_CURRENT_OUTPUT
;
2758 ret
= lttng_strncpy(lsm
.session
.name
, session_name
,
2759 sizeof(lsm
.session
.name
));
2761 ret
= -LTTNG_ERR_INVALID
;
2765 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) &output_return
);
2771 path_len
= lttng_strnlen(output_return
->path
,
2772 sizeof(output_return
->path
));
2773 if (path_len
== 0 || path_len
== sizeof(output_return
->path
)) {
2774 ret
= -LTTNG_ERR_NO_SESSION_OUTPUT
;
2778 *chunk_path
= zmalloc(path_len
+ 1);
2783 memcpy(*chunk_path
, output_return
->path
, path_len
);
2788 free(output_return
);
2795 static void __attribute__((constructor
)) init(void)
2797 /* Set default session group */
2798 lttng_set_tracing_group(DEFAULT_TRACING_GROUP
);
2804 static void __attribute__((destructor
)) lttng_ctl_exit(void)
2806 free(tracing_group
);