4 * Linux Trace Toolkit Control Library
6 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * 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 <lttng/lttng.h>
38 #include <lttng/health-internal.h>
40 #include "filter/filter-ast.h"
41 #include "filter/filter-parser.h"
42 #include "filter/filter-bytecode.h"
43 #include "filter/memstream.h"
44 #include "lttng-ctl-helper.h"
47 static const int print_xml
= 1;
48 #define dbg_printf(fmt, args...) \
49 printf("[debug liblttng-ctl] " fmt, ## args)
51 static const int print_xml
= 0;
52 #define dbg_printf(fmt, args...) \
54 /* do nothing but check printf format */ \
56 printf("[debug liblttnctl] " fmt, ## args); \
61 /* Socket to session daemon for communication */
62 static int sessiond_socket
;
63 static char sessiond_sock_path
[PATH_MAX
];
66 static char *tracing_group
;
72 * Those two variables are used by error.h to silent or control the verbosity of
73 * error message. They are global to the library so application linking with it
74 * are able to compile correctly and also control verbosity of the library.
77 int lttng_opt_verbose
;
81 * Copy string from src to dst and enforce null terminated byte.
84 void lttng_ctl_copy_string(char *dst
, const char *src
, size_t len
)
87 strncpy(dst
, src
, len
);
88 /* Enforce the NULL terminated byte */
96 * Copy domain to lttcomm_session_msg domain.
98 * If domain is unknown, default domain will be the kernel.
101 void lttng_ctl_copy_lttng_domain(struct lttng_domain
*dst
,
102 struct lttng_domain
*src
)
106 case LTTNG_DOMAIN_KERNEL
:
107 case LTTNG_DOMAIN_UST
:
108 case LTTNG_DOMAIN_JUL
:
109 case LTTNG_DOMAIN_LOG4J
:
110 case LTTNG_DOMAIN_PYTHON
:
111 memcpy(dst
, src
, sizeof(struct lttng_domain
));
114 memset(dst
, 0, sizeof(struct lttng_domain
));
121 * Send lttcomm_session_msg to the session daemon.
123 * On success, returns the number of bytes sent (>=0)
124 * On error, returns -1
126 static int send_session_msg(struct lttcomm_session_msg
*lsm
)
131 ret
= -LTTNG_ERR_NO_SESSIOND
;
135 DBG("LSM cmd type : %d", lsm
->cmd_type
);
137 ret
= lttcomm_send_creds_unix_sock(sessiond_socket
, lsm
,
138 sizeof(struct lttcomm_session_msg
));
140 ret
= -LTTNG_ERR_FATAL
;
148 * Send var len data to the session daemon.
150 * On success, returns the number of bytes sent (>=0)
151 * On error, returns -1
153 static int send_session_varlen(void *data
, size_t len
)
158 ret
= -LTTNG_ERR_NO_SESSIOND
;
167 ret
= lttcomm_send_unix_sock(sessiond_socket
, data
, len
);
169 ret
= -LTTNG_ERR_FATAL
;
177 * Receive data from the sessiond socket.
179 * On success, returns the number of bytes received (>=0)
180 * On error, returns -1 (recvmsg() error) or -ENOTCONN
182 static int recv_data_sessiond(void *buf
, size_t len
)
187 ret
= -LTTNG_ERR_NO_SESSIOND
;
191 ret
= lttcomm_recv_unix_sock(sessiond_socket
, buf
, len
);
193 ret
= -LTTNG_ERR_FATAL
;
201 * Check if we are in the specified group.
203 * If yes return 1, else return -1.
206 int lttng_check_tracing_group(void)
208 struct group
*grp_tracing
; /* no free(). See getgrnam(3) */
210 int grp_list_size
, grp_id
, i
;
212 const char *grp_name
= tracing_group
;
214 /* Get GID of group 'tracing' */
215 grp_tracing
= getgrnam(grp_name
);
217 /* If grp_tracing is NULL, the group does not exist. */
221 /* Get number of supplementary group IDs */
222 grp_list_size
= getgroups(0, NULL
);
223 if (grp_list_size
< 0) {
228 /* Alloc group list of the right size */
229 grp_list
= zmalloc(grp_list_size
* sizeof(gid_t
));
234 grp_id
= getgroups(grp_list_size
, grp_list
);
240 for (i
= 0; i
< grp_list_size
; i
++) {
241 if (grp_list
[i
] == grp_tracing
->gr_gid
) {
255 * Try connect to session daemon with sock_path.
257 * Return 0 on success, else -1
259 static int try_connect_sessiond(const char *sock_path
)
263 /* If socket exist, we check if the daemon listens for connect. */
264 ret
= access(sock_path
, F_OK
);
270 ret
= lttcomm_connect_unix_sock(sock_path
);
276 ret
= lttcomm_close_unix_sock(ret
);
278 perror("lttcomm_close_unix_sock");
288 * Set sessiond socket path by putting it in the global sessiond_sock_path
291 * Returns 0 on success, negative value on failure (the sessiond socket path
292 * is somehow too long or ENOMEM).
294 static int set_session_daemon_path(void)
296 int in_tgroup
= 0; /* In tracing group */
302 /* Are we in the tracing group ? */
303 in_tgroup
= lttng_check_tracing_group();
306 if ((uid
== 0) || in_tgroup
) {
307 lttng_ctl_copy_string(sessiond_sock_path
,
308 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
, sizeof(sessiond_sock_path
));
316 ret
= try_connect_sessiond(sessiond_sock_path
);
320 /* Global session daemon not available... */
322 /* ...or not in tracing group (and not root), default */
325 * With GNU C < 2.1, snprintf returns -1 if the target buffer is too small;
326 * With GNU C >= 2.1, snprintf returns the required size (excluding closing null)
328 ret
= snprintf(sessiond_sock_path
, sizeof(sessiond_sock_path
),
329 DEFAULT_HOME_CLIENT_UNIX_SOCK
, utils_get_home_dir());
330 if ((ret
< 0) || (ret
>= sizeof(sessiond_sock_path
))) {
342 * Connect to the LTTng session daemon.
344 * On success, return 0. On error, return -1.
346 static int connect_sessiond(void)
350 /* Don't try to connect if already connected. */
355 ret
= set_session_daemon_path();
360 /* Connect to the sesssion daemon */
361 ret
= lttcomm_connect_unix_sock(sessiond_sock_path
);
366 sessiond_socket
= ret
;
376 * Clean disconnect from the session daemon.
377 * On success, return 0. On error, return -1.
379 static int disconnect_sessiond(void)
384 ret
= lttcomm_close_unix_sock(sessiond_socket
);
393 * Ask the session daemon a specific command and put the data into buf.
394 * Takes extra var. len. data as input to send to the session daemon.
396 * Return size of data (only payload, not header) or a negative error code.
399 int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg
*lsm
,
400 void *vardata
, size_t varlen
, void **buf
)
405 struct lttcomm_lttng_msg llm
;
407 ret
= connect_sessiond();
409 ret
= -LTTNG_ERR_NO_SESSIOND
;
413 /* Send command to session daemon */
414 ret
= send_session_msg(lsm
);
416 /* Ret value is a valid lttng error code. */
419 /* Send var len data */
420 ret
= send_session_varlen(vardata
, varlen
);
422 /* Ret value is a valid lttng error code. */
426 /* Get header from data transmission */
427 ret
= recv_data_sessiond(&llm
, sizeof(llm
));
429 /* Ret value is a valid lttng error code. */
433 /* Check error code if OK */
434 if (llm
.ret_code
!= LTTNG_OK
) {
439 size
= llm
.data_size
;
441 /* If client free with size 0 */
449 data
= zmalloc(size
);
455 /* Get payload data */
456 ret
= recv_data_sessiond(data
, size
);
463 * Extra protection not to dereference a NULL pointer. If buf is NULL at
464 * this point, an error is returned and data is freed.
467 ret
= -LTTNG_ERR_INVALID
;
476 disconnect_sessiond();
481 * Create lttng handle and return pointer.
482 * The returned pointer will be NULL in case of malloc() error.
484 struct lttng_handle
*lttng_create_handle(const char *session_name
,
485 struct lttng_domain
*domain
)
487 struct lttng_handle
*handle
= NULL
;
489 if (domain
== NULL
) {
493 handle
= zmalloc(sizeof(struct lttng_handle
));
494 if (handle
== NULL
) {
495 PERROR("malloc handle");
499 /* Copy session name */
500 lttng_ctl_copy_string(handle
->session_name
, session_name
,
501 sizeof(handle
->session_name
));
503 /* Copy lttng domain */
504 lttng_ctl_copy_lttng_domain(&handle
->domain
, domain
);
511 * Destroy handle by free(3) the pointer.
513 void lttng_destroy_handle(struct lttng_handle
*handle
)
519 * Register an outside consumer.
520 * Returns size of returned session payload data or a negative error code.
522 int lttng_register_consumer(struct lttng_handle
*handle
,
523 const char *socket_path
)
525 struct lttcomm_session_msg lsm
;
527 if (handle
== NULL
|| socket_path
== NULL
) {
528 return -LTTNG_ERR_INVALID
;
531 memset(&lsm
, 0, sizeof(lsm
));
532 lsm
.cmd_type
= LTTNG_REGISTER_CONSUMER
;
533 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
534 sizeof(lsm
.session
.name
));
535 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
537 lttng_ctl_copy_string(lsm
.u
.reg
.path
, socket_path
, sizeof(lsm
.u
.reg
.path
));
539 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
543 * Start tracing for all traces of the session.
544 * Returns size of returned session payload data or a negative error code.
546 int lttng_start_tracing(const char *session_name
)
548 struct lttcomm_session_msg lsm
;
550 if (session_name
== NULL
) {
551 return -LTTNG_ERR_INVALID
;
554 memset(&lsm
, 0, sizeof(lsm
));
555 lsm
.cmd_type
= LTTNG_START_TRACE
;
557 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
558 sizeof(lsm
.session
.name
));
560 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
564 * Stop tracing for all traces of the session.
566 static int _lttng_stop_tracing(const char *session_name
, int wait
)
569 struct lttcomm_session_msg lsm
;
571 if (session_name
== NULL
) {
572 return -LTTNG_ERR_INVALID
;
575 memset(&lsm
, 0, sizeof(lsm
));
576 lsm
.cmd_type
= LTTNG_STOP_TRACE
;
578 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
579 sizeof(lsm
.session
.name
));
581 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
582 if (ret
< 0 && ret
!= -LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
590 /* Check for data availability */
592 data_ret
= lttng_data_pending(session_name
);
594 /* Return the data available call error. */
600 * Data sleep time before retrying (in usec). Don't sleep if the call
601 * returned value indicates availability.
604 usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME
);
606 } while (data_ret
!= 0);
614 * Stop tracing and wait for data availability.
616 int lttng_stop_tracing(const char *session_name
)
618 return _lttng_stop_tracing(session_name
, 1);
622 * Stop tracing but _don't_ wait for data availability.
624 int lttng_stop_tracing_no_wait(const char *session_name
)
626 return _lttng_stop_tracing(session_name
, 0);
630 * Add context to a channel.
632 * If the given channel is NULL, add the contexts to all channels.
633 * The event_name param is ignored.
635 * Returns the size of the returned payload data or a negative error code.
637 int lttng_add_context(struct lttng_handle
*handle
,
638 struct lttng_event_context
*ctx
, const char *event_name
,
639 const char *channel_name
)
641 struct lttcomm_session_msg lsm
;
643 /* Safety check. Both are mandatory */
644 if (handle
== NULL
|| ctx
== NULL
) {
645 return -LTTNG_ERR_INVALID
;
648 memset(&lsm
, 0, sizeof(lsm
));
650 lsm
.cmd_type
= LTTNG_ADD_CONTEXT
;
652 /* If no channel name, send empty string. */
653 if (channel_name
== NULL
) {
654 lttng_ctl_copy_string(lsm
.u
.context
.channel_name
, "",
655 sizeof(lsm
.u
.context
.channel_name
));
657 lttng_ctl_copy_string(lsm
.u
.context
.channel_name
, channel_name
,
658 sizeof(lsm
.u
.context
.channel_name
));
661 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
663 memcpy(&lsm
.u
.context
.ctx
, ctx
, sizeof(struct lttng_event_context
));
665 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
666 sizeof(lsm
.session
.name
));
668 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
672 * Enable event(s) for a channel.
673 * If no event name is specified, all events are enabled.
674 * If no channel name is specified, the default 'channel0' is used.
675 * Returns size of returned session payload data or a negative error code.
677 int lttng_enable_event(struct lttng_handle
*handle
,
678 struct lttng_event
*ev
, const char *channel_name
)
680 return lttng_enable_event_with_exclusions(handle
, ev
, channel_name
,
685 * Create or enable an event with a filter expression.
687 * Return negative error value on error.
688 * Return size of returned session payload data if OK.
690 int lttng_enable_event_with_filter(struct lttng_handle
*handle
,
691 struct lttng_event
*event
, const char *channel_name
,
692 const char *filter_expression
)
694 return lttng_enable_event_with_exclusions(handle
, event
, channel_name
,
695 filter_expression
, 0, NULL
);
699 * Depending on the event, return a newly allocated agent filter expression or
700 * NULL if not applicable.
702 * An event with NO loglevel and the name is * will return NULL.
704 static char *set_agent_filter(const char *filter
, struct lttng_event
*ev
)
707 char *agent_filter
= NULL
;
711 /* Don't add filter for the '*' event. */
712 if (ev
->name
[0] != '*') {
714 err
= asprintf(&agent_filter
, "(%s) && (logger_name == \"%s\")", filter
,
717 err
= asprintf(&agent_filter
, "logger_name == \"%s\"", ev
->name
);
725 /* Add loglevel filtering if any for the JUL domain. */
726 if (ev
->loglevel_type
!= LTTNG_EVENT_LOGLEVEL_ALL
) {
729 if (ev
->loglevel_type
== LTTNG_EVENT_LOGLEVEL_RANGE
) {
735 if (filter
|| agent_filter
) {
738 err
= asprintf(&new_filter
, "(%s) && (int_loglevel %s %d)",
739 agent_filter
? agent_filter
: filter
, op
,
744 agent_filter
= new_filter
;
746 err
= asprintf(&agent_filter
, "int_loglevel %s %d", op
,
762 * Generate the filter bytecode from a give filter expression string. Put the
763 * newly allocated parser context in ctxp and populate the lsm object with the
766 * Return 0 on success else a LTTNG_ERR_* code and ctxp is untouched.
768 static int generate_filter(char *filter_expression
,
769 struct lttcomm_session_msg
*lsm
, struct filter_parser_ctx
**ctxp
)
772 struct filter_parser_ctx
*ctx
= NULL
;
775 assert(filter_expression
);
780 * Casting const to non-const, as the underlying function will use it in
783 fmem
= lttng_fmemopen((void *) filter_expression
,
784 strlen(filter_expression
), "r");
786 fprintf(stderr
, "Error opening memory as stream\n");
787 ret
= -LTTNG_ERR_FILTER_NOMEM
;
790 ctx
= filter_parser_ctx_alloc(fmem
);
792 fprintf(stderr
, "Error allocating parser\n");
793 ret
= -LTTNG_ERR_FILTER_NOMEM
;
794 goto filter_alloc_error
;
796 ret
= filter_parser_ctx_append_ast(ctx
);
798 fprintf(stderr
, "Parse error\n");
799 ret
= -LTTNG_ERR_FILTER_INVAL
;
802 ret
= filter_visitor_set_parent(ctx
);
804 fprintf(stderr
, "Set parent error\n");
805 ret
= -LTTNG_ERR_FILTER_INVAL
;
809 ret
= filter_visitor_print_xml(ctx
, stdout
, 0);
812 fprintf(stderr
, "XML print error\n");
813 ret
= -LTTNG_ERR_FILTER_INVAL
;
818 dbg_printf("Generating IR... ");
820 ret
= filter_visitor_ir_generate(ctx
);
822 fprintf(stderr
, "Generate IR error\n");
823 ret
= -LTTNG_ERR_FILTER_INVAL
;
826 dbg_printf("done\n");
828 dbg_printf("Validating IR... ");
830 ret
= filter_visitor_ir_check_binary_op_nesting(ctx
);
832 ret
= -LTTNG_ERR_FILTER_INVAL
;
835 /* Validate strings used as literals in the expression */
836 ret
= filter_visitor_ir_validate_string(ctx
);
838 ret
= -LTTNG_ERR_FILTER_INVAL
;
841 dbg_printf("done\n");
843 dbg_printf("Generating bytecode... ");
845 ret
= filter_visitor_bytecode_generate(ctx
);
847 fprintf(stderr
, "Generate bytecode error\n");
848 ret
= -LTTNG_ERR_FILTER_INVAL
;
851 dbg_printf("done\n");
852 dbg_printf("Size of bytecode generated: %u bytes.\n",
853 bytecode_get_len(&ctx
->bytecode
->b
));
855 lsm
->u
.enable
.bytecode_len
= sizeof(ctx
->bytecode
->b
)
856 + bytecode_get_len(&ctx
->bytecode
->b
);
857 lsm
->u
.enable
.expression_len
= strlen(filter_expression
) + 1;
859 /* No need to keep the memory stream. */
860 if (fclose(fmem
) != 0) {
869 filter_parser_ctx_free(ctx
);
871 if (fclose(fmem
) != 0) {
879 * Enable event(s) for a channel, possibly with exclusions and a filter.
880 * If no event name is specified, all events are enabled.
881 * If no channel name is specified, the default name is used.
882 * If filter expression is not NULL, the filter is set for the event.
883 * If exclusion count is not zero, the exclusions are set for the event.
884 * Returns size of returned session payload data or a negative error code.
886 int lttng_enable_event_with_exclusions(struct lttng_handle
*handle
,
887 struct lttng_event
*ev
, const char *channel_name
,
888 const char *original_filter_expression
,
889 int exclusion_count
, char **exclusion_list
)
891 struct lttcomm_session_msg lsm
;
894 unsigned int free_filter_expression
= 0;
895 struct filter_parser_ctx
*ctx
= NULL
;
897 * Cast as non-const since we may replace the filter expression
898 * by a dynamically allocated string. Otherwise, the original
899 * string is not modified.
901 char *filter_expression
= (char *) original_filter_expression
;
903 if (handle
== NULL
|| ev
== NULL
) {
904 ret
= -LTTNG_ERR_INVALID
;
908 /* Empty filter string will always be rejected by the parser
909 * anyway, so treat this corner-case early to eliminate
910 * lttng_fmemopen error for 0-byte allocation.
912 if (filter_expression
&& filter_expression
[0] == '\0') {
913 ret
= -LTTNG_ERR_INVALID
;
917 memset(&lsm
, 0, sizeof(lsm
));
919 /* If no channel name, send empty string. */
920 if (channel_name
== NULL
) {
921 lttng_ctl_copy_string(lsm
.u
.enable
.channel_name
, "",
922 sizeof(lsm
.u
.enable
.channel_name
));
924 lttng_ctl_copy_string(lsm
.u
.enable
.channel_name
, channel_name
,
925 sizeof(lsm
.u
.enable
.channel_name
));
928 lsm
.cmd_type
= LTTNG_ENABLE_EVENT
;
929 if (ev
->name
[0] == '\0') {
930 /* Enable all events */
931 lttng_ctl_copy_string(ev
->name
, "*", sizeof(ev
->name
));
934 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
935 /* FIXME: copying non-packed struct to packed struct. */
936 memcpy(&lsm
.u
.enable
.event
, ev
, sizeof(lsm
.u
.enable
.event
));
938 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
939 sizeof(lsm
.session
.name
));
940 lsm
.u
.enable
.exclusion_count
= exclusion_count
;
941 lsm
.u
.enable
.bytecode_len
= 0;
944 * For the JUL domain, a filter is enforced except for the enable all
945 * event. This is done to avoid having the event in all sessions thus
946 * filtering by logger name.
948 if (exclusion_count
== 0 && filter_expression
== NULL
&&
949 (handle
->domain
.type
!= LTTNG_DOMAIN_JUL
&&
950 handle
->domain
.type
!= LTTNG_DOMAIN_LOG4J
&&
951 handle
->domain
.type
!= LTTNG_DOMAIN_PYTHON
)) {
956 * We have either a filter or some exclusions, so we need to set up
957 * a variable-length memory block from where to send the data
960 /* Parse filter expression */
961 if (filter_expression
!= NULL
|| handle
->domain
.type
== LTTNG_DOMAIN_JUL
962 || handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
963 || handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
964 if (handle
->domain
.type
== LTTNG_DOMAIN_JUL
||
965 handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
||
966 handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
969 /* Setup JUL filter if needed. */
970 agent_filter
= set_agent_filter(filter_expression
, ev
);
972 if (!filter_expression
) {
973 /* No JUL and no filter, just skip everything below. */
978 * With an agent filter, the original filter has been added to
979 * it thus replace the filter expression.
981 filter_expression
= agent_filter
;
982 free_filter_expression
= 1;
986 ret
= generate_filter(filter_expression
, &lsm
, &ctx
);
992 varlen_data
= zmalloc(lsm
.u
.enable
.bytecode_len
993 + lsm
.u
.enable
.expression_len
994 + LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
996 ret
= -LTTNG_ERR_EXCLUSION_NOMEM
;
1000 /* Put exclusion names first in the data */
1001 while (exclusion_count
--) {
1002 strncpy(varlen_data
+ LTTNG_SYMBOL_NAME_LEN
* exclusion_count
,
1003 *(exclusion_list
+ exclusion_count
), LTTNG_SYMBOL_NAME_LEN
);
1005 /* Add filter expression next */
1006 if (lsm
.u
.enable
.expression_len
!= 0) {
1008 + LTTNG_SYMBOL_NAME_LEN
* lsm
.u
.enable
.exclusion_count
,
1010 lsm
.u
.enable
.expression_len
);
1012 /* Add filter bytecode next */
1013 if (ctx
&& lsm
.u
.enable
.bytecode_len
!= 0) {
1015 + LTTNG_SYMBOL_NAME_LEN
* lsm
.u
.enable
.exclusion_count
1016 + lsm
.u
.enable
.expression_len
,
1018 lsm
.u
.enable
.bytecode_len
);
1021 ret
= lttng_ctl_ask_sessiond_varlen(&lsm
, varlen_data
,
1022 (LTTNG_SYMBOL_NAME_LEN
* lsm
.u
.enable
.exclusion_count
) +
1023 lsm
.u
.enable
.bytecode_len
+ lsm
.u
.enable
.expression_len
, NULL
);
1027 if (filter_expression
&& ctx
) {
1028 filter_bytecode_free(ctx
);
1029 filter_ir_free(ctx
);
1030 filter_parser_ctx_free(ctx
);
1033 if (free_filter_expression
) {
1035 * The filter expression has been replaced and must be freed as it is
1036 * not the original filter expression received as a parameter.
1038 free(filter_expression
);
1042 * Return directly to the caller and don't ask the sessiond since something
1043 * went wrong in the parsing of data above.
1048 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1052 int lttng_disable_event_ext(struct lttng_handle
*handle
,
1053 struct lttng_event
*ev
, const char *channel_name
,
1054 const char *original_filter_expression
)
1056 struct lttcomm_session_msg lsm
;
1059 unsigned int free_filter_expression
= 0;
1060 struct filter_parser_ctx
*ctx
= NULL
;
1062 * Cast as non-const since we may replace the filter expression
1063 * by a dynamically allocated string. Otherwise, the original
1064 * string is not modified.
1066 char *filter_expression
= (char *) original_filter_expression
;
1068 if (handle
== NULL
|| ev
== NULL
) {
1069 ret
= -LTTNG_ERR_INVALID
;
1073 /* Empty filter string will always be rejected by the parser
1074 * anyway, so treat this corner-case early to eliminate
1075 * lttng_fmemopen error for 0-byte allocation.
1077 if (filter_expression
&& filter_expression
[0] == '\0') {
1078 ret
= -LTTNG_ERR_INVALID
;
1082 memset(&lsm
, 0, sizeof(lsm
));
1084 /* If no channel name, send empty string. */
1085 if (channel_name
== NULL
) {
1086 lttng_ctl_copy_string(lsm
.u
.disable
.channel_name
, "",
1087 sizeof(lsm
.u
.disable
.channel_name
));
1089 lttng_ctl_copy_string(lsm
.u
.disable
.channel_name
, channel_name
,
1090 sizeof(lsm
.u
.disable
.channel_name
));
1093 lsm
.cmd_type
= LTTNG_DISABLE_EVENT
;
1094 if (ev
->name
[0] == '\0') {
1095 /* Disable all events */
1096 lttng_ctl_copy_string(ev
->name
, "*", sizeof(ev
->name
));
1099 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1100 /* FIXME: copying non-packed struct to packed struct. */
1101 memcpy(&lsm
.u
.disable
.event
, ev
, sizeof(lsm
.u
.disable
.event
));
1103 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1104 sizeof(lsm
.session
.name
));
1105 lsm
.u
.disable
.bytecode_len
= 0;
1108 * For the JUL domain, a filter is enforced except for the
1109 * disable all event. This is done to avoid having the event in
1110 * all sessions thus filtering by logger name.
1112 if (filter_expression
== NULL
&&
1113 (handle
->domain
.type
!= LTTNG_DOMAIN_JUL
&&
1114 handle
->domain
.type
!= LTTNG_DOMAIN_LOG4J
&&
1115 handle
->domain
.type
!= LTTNG_DOMAIN_PYTHON
)) {
1120 * We have a filter, so we need to set up a variable-length
1121 * memory block from where to send the data.
1124 /* Parse filter expression */
1125 if (filter_expression
!= NULL
|| handle
->domain
.type
== LTTNG_DOMAIN_JUL
1126 || handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
1127 || handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1128 if (handle
->domain
.type
== LTTNG_DOMAIN_JUL
||
1129 handle
->domain
.type
== LTTNG_DOMAIN_LOG4J
||
1130 handle
->domain
.type
== LTTNG_DOMAIN_PYTHON
) {
1133 /* Setup JUL filter if needed. */
1134 agent_filter
= set_agent_filter(filter_expression
, ev
);
1135 if (!agent_filter
) {
1136 if (!filter_expression
) {
1137 /* No JUL and no filter, just skip everything below. */
1142 * With a JUL filter, the original filter has been added to it
1143 * thus replace the filter expression.
1145 filter_expression
= agent_filter
;
1146 free_filter_expression
= 1;
1150 ret
= generate_filter(filter_expression
, &lsm
, &ctx
);
1156 varlen_data
= zmalloc(lsm
.u
.disable
.bytecode_len
1157 + lsm
.u
.disable
.expression_len
);
1159 ret
= -LTTNG_ERR_EXCLUSION_NOMEM
;
1163 /* Add filter expression */
1164 if (lsm
.u
.disable
.expression_len
!= 0) {
1167 lsm
.u
.disable
.expression_len
);
1169 /* Add filter bytecode next */
1170 if (ctx
&& lsm
.u
.disable
.bytecode_len
!= 0) {
1172 + lsm
.u
.disable
.expression_len
,
1174 lsm
.u
.disable
.bytecode_len
);
1177 ret
= lttng_ctl_ask_sessiond_varlen(&lsm
, varlen_data
,
1178 lsm
.u
.disable
.bytecode_len
+ lsm
.u
.disable
.expression_len
, NULL
);
1182 if (filter_expression
&& ctx
) {
1183 filter_bytecode_free(ctx
);
1184 filter_ir_free(ctx
);
1185 filter_parser_ctx_free(ctx
);
1188 if (free_filter_expression
) {
1190 * The filter expression has been replaced and must be freed as it is
1191 * not the original filter expression received as a parameter.
1193 free(filter_expression
);
1197 * Return directly to the caller and don't ask the sessiond since something
1198 * went wrong in the parsing of data above.
1203 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1208 * Disable event(s) of a channel and domain.
1209 * If no event name is specified, all events are disabled.
1210 * If no channel name is specified, the default 'channel0' is used.
1211 * Returns size of returned session payload data or a negative error code.
1213 int lttng_disable_event(struct lttng_handle
*handle
, const char *name
,
1214 const char *channel_name
)
1216 struct lttng_event ev
;
1218 memset(&ev
, 0, sizeof(ev
));
1220 ev
.type
= LTTNG_EVENT_ALL
;
1221 lttng_ctl_copy_string(ev
.name
, name
, sizeof(ev
.name
));
1222 return lttng_disable_event_ext(handle
, &ev
, channel_name
, NULL
);
1226 * Enable channel per domain
1227 * Returns size of returned session payload data or a negative error code.
1229 int lttng_enable_channel(struct lttng_handle
*handle
,
1230 struct lttng_channel
*chan
)
1232 struct lttcomm_session_msg lsm
;
1235 * NULL arguments are forbidden. No default values.
1237 if (handle
== NULL
|| chan
== NULL
) {
1238 return -LTTNG_ERR_INVALID
;
1241 memset(&lsm
, 0, sizeof(lsm
));
1243 memcpy(&lsm
.u
.channel
.chan
, chan
, sizeof(lsm
.u
.channel
.chan
));
1245 lsm
.cmd_type
= LTTNG_ENABLE_CHANNEL
;
1247 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1249 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1250 sizeof(lsm
.session
.name
));
1252 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1256 * All tracing will be stopped for registered events of the channel.
1257 * Returns size of returned session payload data or a negative error code.
1259 int lttng_disable_channel(struct lttng_handle
*handle
, const char *name
)
1261 struct lttcomm_session_msg lsm
;
1263 /* Safety check. Both are mandatory */
1264 if (handle
== NULL
|| name
== NULL
) {
1265 return -LTTNG_ERR_INVALID
;
1268 memset(&lsm
, 0, sizeof(lsm
));
1270 lsm
.cmd_type
= LTTNG_DISABLE_CHANNEL
;
1272 lttng_ctl_copy_string(lsm
.u
.disable
.channel_name
, name
,
1273 sizeof(lsm
.u
.disable
.channel_name
));
1275 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1277 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1278 sizeof(lsm
.session
.name
));
1280 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1284 * Lists all available tracepoints of domain.
1285 * Sets the contents of the events array.
1286 * Returns the number of lttng_event entries in events;
1287 * on error, returns a negative value.
1289 int lttng_list_tracepoints(struct lttng_handle
*handle
,
1290 struct lttng_event
**events
)
1293 struct lttcomm_session_msg lsm
;
1295 if (handle
== NULL
) {
1296 return -LTTNG_ERR_INVALID
;
1299 memset(&lsm
, 0, sizeof(lsm
));
1300 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINTS
;
1301 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1303 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) events
);
1308 return ret
/ sizeof(struct lttng_event
);
1312 * Lists all available tracepoint fields of domain.
1313 * Sets the contents of the event field array.
1314 * Returns the number of lttng_event_field entries in events;
1315 * on error, returns a negative value.
1317 int lttng_list_tracepoint_fields(struct lttng_handle
*handle
,
1318 struct lttng_event_field
**fields
)
1321 struct lttcomm_session_msg lsm
;
1323 if (handle
== NULL
) {
1324 return -LTTNG_ERR_INVALID
;
1327 memset(&lsm
, 0, sizeof(lsm
));
1328 lsm
.cmd_type
= LTTNG_LIST_TRACEPOINT_FIELDS
;
1329 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1331 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) fields
);
1336 return ret
/ sizeof(struct lttng_event_field
);
1340 * Lists all available kernel system calls. Allocates and sets the contents of
1343 * Returns the number of lttng_event entries in events; on error, returns a
1346 int lttng_list_syscalls(struct lttng_event
**events
)
1349 struct lttcomm_session_msg lsm
;
1352 return -LTTNG_ERR_INVALID
;
1355 memset(&lsm
, 0, sizeof(lsm
));
1356 lsm
.cmd_type
= LTTNG_LIST_SYSCALLS
;
1357 /* Force kernel domain for system calls. */
1358 lsm
.domain
.type
= LTTNG_DOMAIN_KERNEL
;
1360 ret
= lttng_ctl_ask_sessiond(&lsm
, (void **) events
);
1365 return ret
/ sizeof(struct lttng_event
);
1369 * Returns a human readable string describing
1370 * the error code (a negative value).
1372 const char *lttng_strerror(int code
)
1374 return error_get_str(code
);
1378 * Create a brand new session using name and url for destination.
1380 * Returns LTTNG_OK on success or a negative error code.
1382 int lttng_create_session(const char *name
, const char *url
)
1386 struct lttcomm_session_msg lsm
;
1387 struct lttng_uri
*uris
= NULL
;
1390 return -LTTNG_ERR_INVALID
;
1393 memset(&lsm
, 0, sizeof(lsm
));
1395 lsm
.cmd_type
= LTTNG_CREATE_SESSION
;
1396 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
1398 /* There should never be a data URL */
1399 size
= uri_parse_str_urls(url
, NULL
, &uris
);
1401 return -LTTNG_ERR_INVALID
;
1404 lsm
.u
.uri
.size
= size
;
1406 ret
= lttng_ctl_ask_sessiond_varlen(&lsm
, uris
,
1407 sizeof(struct lttng_uri
) * size
, NULL
);
1414 * Destroy session using name.
1415 * Returns size of returned session payload data or a negative error code.
1417 int lttng_destroy_session(const char *session_name
)
1419 struct lttcomm_session_msg lsm
;
1421 if (session_name
== NULL
) {
1422 return -LTTNG_ERR_INVALID
;
1425 memset(&lsm
, 0, sizeof(lsm
));
1426 lsm
.cmd_type
= LTTNG_DESTROY_SESSION
;
1428 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
1429 sizeof(lsm
.session
.name
));
1431 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1435 * Ask the session daemon for all available sessions.
1436 * Sets the contents of the sessions array.
1437 * Returns the number of lttng_session entries in sessions;
1438 * on error, returns a negative value.
1440 int lttng_list_sessions(struct lttng_session
**sessions
)
1443 struct lttcomm_session_msg lsm
;
1445 memset(&lsm
, 0, sizeof(lsm
));
1446 lsm
.cmd_type
= LTTNG_LIST_SESSIONS
;
1447 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) sessions
);
1452 return ret
/ sizeof(struct lttng_session
);
1456 * Ask the session daemon for all available domains of a session.
1457 * Sets the contents of the domains array.
1458 * Returns the number of lttng_domain entries in domains;
1459 * on error, returns a negative value.
1461 int lttng_list_domains(const char *session_name
,
1462 struct lttng_domain
**domains
)
1465 struct lttcomm_session_msg lsm
;
1467 if (session_name
== NULL
) {
1468 return -LTTNG_ERR_INVALID
;
1471 memset(&lsm
, 0, sizeof(lsm
));
1472 lsm
.cmd_type
= LTTNG_LIST_DOMAINS
;
1474 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
1475 sizeof(lsm
.session
.name
));
1477 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) domains
);
1482 return ret
/ sizeof(struct lttng_domain
);
1486 * Ask the session daemon for all available channels of a session.
1487 * Sets the contents of the channels array.
1488 * Returns the number of lttng_channel entries in channels;
1489 * on error, returns a negative value.
1491 int lttng_list_channels(struct lttng_handle
*handle
,
1492 struct lttng_channel
**channels
)
1495 struct lttcomm_session_msg lsm
;
1497 if (handle
== NULL
) {
1498 return -LTTNG_ERR_INVALID
;
1501 memset(&lsm
, 0, sizeof(lsm
));
1502 lsm
.cmd_type
= LTTNG_LIST_CHANNELS
;
1503 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1504 sizeof(lsm
.session
.name
));
1506 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1508 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) channels
);
1513 return ret
/ sizeof(struct lttng_channel
);
1517 * Ask the session daemon for all available events of a session channel.
1518 * Sets the contents of the events array.
1519 * Returns the number of lttng_event entries in events;
1520 * on error, returns a negative value.
1522 int lttng_list_events(struct lttng_handle
*handle
,
1523 const char *channel_name
, struct lttng_event
**events
)
1526 struct lttcomm_session_msg lsm
;
1528 /* Safety check. An handle and channel name are mandatory */
1529 if (handle
== NULL
|| channel_name
== NULL
) {
1530 return -LTTNG_ERR_INVALID
;
1533 memset(&lsm
, 0, sizeof(lsm
));
1534 lsm
.cmd_type
= LTTNG_LIST_EVENTS
;
1535 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1536 sizeof(lsm
.session
.name
));
1537 lttng_ctl_copy_string(lsm
.u
.list
.channel_name
, channel_name
,
1538 sizeof(lsm
.u
.list
.channel_name
));
1540 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1542 ret
= lttng_ctl_ask_sessiond(&lsm
, (void**) events
);
1547 return ret
/ sizeof(struct lttng_event
);
1551 * Sets the tracing_group variable with name.
1552 * This function allocates memory pointed to by tracing_group.
1553 * On success, returns 0, on error, returns -1 (null name) or -ENOMEM.
1555 int lttng_set_tracing_group(const char *name
)
1558 return -LTTNG_ERR_INVALID
;
1561 if (asprintf(&tracing_group
, "%s", name
) < 0) {
1562 return -LTTNG_ERR_FATAL
;
1569 * Returns size of returned session payload data or a negative error code.
1571 int lttng_calibrate(struct lttng_handle
*handle
,
1572 struct lttng_calibrate
*calibrate
)
1574 struct lttcomm_session_msg lsm
;
1576 /* Safety check. NULL pointer are forbidden */
1577 if (handle
== NULL
|| calibrate
== NULL
) {
1578 return -LTTNG_ERR_INVALID
;
1581 memset(&lsm
, 0, sizeof(lsm
));
1582 lsm
.cmd_type
= LTTNG_CALIBRATE
;
1583 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1585 memcpy(&lsm
.u
.calibrate
, calibrate
, sizeof(lsm
.u
.calibrate
));
1587 return lttng_ctl_ask_sessiond(&lsm
, NULL
);
1591 * Set default channel attributes.
1592 * If either or both of the arguments are null, attr content is zeroe'd.
1594 void lttng_channel_set_default_attr(struct lttng_domain
*domain
,
1595 struct lttng_channel_attr
*attr
)
1598 if (attr
== NULL
|| domain
== NULL
) {
1602 memset(attr
, 0, sizeof(struct lttng_channel_attr
));
1604 /* Same for all domains. */
1605 attr
->overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
1606 attr
->tracefile_size
= DEFAULT_CHANNEL_TRACEFILE_SIZE
;
1607 attr
->tracefile_count
= DEFAULT_CHANNEL_TRACEFILE_COUNT
;
1609 switch (domain
->type
) {
1610 case LTTNG_DOMAIN_KERNEL
:
1611 attr
->switch_timer_interval
= DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER
;
1612 attr
->read_timer_interval
= DEFAULT_KERNEL_CHANNEL_READ_TIMER
;
1613 attr
->subbuf_size
= default_get_kernel_channel_subbuf_size();
1614 attr
->num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
1615 attr
->output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
1617 case LTTNG_DOMAIN_UST
:
1618 switch (domain
->buf_type
) {
1619 case LTTNG_BUFFER_PER_UID
:
1620 attr
->subbuf_size
= default_get_ust_uid_channel_subbuf_size();
1621 attr
->num_subbuf
= DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM
;
1622 attr
->output
= DEFAULT_UST_UID_CHANNEL_OUTPUT
;
1623 attr
->switch_timer_interval
= DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER
;
1624 attr
->read_timer_interval
= DEFAULT_UST_UID_CHANNEL_READ_TIMER
;
1626 case LTTNG_BUFFER_PER_PID
:
1628 attr
->subbuf_size
= default_get_ust_pid_channel_subbuf_size();
1629 attr
->num_subbuf
= DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM
;
1630 attr
->output
= DEFAULT_UST_PID_CHANNEL_OUTPUT
;
1631 attr
->switch_timer_interval
= DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER
;
1632 attr
->read_timer_interval
= DEFAULT_UST_PID_CHANNEL_READ_TIMER
;
1636 /* Default behavior: leave set to 0. */
1642 * Check if session daemon is alive.
1644 * Return 1 if alive or 0 if not.
1645 * On error returns a negative value.
1647 int lttng_session_daemon_alive(void)
1651 ret
= set_session_daemon_path();
1657 if (*sessiond_sock_path
== '\0') {
1659 * No socket path set. Weird error which means the constructor was not
1665 ret
= try_connect_sessiond(sessiond_sock_path
);
1676 * Set URL for a consumer for a session and domain.
1678 * Return 0 on success, else a negative value.
1680 int lttng_set_consumer_url(struct lttng_handle
*handle
,
1681 const char *control_url
, const char *data_url
)
1685 struct lttcomm_session_msg lsm
;
1686 struct lttng_uri
*uris
= NULL
;
1688 if (handle
== NULL
|| (control_url
== NULL
&& data_url
== NULL
)) {
1689 return -LTTNG_ERR_INVALID
;
1692 memset(&lsm
, 0, sizeof(lsm
));
1694 lsm
.cmd_type
= LTTNG_SET_CONSUMER_URI
;
1696 lttng_ctl_copy_string(lsm
.session
.name
, handle
->session_name
,
1697 sizeof(lsm
.session
.name
));
1698 lttng_ctl_copy_lttng_domain(&lsm
.domain
, &handle
->domain
);
1700 size
= uri_parse_str_urls(control_url
, data_url
, &uris
);
1702 return -LTTNG_ERR_INVALID
;
1705 lsm
.u
.uri
.size
= size
;
1707 ret
= lttng_ctl_ask_sessiond_varlen(&lsm
, uris
,
1708 sizeof(struct lttng_uri
) * size
, NULL
);
1717 int lttng_enable_consumer(struct lttng_handle
*handle
)
1725 int lttng_disable_consumer(struct lttng_handle
*handle
)
1731 * This is an extension of create session that is ONLY and SHOULD only be used
1732 * by the lttng command line program. It exists to avoid using URI parsing in
1735 * We need the date and time for the trace path subdirectory for the case where
1736 * the user does NOT define one using either -o or -U. Using the normal
1737 * lttng_create_session API call, we have no clue on the session daemon side if
1738 * the URL was generated automatically by the client or define by the user.
1740 * So this function "wrapper" is hidden from the public API, takes the datetime
1741 * string and appends it if necessary to the URI subdirectory before sending it
1742 * to the session daemon.
1744 * With this extra function, the lttng_create_session call behavior is not
1745 * changed and the timestamp is appended to the URI on the session daemon side
1748 int _lttng_create_session_ext(const char *name
, const char *url
,
1749 const char *datetime
)
1753 struct lttcomm_session_msg lsm
;
1754 struct lttng_uri
*uris
= NULL
;
1756 if (name
== NULL
|| datetime
== NULL
) {
1757 return -LTTNG_ERR_INVALID
;
1760 memset(&lsm
, 0, sizeof(lsm
));
1762 lsm
.cmd_type
= LTTNG_CREATE_SESSION
;
1763 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
1765 /* There should never be a data URL */
1766 size
= uri_parse_str_urls(url
, NULL
, &uris
);
1768 ret
= -LTTNG_ERR_INVALID
;
1772 lsm
.u
.uri
.size
= size
;
1774 if (size
> 0 && uris
[0].dtype
!= LTTNG_DST_PATH
&& strlen(uris
[0].subdir
) == 0) {
1775 /* Don't append datetime if the name was automatically created. */
1776 if (strncmp(name
, DEFAULT_SESSION_NAME
"-",
1777 strlen(DEFAULT_SESSION_NAME
) + 1)) {
1778 ret
= snprintf(uris
[0].subdir
, sizeof(uris
[0].subdir
), "%s-%s",
1781 ret
= snprintf(uris
[0].subdir
, sizeof(uris
[0].subdir
), "%s", name
);
1784 PERROR("snprintf uri subdir");
1785 ret
= -LTTNG_ERR_FATAL
;
1790 ret
= lttng_ctl_ask_sessiond_varlen(&lsm
, uris
,
1791 sizeof(struct lttng_uri
) * size
, NULL
);
1799 * For a given session name, this call checks if the data is ready to be read
1800 * or is still being extracted by the consumer(s) hence not ready to be used by
1803 int lttng_data_pending(const char *session_name
)
1806 struct lttcomm_session_msg lsm
;
1808 if (session_name
== NULL
) {
1809 return -LTTNG_ERR_INVALID
;
1812 memset(&lsm
, 0, sizeof(lsm
));
1813 lsm
.cmd_type
= LTTNG_DATA_PENDING
;
1815 lttng_ctl_copy_string(lsm
.session
.name
, session_name
,
1816 sizeof(lsm
.session
.name
));
1818 ret
= lttng_ctl_ask_sessiond(&lsm
, NULL
);
1821 * The lttng_ctl_ask_sessiond function negate the return code if it's not
1822 * LTTNG_OK so getting -1 means that the reply ret_code was 1 thus meaning
1823 * that the data is available. Yes it is hackish but for now this is the
1834 * Create a session exclusively used for snapshot.
1836 * Returns LTTNG_OK on success or a negative error code.
1838 int lttng_create_session_snapshot(const char *name
, const char *snapshot_url
)
1842 struct lttcomm_session_msg lsm
;
1843 struct lttng_uri
*uris
= NULL
;
1846 return -LTTNG_ERR_INVALID
;
1849 memset(&lsm
, 0, sizeof(lsm
));
1851 lsm
.cmd_type
= LTTNG_CREATE_SESSION_SNAPSHOT
;
1852 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
1854 size
= uri_parse_str_urls(snapshot_url
, NULL
, &uris
);
1856 return -LTTNG_ERR_INVALID
;
1859 lsm
.u
.uri
.size
= size
;
1861 ret
= lttng_ctl_ask_sessiond_varlen(&lsm
, uris
,
1862 sizeof(struct lttng_uri
) * size
, NULL
);
1869 * Create a session exclusively used for live.
1871 * Returns LTTNG_OK on success or a negative error code.
1873 int lttng_create_session_live(const char *name
, const char *url
,
1874 unsigned int timer_interval
)
1878 struct lttcomm_session_msg lsm
;
1879 struct lttng_uri
*uris
= NULL
;
1882 return -LTTNG_ERR_INVALID
;
1885 memset(&lsm
, 0, sizeof(lsm
));
1887 lsm
.cmd_type
= LTTNG_CREATE_SESSION_LIVE
;
1888 lttng_ctl_copy_string(lsm
.session
.name
, name
, sizeof(lsm
.session
.name
));
1891 size
= uri_parse_str_urls(url
, NULL
, &uris
);
1893 ret
= -LTTNG_ERR_INVALID
;
1897 /* file:// is not accepted for live session. */
1898 if (uris
[0].dtype
== LTTNG_DST_PATH
) {
1899 ret
= -LTTNG_ERR_INVALID
;
1906 lsm
.u
.session_live
.nb_uri
= size
;
1907 lsm
.u
.session_live
.timer_interval
= timer_interval
;
1909 ret
= lttng_ctl_ask_sessiond_varlen(&lsm
, uris
,
1910 sizeof(struct lttng_uri
) * size
, NULL
);
1920 static void __attribute__((constructor
)) init()
1922 /* Set default session group */
1923 lttng_set_tracing_group(DEFAULT_TRACING_GROUP
);
1929 static void __attribute__((destructor
)) lttng_ctl_exit()
1931 free(tracing_group
);