165fef4dc5c412392fe49daec62be947d4de3853
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.c
1 /*
2 * lttng-ctl.c
3 *
4 * Linux Trace Toolkit Control Library
5 *
6 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
7 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 *
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.
12 *
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.
17 *
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
21 */
22
23 #define _LGPL_SOURCE
24 #include <assert.h>
25 #include <grp.h>
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
31
32 #include <common/common.h>
33 #include <common/compat/string.h>
34 #include <common/defaults.h>
35 #include <common/sessiond-comm/sessiond-comm.h>
36 #include <common/uri.h>
37 #include <common/utils.h>
38 #include <common/dynamic-buffer.h>
39 #include <lttng/lttng.h>
40 #include <lttng/health-internal.h>
41 #include <lttng/trigger/trigger-internal.h>
42 #include <lttng/endpoint.h>
43 #include <lttng/channel-internal.h>
44 #include <lttng/event-internal.h>
45 #include <lttng/userspace-probe-internal.h>
46
47 #include "filter/filter-ast.h"
48 #include "filter/filter-parser.h"
49 #include "filter/filter-bytecode.h"
50 #include "filter/memstream.h"
51 #include "lttng-ctl-helper.h"
52
53 #ifdef DEBUG
54 static const int print_xml = 1;
55 #define dbg_printf(fmt, args...) \
56 printf("[debug liblttng-ctl] " fmt, ## args)
57 #else
58 static const int print_xml = 0;
59 #define dbg_printf(fmt, args...) \
60 do { \
61 /* do nothing but check printf format */ \
62 if (0) \
63 printf("[debug liblttnctl] " fmt, ## args); \
64 } while (0)
65 #endif
66
67
68 /* Socket to session daemon for communication */
69 static int sessiond_socket;
70 static char sessiond_sock_path[PATH_MAX];
71
72 /* Variables */
73 static char *tracing_group;
74 static int connected;
75
76 /* Global */
77
78 /*
79 * Those two variables are used by error.h to silent or control the verbosity of
80 * error message. They are global to the library so application linking with it
81 * are able to compile correctly and also control verbosity of the library.
82 */
83 int lttng_opt_quiet;
84 int lttng_opt_verbose;
85 int lttng_opt_mi;
86
87 /*
88 * Copy string from src to dst and enforce null terminated byte.
89 */
90 LTTNG_HIDDEN
91 void lttng_ctl_copy_string(char *dst, const char *src, size_t len)
92 {
93 if (src && dst) {
94 strncpy(dst, src, len);
95 /* Enforce the NULL terminated byte */
96 dst[len - 1] = '\0';
97 } else if (dst) {
98 dst[0] = '\0';
99 }
100 }
101
102 /*
103 * Copy domain to lttcomm_session_msg domain.
104 *
105 * If domain is unknown, default domain will be the kernel.
106 */
107 LTTNG_HIDDEN
108 void lttng_ctl_copy_lttng_domain(struct lttng_domain *dst,
109 struct lttng_domain *src)
110 {
111 if (src && dst) {
112 switch (src->type) {
113 case LTTNG_DOMAIN_KERNEL:
114 case LTTNG_DOMAIN_UST:
115 case LTTNG_DOMAIN_JUL:
116 case LTTNG_DOMAIN_LOG4J:
117 case LTTNG_DOMAIN_PYTHON:
118 memcpy(dst, src, sizeof(struct lttng_domain));
119 break;
120 default:
121 memset(dst, 0, sizeof(struct lttng_domain));
122 break;
123 }
124 }
125 }
126
127 /*
128 * Send lttcomm_session_msg to the session daemon.
129 *
130 * On success, returns the number of bytes sent (>=0)
131 * On error, returns -1
132 */
133 static int send_session_msg(struct lttcomm_session_msg *lsm)
134 {
135 int ret;
136
137 if (!connected) {
138 ret = -LTTNG_ERR_NO_SESSIOND;
139 goto end;
140 }
141
142 DBG("LSM cmd type : %d", lsm->cmd_type);
143
144 ret = lttcomm_send_creds_unix_sock(sessiond_socket, lsm,
145 sizeof(struct lttcomm_session_msg));
146 if (ret < 0) {
147 ret = -LTTNG_ERR_FATAL;
148 }
149
150 end:
151 return ret;
152 }
153
154 /*
155 * Send var len data to the session daemon.
156 *
157 * On success, returns the number of bytes sent (>=0)
158 * On error, returns -1
159 */
160 static int send_session_varlen(const void *data, size_t len)
161 {
162 int ret;
163
164 if (!connected) {
165 ret = -LTTNG_ERR_NO_SESSIOND;
166 goto end;
167 }
168
169 if (!data || !len) {
170 ret = 0;
171 goto end;
172 }
173
174 ret = lttcomm_send_unix_sock(sessiond_socket, data, len);
175 if (ret < 0) {
176 ret = -LTTNG_ERR_FATAL;
177 }
178
179 end:
180 return ret;
181 }
182
183 /*
184 * Send file descriptors to the session daemon.
185 *
186 * On success, returns the number of bytes sent (>=0)
187 * On error, returns -1
188 */
189 static int send_session_fds(const int *fds, size_t nb_fd)
190 {
191 int ret;
192
193 if (!connected) {
194 ret = -LTTNG_ERR_NO_SESSIOND;
195 goto end;
196 }
197
198 if (!fds || !nb_fd) {
199 ret = 0;
200 goto end;
201 }
202
203 ret = lttcomm_send_fds_unix_sock(sessiond_socket, fds, nb_fd);
204 if (ret < 0) {
205 ret = -LTTNG_ERR_FATAL;
206 }
207
208 end:
209 return ret;
210 }
211
212 /*
213 * Receive data from the sessiond socket.
214 *
215 * On success, returns the number of bytes received (>=0)
216 * On error, returns -1 (recvmsg() error) or -ENOTCONN
217 */
218 static int recv_data_sessiond(void *buf, size_t len)
219 {
220 int ret;
221
222 if (!connected) {
223 ret = -LTTNG_ERR_NO_SESSIOND;
224 goto end;
225 }
226
227 ret = lttcomm_recv_unix_sock(sessiond_socket, buf, len);
228 if (ret < 0) {
229 ret = -LTTNG_ERR_FATAL;
230 }
231
232 end:
233 return ret;
234 }
235
236 /*
237 * Check if we are in the specified group.
238 *
239 * If yes return 1, else return -1.
240 */
241 LTTNG_HIDDEN
242 int lttng_check_tracing_group(void)
243 {
244 struct group *grp_tracing; /* no free(). See getgrnam(3) */
245 gid_t *grp_list;
246 int grp_list_size, grp_id, i;
247 int ret = -1;
248 const char *grp_name = tracing_group;
249
250 /* Get GID of group 'tracing' */
251 grp_tracing = getgrnam(grp_name);
252 if (!grp_tracing) {
253 /* If grp_tracing is NULL, the group does not exist. */
254 goto end;
255 }
256
257 /* Get number of supplementary group IDs */
258 grp_list_size = getgroups(0, NULL);
259 if (grp_list_size < 0) {
260 PERROR("getgroups");
261 goto end;
262 }
263
264 /* Alloc group list of the right size */
265 grp_list = zmalloc(grp_list_size * sizeof(gid_t));
266 if (!grp_list) {
267 PERROR("malloc");
268 goto end;
269 }
270 grp_id = getgroups(grp_list_size, grp_list);
271 if (grp_id < 0) {
272 PERROR("getgroups");
273 goto free_list;
274 }
275
276 for (i = 0; i < grp_list_size; i++) {
277 if (grp_list[i] == grp_tracing->gr_gid) {
278 ret = 1;
279 break;
280 }
281 }
282
283 free_list:
284 free(grp_list);
285
286 end:
287 return ret;
288 }
289
290 static int check_enough_available_memory(size_t num_bytes_requested_per_cpu)
291 {
292 int ret;
293 long num_cpu;
294 size_t best_mem_info;
295 size_t num_bytes_requested_total;
296
297 /*
298 * Get the number of CPU currently online to compute the amount of
299 * memory needed to create a buffer for every CPU.
300 */
301 num_cpu = sysconf(_SC_NPROCESSORS_ONLN);
302 if (num_cpu == -1) {
303 goto error;
304 }
305
306 num_bytes_requested_total = num_bytes_requested_per_cpu * num_cpu;
307
308 /*
309 * Try to get the `MemAvail` field of `/proc/meminfo`. This is the most
310 * reliable estimate we can get but it is only exposed by the kernel
311 * since 3.14. (See Linux kernel commit:
312 * 34e431b0ae398fc54ea69ff85ec700722c9da773)
313 */
314 ret = utils_get_memory_available(&best_mem_info);
315 if (ret >= 0) {
316 goto success;
317 }
318
319 /*
320 * As a backup plan, use `MemTotal` field of `/proc/meminfo`. This
321 * is a sanity check for obvious user error.
322 */
323 ret = utils_get_memory_total(&best_mem_info);
324 if (ret >= 0) {
325 goto success;
326 }
327
328 error:
329 return -1;
330 success:
331 return best_mem_info >= num_bytes_requested_total;
332 }
333
334 /*
335 * Try connect to session daemon with sock_path.
336 *
337 * Return 0 on success, else -1
338 */
339 static int try_connect_sessiond(const char *sock_path)
340 {
341 int ret;
342
343 /* If socket exist, we check if the daemon listens for connect. */
344 ret = access(sock_path, F_OK);
345 if (ret < 0) {
346 /* Not alive */
347 goto error;
348 }
349
350 ret = lttcomm_connect_unix_sock(sock_path);
351 if (ret < 0) {
352 /* Not alive. */
353 goto error;
354 }
355
356 ret = lttcomm_close_unix_sock(ret);
357 if (ret < 0) {
358 PERROR("lttcomm_close_unix_sock");
359 }
360
361 return 0;
362
363 error:
364 return -1;
365 }
366
367 /*
368 * Set sessiond socket path by putting it in the global sessiond_sock_path
369 * variable.
370 *
371 * Returns 0 on success, negative value on failure (the sessiond socket path
372 * is somehow too long or ENOMEM).
373 */
374 static int set_session_daemon_path(void)
375 {
376 int in_tgroup = 0; /* In tracing group. */
377 uid_t uid;
378
379 uid = getuid();
380
381 if (uid != 0) {
382 /* Are we in the tracing group ? */
383 in_tgroup = lttng_check_tracing_group();
384 }
385
386 if ((uid == 0) || in_tgroup) {
387 lttng_ctl_copy_string(sessiond_sock_path,
388 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK, sizeof(sessiond_sock_path));
389 }
390
391 if (uid != 0) {
392 int ret;
393
394 if (in_tgroup) {
395 /* Tracing group. */
396 ret = try_connect_sessiond(sessiond_sock_path);
397 if (ret >= 0) {
398 goto end;
399 }
400 /* Global session daemon not available... */
401 }
402 /* ...or not in tracing group (and not root), default */
403
404 /*
405 * With GNU C < 2.1, snprintf returns -1 if the target buffer
406 * is too small;
407 * With GNU C >= 2.1, snprintf returns the required size
408 * (excluding closing null)
409 */
410 ret = snprintf(sessiond_sock_path, sizeof(sessiond_sock_path),
411 DEFAULT_HOME_CLIENT_UNIX_SOCK, utils_get_home_dir());
412 if ((ret < 0) || (ret >= sizeof(sessiond_sock_path))) {
413 goto error;
414 }
415 }
416 end:
417 return 0;
418
419 error:
420 return -1;
421 }
422
423 /*
424 * Connect to the LTTng session daemon.
425 *
426 * On success, return 0. On error, return -1.
427 */
428 static int connect_sessiond(void)
429 {
430 int ret;
431
432 /* Don't try to connect if already connected. */
433 if (connected) {
434 return 0;
435 }
436
437 ret = set_session_daemon_path();
438 if (ret < 0) {
439 goto error;
440 }
441
442 /* Connect to the sesssion daemon. */
443 ret = lttcomm_connect_unix_sock(sessiond_sock_path);
444 if (ret < 0) {
445 goto error;
446 }
447
448 sessiond_socket = ret;
449 connected = 1;
450
451 return 0;
452
453 error:
454 return -1;
455 }
456
457 /*
458 * Clean disconnect from the session daemon.
459 *
460 * On success, return 0. On error, return -1.
461 */
462 static int disconnect_sessiond(void)
463 {
464 int ret = 0;
465
466 if (connected) {
467 ret = lttcomm_close_unix_sock(sessiond_socket);
468 sessiond_socket = 0;
469 connected = 0;
470 }
471
472 return ret;
473 }
474
475 static int recv_sessiond_optional_data(size_t len, void **user_buf,
476 size_t *user_len)
477 {
478 int ret = 0;
479 void *buf = NULL;
480
481 if (len) {
482 if (!user_len) {
483 ret = -LTTNG_ERR_INVALID;
484 goto end;
485 }
486
487 buf = zmalloc(len);
488 if (!buf) {
489 ret = -ENOMEM;
490 goto end;
491 }
492
493 ret = recv_data_sessiond(buf, len);
494 if (ret < 0) {
495 goto end;
496 }
497
498 if (!user_buf) {
499 ret = -LTTNG_ERR_INVALID;
500 goto end;
501 }
502
503 /* Move ownership of command header buffer to user. */
504 *user_buf = buf;
505 buf = NULL;
506 *user_len = len;
507 } else {
508 /* No command header. */
509 if (user_len) {
510 *user_len = 0;
511 }
512
513 if (user_buf) {
514 *user_buf = NULL;
515 }
516 }
517
518 end:
519 free(buf);
520 return ret;
521 }
522
523 /*
524 * Ask the session daemon a specific command and put the data into buf.
525 * Takes extra var. len. data and file descriptors as input to send to the
526 * session daemon.
527 *
528 * Return size of data (only payload, not header) or a negative error code.
529 */
530 LTTNG_HIDDEN
531 int lttng_ctl_ask_sessiond_fds_varlen(struct lttcomm_session_msg *lsm,
532 const int *fds, size_t nb_fd, const void *vardata,
533 size_t vardata_len, void **user_payload_buf,
534 void **user_cmd_header_buf, size_t *user_cmd_header_len)
535 {
536 int ret;
537 size_t payload_len;
538 struct lttcomm_lttng_msg llm;
539
540 ret = connect_sessiond();
541 if (ret < 0) {
542 ret = -LTTNG_ERR_NO_SESSIOND;
543 goto end;
544 }
545
546 /* Send command to session daemon */
547 ret = send_session_msg(lsm);
548 if (ret < 0) {
549 /* Ret value is a valid lttng error code. */
550 goto end;
551 }
552 /* Send var len data */
553 ret = send_session_varlen(vardata, vardata_len);
554 if (ret < 0) {
555 /* Ret value is a valid lttng error code. */
556 goto end;
557 }
558
559 /* Send fds */
560 ret = send_session_fds(fds, nb_fd);
561 if (ret < 0) {
562 /* Ret value is a valid lttng error code. */
563 goto end;
564 }
565
566 /* Get header from data transmission */
567 ret = recv_data_sessiond(&llm, sizeof(llm));
568 if (ret < 0) {
569 /* Ret value is a valid lttng error code. */
570 goto end;
571 }
572
573 /* Check error code if OK */
574 if (llm.ret_code != LTTNG_OK) {
575 ret = -llm.ret_code;
576 goto end;
577 }
578
579 /* Get command header from data transmission */
580 ret = recv_sessiond_optional_data(llm.cmd_header_size,
581 user_cmd_header_buf, user_cmd_header_len);
582 if (ret < 0) {
583 goto end;
584 }
585
586 /* Get payload from data transmission */
587 ret = recv_sessiond_optional_data(llm.data_size, user_payload_buf,
588 &payload_len);
589 if (ret < 0) {
590 goto end;
591 }
592
593 ret = llm.data_size;
594
595 end:
596 disconnect_sessiond();
597 return ret;
598 }
599
600 /*
601 * Create lttng handle and return pointer.
602 *
603 * The returned pointer will be NULL in case of malloc() error.
604 */
605 struct lttng_handle *lttng_create_handle(const char *session_name,
606 struct lttng_domain *domain)
607 {
608 struct lttng_handle *handle = NULL;
609
610 handle = zmalloc(sizeof(struct lttng_handle));
611 if (handle == NULL) {
612 PERROR("malloc handle");
613 goto end;
614 }
615
616 /* Copy session name */
617 lttng_ctl_copy_string(handle->session_name, session_name,
618 sizeof(handle->session_name));
619
620 /* Copy lttng domain or leave initialized to 0. */
621 if (domain) {
622 lttng_ctl_copy_lttng_domain(&handle->domain, domain);
623 }
624
625 end:
626 return handle;
627 }
628
629 /*
630 * Destroy handle by free(3) the pointer.
631 */
632 void lttng_destroy_handle(struct lttng_handle *handle)
633 {
634 free(handle);
635 }
636
637 /*
638 * Register an outside consumer.
639 *
640 * Returns size of returned session payload data or a negative error code.
641 */
642 int lttng_register_consumer(struct lttng_handle *handle,
643 const char *socket_path)
644 {
645 struct lttcomm_session_msg lsm;
646
647 if (handle == NULL || socket_path == NULL) {
648 return -LTTNG_ERR_INVALID;
649 }
650
651 memset(&lsm, 0, sizeof(lsm));
652 lsm.cmd_type = LTTNG_REGISTER_CONSUMER;
653 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
654 sizeof(lsm.session.name));
655 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
656
657 lttng_ctl_copy_string(lsm.u.reg.path, socket_path,
658 sizeof(lsm.u.reg.path));
659
660 return lttng_ctl_ask_sessiond(&lsm, NULL);
661 }
662
663 /*
664 * Start tracing for all traces of the session.
665 *
666 * Returns size of returned session payload data or a negative error code.
667 */
668 int lttng_start_tracing(const char *session_name)
669 {
670 struct lttcomm_session_msg lsm;
671
672 if (session_name == NULL) {
673 return -LTTNG_ERR_INVALID;
674 }
675
676 memset(&lsm, 0, sizeof(lsm));
677 lsm.cmd_type = LTTNG_START_TRACE;
678
679 lttng_ctl_copy_string(lsm.session.name, session_name,
680 sizeof(lsm.session.name));
681
682 return lttng_ctl_ask_sessiond(&lsm, NULL);
683 }
684
685 /*
686 * Stop tracing for all traces of the session.
687 */
688 static int _lttng_stop_tracing(const char *session_name, int wait)
689 {
690 int ret, data_ret;
691 struct lttcomm_session_msg lsm;
692
693 if (session_name == NULL) {
694 return -LTTNG_ERR_INVALID;
695 }
696
697 memset(&lsm, 0, sizeof(lsm));
698 lsm.cmd_type = LTTNG_STOP_TRACE;
699
700 lttng_ctl_copy_string(lsm.session.name, session_name,
701 sizeof(lsm.session.name));
702
703 ret = lttng_ctl_ask_sessiond(&lsm, NULL);
704 if (ret < 0 && ret != -LTTNG_ERR_TRACE_ALREADY_STOPPED) {
705 goto error;
706 }
707
708 if (!wait) {
709 goto end;
710 }
711
712 /* Check for data availability */
713 do {
714 data_ret = lttng_data_pending(session_name);
715 if (data_ret < 0) {
716 /* Return the data available call error. */
717 ret = data_ret;
718 goto error;
719 }
720
721 /*
722 * Data sleep time before retrying (in usec). Don't sleep if the
723 * call returned value indicates availability.
724 */
725 if (data_ret) {
726 usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME);
727 }
728 } while (data_ret != 0);
729
730 end:
731 error:
732 return ret;
733 }
734
735 /*
736 * Stop tracing and wait for data availability.
737 */
738 int lttng_stop_tracing(const char *session_name)
739 {
740 return _lttng_stop_tracing(session_name, 1);
741 }
742
743 /*
744 * Stop tracing but _don't_ wait for data availability.
745 */
746 int lttng_stop_tracing_no_wait(const char *session_name)
747 {
748 return _lttng_stop_tracing(session_name, 0);
749 }
750
751 /*
752 * Add context to a channel.
753 *
754 * If the given channel is NULL, add the contexts to all channels.
755 * The event_name param is ignored.
756 *
757 * Returns the size of the returned payload data or a negative error code.
758 */
759 int lttng_add_context(struct lttng_handle *handle,
760 struct lttng_event_context *ctx, const char *event_name,
761 const char *channel_name)
762 {
763 int ret;
764 size_t len = 0;
765 char *buf = NULL;
766 struct lttcomm_session_msg lsm;
767
768 /* Safety check. Both are mandatory. */
769 if (handle == NULL || ctx == NULL) {
770 ret = -LTTNG_ERR_INVALID;
771 goto end;
772 }
773
774 memset(&lsm, 0, sizeof(lsm));
775 lsm.cmd_type = LTTNG_ADD_CONTEXT;
776
777 /* If no channel name, send empty string. */
778 if (channel_name == NULL) {
779 lttng_ctl_copy_string(lsm.u.context.channel_name, "",
780 sizeof(lsm.u.context.channel_name));
781 } else {
782 lttng_ctl_copy_string(lsm.u.context.channel_name, channel_name,
783 sizeof(lsm.u.context.channel_name));
784 }
785
786 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
787 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
788 sizeof(lsm.session.name));
789
790 if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
791 size_t provider_len, ctx_len;
792 const char *provider_name = ctx->u.app_ctx.provider_name;
793 const char *ctx_name = ctx->u.app_ctx.ctx_name;
794
795 if (!provider_name || !ctx_name) {
796 ret = -LTTNG_ERR_INVALID;
797 goto end;
798 }
799
800 provider_len = strlen(provider_name);
801 if (provider_len == 0) {
802 ret = -LTTNG_ERR_INVALID;
803 goto end;
804 }
805 lsm.u.context.provider_name_len = provider_len;
806
807 ctx_len = strlen(ctx_name);
808 if (ctx_len == 0) {
809 ret = -LTTNG_ERR_INVALID;
810 goto end;
811 }
812 lsm.u.context.context_name_len = ctx_len;
813
814 len = provider_len + ctx_len;
815 buf = zmalloc(len);
816 if (!buf) {
817 ret = -LTTNG_ERR_NOMEM;
818 goto end;
819 }
820
821 memcpy(buf, provider_name, provider_len);
822 memcpy(buf + provider_len, ctx_name, ctx_len);
823 }
824 memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context));
825
826 if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
827 /*
828 * Don't leak application addresses to the sessiond.
829 * This is only necessary when ctx is for an app ctx otherwise
830 * the values inside the union (type & config) are overwritten.
831 */
832 lsm.u.context.ctx.u.app_ctx.provider_name = NULL;
833 lsm.u.context.ctx.u.app_ctx.ctx_name = NULL;
834 }
835
836 ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buf, len, NULL);
837 end:
838 free(buf);
839 return ret;
840 }
841
842 /*
843 * Enable event(s) for a channel.
844 *
845 * If no event name is specified, all events are enabled.
846 * If no channel name is specified, the default 'channel0' is used.
847 *
848 * Returns size of returned session payload data or a negative error code.
849 */
850 int lttng_enable_event(struct lttng_handle *handle,
851 struct lttng_event *ev, const char *channel_name)
852 {
853 return lttng_enable_event_with_exclusions(handle, ev, channel_name,
854 NULL, 0, NULL);
855 }
856
857 /*
858 * Create or enable an event with a filter expression.
859 *
860 * Return negative error value on error.
861 * Return size of returned session payload data if OK.
862 */
863 int lttng_enable_event_with_filter(struct lttng_handle *handle,
864 struct lttng_event *event, const char *channel_name,
865 const char *filter_expression)
866 {
867 return lttng_enable_event_with_exclusions(handle, event, channel_name,
868 filter_expression, 0, NULL);
869 }
870
871 /*
872 * Depending on the event, return a newly allocated agent filter expression or
873 * NULL if not applicable.
874 *
875 * An event with NO loglevel and the name is * will return NULL.
876 */
877 static char *set_agent_filter(const char *filter, struct lttng_event *ev)
878 {
879 int err;
880 char *agent_filter = NULL;
881
882 assert(ev);
883
884 /* Don't add filter for the '*' event. */
885 if (strcmp(ev->name, "*") != 0) {
886 if (filter) {
887 err = asprintf(&agent_filter, "(%s) && (logger_name == \"%s\")", filter,
888 ev->name);
889 } else {
890 err = asprintf(&agent_filter, "logger_name == \"%s\"", ev->name);
891 }
892 if (err < 0) {
893 PERROR("asprintf");
894 goto error;
895 }
896 }
897
898 /* Add loglevel filtering if any for the JUL domain. */
899 if (ev->loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) {
900 char *op;
901
902 if (ev->loglevel_type == LTTNG_EVENT_LOGLEVEL_RANGE) {
903 op = ">=";
904 } else {
905 op = "==";
906 }
907
908 if (filter || agent_filter) {
909 char *new_filter;
910
911 err = asprintf(&new_filter, "(%s) && (int_loglevel %s %d)",
912 agent_filter ? agent_filter : filter, op,
913 ev->loglevel);
914 if (agent_filter) {
915 free(agent_filter);
916 }
917 agent_filter = new_filter;
918 } else {
919 err = asprintf(&agent_filter, "int_loglevel %s %d", op,
920 ev->loglevel);
921 }
922 if (err < 0) {
923 PERROR("asprintf");
924 goto error;
925 }
926 }
927
928 return agent_filter;
929 error:
930 free(agent_filter);
931 return NULL;
932 }
933
934 /*
935 * Generate the filter bytecode from a given filter expression string. Put the
936 * newly allocated parser context in ctxp and populate the lsm object with the
937 * expression len.
938 *
939 * Return 0 on success else a LTTNG_ERR_* code and ctxp is untouched.
940 */
941 static int generate_filter(char *filter_expression,
942 struct lttcomm_session_msg *lsm, struct filter_parser_ctx **ctxp)
943 {
944 int ret;
945 struct filter_parser_ctx *ctx = NULL;
946 FILE *fmem = NULL;
947
948 assert(filter_expression);
949 assert(lsm);
950 assert(ctxp);
951
952 /*
953 * Casting const to non-const, as the underlying function will use it in
954 * read-only mode.
955 */
956 fmem = lttng_fmemopen((void *) filter_expression,
957 strlen(filter_expression), "r");
958 if (!fmem) {
959 fprintf(stderr, "Error opening memory as stream\n");
960 ret = -LTTNG_ERR_FILTER_NOMEM;
961 goto error;
962 }
963 ctx = filter_parser_ctx_alloc(fmem);
964 if (!ctx) {
965 fprintf(stderr, "Error allocating parser\n");
966 ret = -LTTNG_ERR_FILTER_NOMEM;
967 goto filter_alloc_error;
968 }
969 ret = filter_parser_ctx_append_ast(ctx);
970 if (ret) {
971 fprintf(stderr, "Parse error\n");
972 ret = -LTTNG_ERR_FILTER_INVAL;
973 goto parse_error;
974 }
975 if (print_xml) {
976 ret = filter_visitor_print_xml(ctx, stdout, 0);
977 if (ret) {
978 fflush(stdout);
979 fprintf(stderr, "XML print error\n");
980 ret = -LTTNG_ERR_FILTER_INVAL;
981 goto parse_error;
982 }
983 }
984
985 dbg_printf("Generating IR... ");
986 fflush(stdout);
987 ret = filter_visitor_ir_generate(ctx);
988 if (ret) {
989 fprintf(stderr, "Generate IR error\n");
990 ret = -LTTNG_ERR_FILTER_INVAL;
991 goto parse_error;
992 }
993 dbg_printf("done\n");
994
995 dbg_printf("Validating IR... ");
996 fflush(stdout);
997 ret = filter_visitor_ir_check_binary_op_nesting(ctx);
998 if (ret) {
999 ret = -LTTNG_ERR_FILTER_INVAL;
1000 goto parse_error;
1001 }
1002
1003 /* Normalize globbing patterns in the expression. */
1004 ret = filter_visitor_ir_normalize_glob_patterns(ctx);
1005 if (ret) {
1006 ret = -LTTNG_ERR_FILTER_INVAL;
1007 goto parse_error;
1008 }
1009
1010 /* Validate strings used as literals in the expression. */
1011 ret = filter_visitor_ir_validate_string(ctx);
1012 if (ret) {
1013 ret = -LTTNG_ERR_FILTER_INVAL;
1014 goto parse_error;
1015 }
1016
1017 /* Validate globbing patterns in the expression. */
1018 ret = filter_visitor_ir_validate_globbing(ctx);
1019 if (ret) {
1020 ret = -LTTNG_ERR_FILTER_INVAL;
1021 goto parse_error;
1022 }
1023
1024 dbg_printf("done\n");
1025
1026 dbg_printf("Generating bytecode... ");
1027 fflush(stdout);
1028 ret = filter_visitor_bytecode_generate(ctx);
1029 if (ret) {
1030 fprintf(stderr, "Generate bytecode error\n");
1031 ret = -LTTNG_ERR_FILTER_INVAL;
1032 goto parse_error;
1033 }
1034 dbg_printf("done\n");
1035 dbg_printf("Size of bytecode generated: %u bytes.\n",
1036 bytecode_get_len(&ctx->bytecode->b));
1037
1038 lsm->u.enable.bytecode_len = sizeof(ctx->bytecode->b)
1039 + bytecode_get_len(&ctx->bytecode->b);
1040 lsm->u.enable.expression_len = strlen(filter_expression) + 1;
1041
1042 /* No need to keep the memory stream. */
1043 if (fclose(fmem) != 0) {
1044 PERROR("fclose");
1045 }
1046
1047 *ctxp = ctx;
1048 return 0;
1049
1050 parse_error:
1051 filter_ir_free(ctx);
1052 filter_parser_ctx_free(ctx);
1053 filter_alloc_error:
1054 if (fclose(fmem) != 0) {
1055 PERROR("fclose");
1056 }
1057 error:
1058 return ret;
1059 }
1060
1061 /*
1062 * Enable event(s) for a channel, possibly with exclusions and a filter.
1063 * If no event name is specified, all events are enabled.
1064 * If no channel name is specified, the default name is used.
1065 * If filter expression is not NULL, the filter is set for the event.
1066 * If exclusion count is not zero, the exclusions are set for the event.
1067 * Returns size of returned session payload data or a negative error code.
1068 */
1069 int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
1070 struct lttng_event *ev, const char *channel_name,
1071 const char *original_filter_expression,
1072 int exclusion_count, char **exclusion_list)
1073 {
1074 struct lttcomm_session_msg lsm;
1075 struct lttng_dynamic_buffer send_buffer;
1076 int ret = 0, i, fd_to_send = -1;
1077 bool send_fd = false;
1078 unsigned int free_filter_expression = 0;
1079 struct filter_parser_ctx *ctx = NULL;
1080
1081 memset(&send_buffer, 0, sizeof(send_buffer));
1082
1083 /*
1084 * Cast as non-const since we may replace the filter expression
1085 * by a dynamically allocated string. Otherwise, the original
1086 * string is not modified.
1087 */
1088 char *filter_expression = (char *) original_filter_expression;
1089
1090 if (handle == NULL || ev == NULL) {
1091 ret = -LTTNG_ERR_INVALID;
1092 goto error;
1093 }
1094
1095 /*
1096 * Empty filter string will always be rejected by the parser
1097 * anyway, so treat this corner-case early to eliminate
1098 * lttng_fmemopen error for 0-byte allocation.
1099 */
1100 if (filter_expression && filter_expression[0] == '\0') {
1101 ret = -LTTNG_ERR_INVALID;
1102 goto error;
1103 }
1104
1105 memset(&lsm, 0, sizeof(lsm));
1106
1107 /* If no channel name, send empty string. */
1108 if (channel_name == NULL) {
1109 lttng_ctl_copy_string(lsm.u.enable.channel_name, "",
1110 sizeof(lsm.u.enable.channel_name));
1111 } else {
1112 lttng_ctl_copy_string(lsm.u.enable.channel_name, channel_name,
1113 sizeof(lsm.u.enable.channel_name));
1114 }
1115
1116 lsm.cmd_type = LTTNG_ENABLE_EVENT;
1117 if (ev->name[0] == '\0') {
1118 /* Enable all events */
1119 lttng_ctl_copy_string(ev->name, "*", sizeof(ev->name));
1120 }
1121
1122 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
1123 /* FIXME: copying non-packed struct to packed struct. */
1124 memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
1125
1126 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
1127 sizeof(lsm.session.name));
1128 lsm.u.enable.exclusion_count = exclusion_count;
1129 lsm.u.enable.bytecode_len = 0;
1130
1131 /*
1132 * We have either a filter or some exclusions, so we need to set up
1133 * a variable-length memory block from where to send the data.
1134 */
1135 lttng_dynamic_buffer_init(&send_buffer);
1136
1137 /* Parse filter expression. */
1138 if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL
1139 || handle->domain.type == LTTNG_DOMAIN_LOG4J
1140 || handle->domain.type == LTTNG_DOMAIN_PYTHON) {
1141 if (handle->domain.type == LTTNG_DOMAIN_JUL ||
1142 handle->domain.type == LTTNG_DOMAIN_LOG4J ||
1143 handle->domain.type == LTTNG_DOMAIN_PYTHON) {
1144 char *agent_filter;
1145
1146 /* Setup JUL filter if needed. */
1147 agent_filter = set_agent_filter(filter_expression, ev);
1148 if (!agent_filter) {
1149 if (!filter_expression) {
1150 /*
1151 * No JUL and no filter, just skip
1152 * everything below.
1153 */
1154 goto ask_sessiond;
1155 }
1156 } else {
1157 /*
1158 * With an agent filter, the original filter has
1159 * been added to it thus replace the filter
1160 * expression.
1161 */
1162 filter_expression = agent_filter;
1163 free_filter_expression = 1;
1164 }
1165 }
1166
1167 ret = generate_filter(filter_expression, &lsm, &ctx);
1168 if (ret) {
1169 goto filter_error;
1170 }
1171 }
1172
1173 ret = lttng_dynamic_buffer_set_capacity(&send_buffer,
1174 lsm.u.enable.bytecode_len
1175 + lsm.u.enable.expression_len
1176 + LTTNG_SYMBOL_NAME_LEN * exclusion_count);
1177 if (ret) {
1178 ret = -LTTNG_ERR_EXCLUSION_NOMEM;
1179 goto mem_error;
1180 }
1181
1182 /* Put exclusion names first in the data. */
1183 for (i = 0; i < exclusion_count; i++) {
1184 size_t exclusion_len;
1185
1186 exclusion_len = lttng_strnlen(*(exclusion_list + i),
1187 LTTNG_SYMBOL_NAME_LEN);
1188 if (exclusion_len == LTTNG_SYMBOL_NAME_LEN) {
1189 /* Exclusion is not NULL-terminated. */
1190 ret = -LTTNG_ERR_INVALID;
1191 goto mem_error;
1192 }
1193
1194 ret = lttng_dynamic_buffer_append(&send_buffer,
1195 *(exclusion_list + i),
1196 LTTNG_SYMBOL_NAME_LEN);
1197 if (ret) {
1198 goto mem_error;
1199 }
1200 }
1201
1202 /* Add filter expression next. */
1203 if (filter_expression) {
1204 ret = lttng_dynamic_buffer_append(&send_buffer,
1205 filter_expression, lsm.u.enable.expression_len);
1206 if (ret) {
1207 goto mem_error;
1208 }
1209 }
1210 /* Add filter bytecode next. */
1211 if (ctx && lsm.u.enable.bytecode_len != 0) {
1212 ret = lttng_dynamic_buffer_append(&send_buffer,
1213 &ctx->bytecode->b, lsm.u.enable.bytecode_len);
1214 if (ret) {
1215 goto mem_error;
1216 }
1217 }
1218 if (ev->extended.ptr) {
1219 struct lttng_event_extended *ev_ext =
1220 (struct lttng_event_extended *) ev->extended.ptr;
1221
1222 if (ev_ext->probe_location) {
1223 /*
1224 * lttng_userspace_probe_location_serialize returns the
1225 * number of bytes that was appended to the buffer.
1226 */
1227 ret = lttng_userspace_probe_location_serialize(
1228 ev_ext->probe_location, &send_buffer,
1229 &fd_to_send);
1230 if (ret < 0) {
1231 goto mem_error;
1232 }
1233
1234 send_fd = fd_to_send >= 0;
1235 /*
1236 * Set the size of the userspace probe location element
1237 * of the buffer so that the receiving side knows where
1238 * to split it.
1239 */
1240 lsm.u.enable.userspace_probe_location_len = ret;
1241 }
1242 }
1243
1244 ret = lttng_ctl_ask_sessiond_fds_varlen(&lsm,
1245 send_fd ? &fd_to_send : NULL,
1246 send_fd ? 1 : 0,
1247 send_buffer.size ? send_buffer.data : NULL,
1248 send_buffer.size, NULL, NULL, 0);
1249
1250 mem_error:
1251 if (filter_expression && ctx) {
1252 filter_bytecode_free(ctx);
1253 filter_ir_free(ctx);
1254 filter_parser_ctx_free(ctx);
1255 }
1256 filter_error:
1257 if (free_filter_expression) {
1258 /*
1259 * The filter expression has been replaced and must be freed as
1260 * it is not the original filter expression received as a
1261 * parameter.
1262 */
1263 free(filter_expression);
1264 }
1265 error:
1266 /*
1267 * Return directly to the caller and don't ask the sessiond since
1268 * something went wrong in the parsing of data above.
1269 */
1270 lttng_dynamic_buffer_reset(&send_buffer);
1271 return ret;
1272
1273 ask_sessiond:
1274 ret = lttng_ctl_ask_sessiond(&lsm, NULL);
1275 return ret;
1276 }
1277
1278 int lttng_disable_event_ext(struct lttng_handle *handle,
1279 struct lttng_event *ev, const char *channel_name,
1280 const char *original_filter_expression)
1281 {
1282 struct lttcomm_session_msg lsm;
1283 char *varlen_data;
1284 int ret = 0;
1285 unsigned int free_filter_expression = 0;
1286 struct filter_parser_ctx *ctx = NULL;
1287 /*
1288 * Cast as non-const since we may replace the filter expression
1289 * by a dynamically allocated string. Otherwise, the original
1290 * string is not modified.
1291 */
1292 char *filter_expression = (char *) original_filter_expression;
1293
1294 if (handle == NULL || ev == NULL) {
1295 ret = -LTTNG_ERR_INVALID;
1296 goto error;
1297 }
1298
1299 /*
1300 * Empty filter string will always be rejected by the parser
1301 * anyway, so treat this corner-case early to eliminate
1302 * lttng_fmemopen error for 0-byte allocation.
1303 */
1304 if (filter_expression && filter_expression[0] == '\0') {
1305 ret = -LTTNG_ERR_INVALID;
1306 goto error;
1307 }
1308
1309 memset(&lsm, 0, sizeof(lsm));
1310
1311 /* If no channel name, send empty string. */
1312 if (channel_name == NULL) {
1313 lttng_ctl_copy_string(lsm.u.disable.channel_name, "",
1314 sizeof(lsm.u.disable.channel_name));
1315 } else {
1316 lttng_ctl_copy_string(lsm.u.disable.channel_name, channel_name,
1317 sizeof(lsm.u.disable.channel_name));
1318 }
1319
1320 lsm.cmd_type = LTTNG_DISABLE_EVENT;
1321
1322 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
1323 /* FIXME: copying non-packed struct to packed struct. */
1324 memcpy(&lsm.u.disable.event, ev, sizeof(lsm.u.disable.event));
1325
1326 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
1327 sizeof(lsm.session.name));
1328 lsm.u.disable.bytecode_len = 0;
1329
1330 /*
1331 * For the JUL domain, a filter is enforced except for the
1332 * disable all event. This is done to avoid having the event in
1333 * all sessions thus filtering by logger name.
1334 */
1335 if (filter_expression == NULL &&
1336 (handle->domain.type != LTTNG_DOMAIN_JUL &&
1337 handle->domain.type != LTTNG_DOMAIN_LOG4J &&
1338 handle->domain.type != LTTNG_DOMAIN_PYTHON)) {
1339 goto ask_sessiond;
1340 }
1341
1342 /*
1343 * We have a filter, so we need to set up a variable-length
1344 * memory block from where to send the data.
1345 */
1346
1347 /* Parse filter expression */
1348 if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL
1349 || handle->domain.type == LTTNG_DOMAIN_LOG4J
1350 || handle->domain.type == LTTNG_DOMAIN_PYTHON) {
1351 if (handle->domain.type == LTTNG_DOMAIN_JUL ||
1352 handle->domain.type == LTTNG_DOMAIN_LOG4J ||
1353 handle->domain.type == LTTNG_DOMAIN_PYTHON) {
1354 char *agent_filter;
1355
1356 /* Setup JUL filter if needed. */
1357 agent_filter = set_agent_filter(filter_expression, ev);
1358 if (!agent_filter) {
1359 if (!filter_expression) {
1360 /*
1361 * No JUL and no filter, just skip
1362 * everything below.
1363 */
1364 goto ask_sessiond;
1365 }
1366 } else {
1367 /*
1368 * With a JUL filter, the original filter has
1369 * been added to it thus replace the filter
1370 * expression.
1371 */
1372 filter_expression = agent_filter;
1373 free_filter_expression = 1;
1374 }
1375 }
1376
1377 ret = generate_filter(filter_expression, &lsm, &ctx);
1378 if (ret) {
1379 goto filter_error;
1380 }
1381 }
1382
1383 varlen_data = zmalloc(lsm.u.disable.bytecode_len
1384 + lsm.u.disable.expression_len);
1385 if (!varlen_data) {
1386 ret = -LTTNG_ERR_EXCLUSION_NOMEM;
1387 goto mem_error;
1388 }
1389
1390 /* Add filter expression. */
1391 if (lsm.u.disable.expression_len != 0) {
1392 memcpy(varlen_data,
1393 filter_expression,
1394 lsm.u.disable.expression_len);
1395 }
1396 /* Add filter bytecode next. */
1397 if (ctx && lsm.u.disable.bytecode_len != 0) {
1398 memcpy(varlen_data
1399 + lsm.u.disable.expression_len,
1400 &ctx->bytecode->b,
1401 lsm.u.disable.bytecode_len);
1402 }
1403
1404 ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, varlen_data,
1405 lsm.u.disable.bytecode_len + lsm.u.disable.expression_len, NULL);
1406 free(varlen_data);
1407
1408 mem_error:
1409 if (filter_expression && ctx) {
1410 filter_bytecode_free(ctx);
1411 filter_ir_free(ctx);
1412 filter_parser_ctx_free(ctx);
1413 }
1414 filter_error:
1415 if (free_filter_expression) {
1416 /*
1417 * The filter expression has been replaced and must be freed as
1418 * it is not the original filter expression received as a
1419 * parameter.
1420 */
1421 free(filter_expression);
1422 }
1423 error:
1424 /*
1425 * Return directly to the caller and don't ask the sessiond since
1426 * something went wrong in the parsing of data above.
1427 */
1428 return ret;
1429
1430 ask_sessiond:
1431 ret = lttng_ctl_ask_sessiond(&lsm, NULL);
1432 return ret;
1433 }
1434
1435 /*
1436 * Disable event(s) of a channel and domain.
1437 * If no event name is specified, all events are disabled.
1438 * If no channel name is specified, the default 'channel0' is used.
1439 * Returns size of returned session payload data or a negative error code.
1440 */
1441 int lttng_disable_event(struct lttng_handle *handle, const char *name,
1442 const char *channel_name)
1443 {
1444 struct lttng_event ev;
1445
1446 memset(&ev, 0, sizeof(ev));
1447 ev.loglevel = -1;
1448 ev.type = LTTNG_EVENT_ALL;
1449 lttng_ctl_copy_string(ev.name, name, sizeof(ev.name));
1450 return lttng_disable_event_ext(handle, &ev, channel_name, NULL);
1451 }
1452
1453 struct lttng_channel *lttng_channel_create(struct lttng_domain *domain)
1454 {
1455 struct lttng_channel *channel = NULL;
1456 struct lttng_channel_extended *extended = NULL;
1457
1458 if (!domain) {
1459 goto error;
1460 }
1461
1462 /* Validate domain. */
1463 switch (domain->type) {
1464 case LTTNG_DOMAIN_UST:
1465 switch (domain->buf_type) {
1466 case LTTNG_BUFFER_PER_UID:
1467 case LTTNG_BUFFER_PER_PID:
1468 break;
1469 default:
1470 goto error;
1471 }
1472 break;
1473 case LTTNG_DOMAIN_KERNEL:
1474 if (domain->buf_type != LTTNG_BUFFER_GLOBAL) {
1475 goto error;
1476 }
1477 break;
1478 default:
1479 goto error;
1480 }
1481
1482 channel = zmalloc(sizeof(*channel));
1483 if (!channel) {
1484 goto error;
1485 }
1486
1487 extended = zmalloc(sizeof(*extended));
1488 if (!extended) {
1489 goto error;
1490 }
1491
1492 channel->attr.extended.ptr = extended;
1493
1494 lttng_channel_set_default_attr(domain, &channel->attr);
1495 return channel;
1496 error:
1497 free(channel);
1498 free(extended);
1499 return NULL;
1500 }
1501
1502 void lttng_channel_destroy(struct lttng_channel *channel)
1503 {
1504 if (!channel) {
1505 return;
1506 }
1507
1508 if (channel->attr.extended.ptr) {
1509 free(channel->attr.extended.ptr);
1510 }
1511 free(channel);
1512 }
1513
1514 /*
1515 * Enable channel per domain
1516 * Returns size of returned session payload data or a negative error code.
1517 */
1518 int lttng_enable_channel(struct lttng_handle *handle,
1519 struct lttng_channel *in_chan)
1520 {
1521 struct lttcomm_session_msg lsm;
1522 size_t total_buffer_size_needed_per_cpu = 0;
1523
1524 /* NULL arguments are forbidden. No default values. */
1525 if (handle == NULL || in_chan == NULL) {
1526 return -LTTNG_ERR_INVALID;
1527 }
1528
1529 memset(&lsm, 0, sizeof(lsm));
1530 memcpy(&lsm.u.channel.chan, in_chan, sizeof(lsm.u.channel.chan));
1531 lsm.u.channel.chan.attr.extended.ptr = NULL;
1532
1533 if (!in_chan->attr.extended.ptr) {
1534 struct lttng_channel *channel;
1535 struct lttng_channel_extended *extended;
1536
1537 channel = lttng_channel_create(&handle->domain);
1538 if (!channel) {
1539 return -LTTNG_ERR_NOMEM;
1540 }
1541
1542 /*
1543 * Create a new channel in order to use default extended
1544 * attribute values.
1545 */
1546 extended = (struct lttng_channel_extended *)
1547 channel->attr.extended.ptr;
1548 memcpy(&lsm.u.channel.extended, extended, sizeof(*extended));
1549 lttng_channel_destroy(channel);
1550 } else {
1551 struct lttng_channel_extended *extended;
1552
1553 extended = (struct lttng_channel_extended *)
1554 in_chan->attr.extended.ptr;
1555 memcpy(&lsm.u.channel.extended, extended, sizeof(*extended));
1556 }
1557
1558 /*
1559 * Verify that the amount of memory required to create the requested
1560 * buffer is available on the system at the moment.
1561 */
1562 total_buffer_size_needed_per_cpu = lsm.u.channel.chan.attr.num_subbuf *
1563 lsm.u.channel.chan.attr.subbuf_size;
1564 if (!check_enough_available_memory(total_buffer_size_needed_per_cpu)) {
1565 return -LTTNG_ERR_NOMEM;
1566 }
1567
1568 lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
1569 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
1570
1571 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
1572 sizeof(lsm.session.name));
1573
1574 return lttng_ctl_ask_sessiond(&lsm, NULL);
1575 }
1576
1577 /*
1578 * All tracing will be stopped for registered events of the channel.
1579 * Returns size of returned session payload data or a negative error code.
1580 */
1581 int lttng_disable_channel(struct lttng_handle *handle, const char *name)
1582 {
1583 struct lttcomm_session_msg lsm;
1584
1585 /* Safety check. Both are mandatory. */
1586 if (handle == NULL || name == NULL) {
1587 return -LTTNG_ERR_INVALID;
1588 }
1589
1590 memset(&lsm, 0, sizeof(lsm));
1591
1592 lsm.cmd_type = LTTNG_DISABLE_CHANNEL;
1593
1594 lttng_ctl_copy_string(lsm.u.disable.channel_name, name,
1595 sizeof(lsm.u.disable.channel_name));
1596
1597 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
1598
1599 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
1600 sizeof(lsm.session.name));
1601
1602 return lttng_ctl_ask_sessiond(&lsm, NULL);
1603 }
1604
1605 /*
1606 * Add PID to session tracker.
1607 * Return 0 on success else a negative LTTng error code.
1608 */
1609 int lttng_track_pid(struct lttng_handle *handle, int pid)
1610 {
1611 struct lttcomm_session_msg lsm;
1612
1613 /* NULL arguments are forbidden. No default values. */
1614 if (handle == NULL) {
1615 return -LTTNG_ERR_INVALID;
1616 }
1617
1618 memset(&lsm, 0, sizeof(lsm));
1619
1620 lsm.cmd_type = LTTNG_TRACK_PID;
1621 lsm.u.pid_tracker.pid = pid;
1622
1623 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
1624
1625 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
1626 sizeof(lsm.session.name));
1627
1628 return lttng_ctl_ask_sessiond(&lsm, NULL);
1629 }
1630
1631 /*
1632 * Remove PID from session tracker.
1633 * Return 0 on success else a negative LTTng error code.
1634 */
1635 int lttng_untrack_pid(struct lttng_handle *handle, int pid)
1636 {
1637 struct lttcomm_session_msg lsm;
1638
1639 /* NULL arguments are forbidden. No default values. */
1640 if (handle == NULL) {
1641 return -LTTNG_ERR_INVALID;
1642 }
1643
1644 memset(&lsm, 0, sizeof(lsm));
1645
1646 lsm.cmd_type = LTTNG_UNTRACK_PID;
1647 lsm.u.pid_tracker.pid = pid;
1648
1649 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
1650
1651 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
1652 sizeof(lsm.session.name));
1653
1654 return lttng_ctl_ask_sessiond(&lsm, NULL);
1655 }
1656
1657 /*
1658 * Lists all available tracepoints of domain.
1659 * Sets the contents of the events array.
1660 * Returns the number of lttng_event entries in events;
1661 * on error, returns a negative value.
1662 */
1663 int lttng_list_tracepoints(struct lttng_handle *handle,
1664 struct lttng_event **events)
1665 {
1666 int ret;
1667 struct lttcomm_session_msg lsm;
1668
1669 if (handle == NULL) {
1670 return -LTTNG_ERR_INVALID;
1671 }
1672
1673 memset(&lsm, 0, sizeof(lsm));
1674 lsm.cmd_type = LTTNG_LIST_TRACEPOINTS;
1675 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
1676
1677 ret = lttng_ctl_ask_sessiond(&lsm, (void **) events);
1678 if (ret < 0) {
1679 return ret;
1680 }
1681
1682 return ret / sizeof(struct lttng_event);
1683 }
1684
1685 /*
1686 * Lists all available tracepoint fields of domain.
1687 * Sets the contents of the event field array.
1688 * Returns the number of lttng_event_field entries in events;
1689 * on error, returns a negative value.
1690 */
1691 int lttng_list_tracepoint_fields(struct lttng_handle *handle,
1692 struct lttng_event_field **fields)
1693 {
1694 int ret;
1695 struct lttcomm_session_msg lsm;
1696
1697 if (handle == NULL) {
1698 return -LTTNG_ERR_INVALID;
1699 }
1700
1701 memset(&lsm, 0, sizeof(lsm));
1702 lsm.cmd_type = LTTNG_LIST_TRACEPOINT_FIELDS;
1703 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
1704
1705 ret = lttng_ctl_ask_sessiond(&lsm, (void **) fields);
1706 if (ret < 0) {
1707 return ret;
1708 }
1709
1710 return ret / sizeof(struct lttng_event_field);
1711 }
1712
1713 /*
1714 * Lists all available kernel system calls. Allocates and sets the contents of
1715 * the events array.
1716 *
1717 * Returns the number of lttng_event entries in events; on error, returns a
1718 * negative value.
1719 */
1720 int lttng_list_syscalls(struct lttng_event **events)
1721 {
1722 int ret;
1723 struct lttcomm_session_msg lsm;
1724
1725 if (!events) {
1726 return -LTTNG_ERR_INVALID;
1727 }
1728
1729 memset(&lsm, 0, sizeof(lsm));
1730 lsm.cmd_type = LTTNG_LIST_SYSCALLS;
1731 /* Force kernel domain for system calls. */
1732 lsm.domain.type = LTTNG_DOMAIN_KERNEL;
1733
1734 ret = lttng_ctl_ask_sessiond(&lsm, (void **) events);
1735 if (ret < 0) {
1736 return ret;
1737 }
1738
1739 return ret / sizeof(struct lttng_event);
1740 }
1741
1742 /*
1743 * Returns a human readable string describing
1744 * the error code (a negative value).
1745 */
1746 const char *lttng_strerror(int code)
1747 {
1748 return error_get_str(code);
1749 }
1750
1751 /*
1752 * Create a brand new session using name and url for destination.
1753 *
1754 * Returns LTTNG_OK on success or a negative error code.
1755 */
1756 int lttng_create_session(const char *name, const char *url)
1757 {
1758 int ret;
1759 ssize_t size;
1760 struct lttcomm_session_msg lsm;
1761 struct lttng_uri *uris = NULL;
1762
1763 if (name == NULL) {
1764 return -LTTNG_ERR_INVALID;
1765 }
1766
1767 memset(&lsm, 0, sizeof(lsm));
1768
1769 lsm.cmd_type = LTTNG_CREATE_SESSION;
1770 lttng_ctl_copy_string(lsm.session.name, name, sizeof(lsm.session.name));
1771
1772 /* There should never be a data URL */
1773 size = uri_parse_str_urls(url, NULL, &uris);
1774 if (size < 0) {
1775 return -LTTNG_ERR_INVALID;
1776 }
1777
1778 lsm.u.uri.size = size;
1779
1780 ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, uris,
1781 sizeof(struct lttng_uri) * size, NULL);
1782
1783 free(uris);
1784 return ret;
1785 }
1786
1787 /*
1788 * Destroy session using name.
1789 * Returns size of returned session payload data or a negative error code.
1790 */
1791 static
1792 int _lttng_destroy_session(const char *session_name)
1793 {
1794 struct lttcomm_session_msg lsm;
1795
1796 if (session_name == NULL) {
1797 return -LTTNG_ERR_INVALID;
1798 }
1799
1800 memset(&lsm, 0, sizeof(lsm));
1801 lsm.cmd_type = LTTNG_DESTROY_SESSION;
1802
1803 lttng_ctl_copy_string(lsm.session.name, session_name,
1804 sizeof(lsm.session.name));
1805
1806 return lttng_ctl_ask_sessiond(&lsm, NULL);
1807 }
1808
1809 /*
1810 * Stop the session and wait for the data before destroying it
1811 */
1812 int lttng_destroy_session(const char *session_name)
1813 {
1814 int ret;
1815
1816 /*
1817 * Stop the tracing and wait for the data.
1818 */
1819 ret = _lttng_stop_tracing(session_name, 1);
1820 if (ret && ret != -LTTNG_ERR_TRACE_ALREADY_STOPPED) {
1821 goto end;
1822 }
1823
1824 ret = _lttng_destroy_session(session_name);
1825 end:
1826 return ret;
1827 }
1828
1829 /*
1830 * Destroy the session without waiting for the data.
1831 */
1832 int lttng_destroy_session_no_wait(const char *session_name)
1833 {
1834 int ret;
1835
1836 /*
1837 * Stop the tracing without waiting for the data.
1838 * The session might already have been stopped, so just
1839 * skip this error.
1840 */
1841 ret = _lttng_stop_tracing(session_name, 0);
1842 if (ret && ret != -LTTNG_ERR_TRACE_ALREADY_STOPPED) {
1843 goto end;
1844 }
1845
1846 ret = _lttng_destroy_session(session_name);
1847 end:
1848 return ret;
1849 }
1850
1851 /*
1852 * Ask the session daemon for all available sessions.
1853 * Sets the contents of the sessions array.
1854 * Returns the number of lttng_session entries in sessions;
1855 * on error, returns a negative value.
1856 */
1857 int lttng_list_sessions(struct lttng_session **sessions)
1858 {
1859 int ret;
1860 struct lttcomm_session_msg lsm;
1861
1862 memset(&lsm, 0, sizeof(lsm));
1863 lsm.cmd_type = LTTNG_LIST_SESSIONS;
1864 ret = lttng_ctl_ask_sessiond(&lsm, (void**) sessions);
1865 if (ret < 0) {
1866 return ret;
1867 }
1868
1869 return ret / sizeof(struct lttng_session);
1870 }
1871
1872 int lttng_set_session_shm_path(const char *session_name,
1873 const char *shm_path)
1874 {
1875 struct lttcomm_session_msg lsm;
1876
1877 if (session_name == NULL) {
1878 return -LTTNG_ERR_INVALID;
1879 }
1880
1881 memset(&lsm, 0, sizeof(lsm));
1882 lsm.cmd_type = LTTNG_SET_SESSION_SHM_PATH;
1883
1884 lttng_ctl_copy_string(lsm.session.name, session_name,
1885 sizeof(lsm.session.name));
1886 lttng_ctl_copy_string(lsm.u.set_shm_path.shm_path, shm_path,
1887 sizeof(lsm.u.set_shm_path.shm_path));
1888
1889 return lttng_ctl_ask_sessiond(&lsm, NULL);
1890 }
1891
1892 /*
1893 * Ask the session daemon for all available domains of a session.
1894 * Sets the contents of the domains array.
1895 * Returns the number of lttng_domain entries in domains;
1896 * on error, returns a negative value.
1897 */
1898 int lttng_list_domains(const char *session_name,
1899 struct lttng_domain **domains)
1900 {
1901 int ret;
1902 struct lttcomm_session_msg lsm;
1903
1904 if (session_name == NULL) {
1905 return -LTTNG_ERR_INVALID;
1906 }
1907
1908 memset(&lsm, 0, sizeof(lsm));
1909 lsm.cmd_type = LTTNG_LIST_DOMAINS;
1910
1911 lttng_ctl_copy_string(lsm.session.name, session_name,
1912 sizeof(lsm.session.name));
1913
1914 ret = lttng_ctl_ask_sessiond(&lsm, (void**) domains);
1915 if (ret < 0) {
1916 return ret;
1917 }
1918
1919 return ret / sizeof(struct lttng_domain);
1920 }
1921
1922 /*
1923 * Ask the session daemon for all available channels of a session.
1924 * Sets the contents of the channels array.
1925 * Returns the number of lttng_channel entries in channels;
1926 * on error, returns a negative value.
1927 */
1928 int lttng_list_channels(struct lttng_handle *handle,
1929 struct lttng_channel **channels)
1930 {
1931 int ret;
1932 size_t channel_count, i;
1933 const size_t channel_size = sizeof(struct lttng_channel) +
1934 sizeof(struct lttng_channel_extended);
1935 struct lttcomm_session_msg lsm;
1936 void *extended_at;
1937
1938 if (handle == NULL) {
1939 ret = -LTTNG_ERR_INVALID;
1940 goto end;
1941 }
1942
1943 memset(&lsm, 0, sizeof(lsm));
1944 lsm.cmd_type = LTTNG_LIST_CHANNELS;
1945 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
1946 sizeof(lsm.session.name));
1947
1948 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
1949
1950 ret = lttng_ctl_ask_sessiond(&lsm, (void**) channels);
1951 if (ret < 0) {
1952 goto end;
1953 }
1954
1955 if (ret % channel_size) {
1956 ret = -LTTNG_ERR_UNK;
1957 free(*channels);
1958 *channels = NULL;
1959 goto end;
1960 }
1961 channel_count = (size_t) ret / channel_size;
1962
1963 /* Set extended info pointers */
1964 extended_at = ((void *) *channels) +
1965 channel_count * sizeof(struct lttng_channel);
1966 for (i = 0; i < channel_count; i++) {
1967 struct lttng_channel *chan = &(*channels)[i];
1968
1969 chan->attr.extended.ptr = extended_at;
1970 extended_at += sizeof(struct lttng_channel_extended);
1971 }
1972
1973 ret = (int) channel_count;
1974 end:
1975 return ret;
1976 }
1977
1978 /*
1979 * Ask the session daemon for all available events of a session channel.
1980 * Sets the contents of the events array.
1981 * Returns the number of lttng_event entries in events;
1982 * on error, returns a negative value.
1983 */
1984 int lttng_list_events(struct lttng_handle *handle,
1985 const char *channel_name, struct lttng_event **events)
1986 {
1987 int ret;
1988 struct lttcomm_session_msg lsm;
1989 struct lttcomm_event_command_header *cmd_header = NULL;
1990 size_t cmd_header_len;
1991 uint32_t nb_events, i;
1992 void *comm_ext_at;
1993 char *reception_buffer = NULL;
1994 struct lttng_dynamic_buffer listing;
1995 size_t storage_req;
1996
1997 /* Safety check. An handle and channel name are mandatory */
1998 if (handle == NULL || channel_name == NULL) {
1999 return -LTTNG_ERR_INVALID;
2000 }
2001
2002 memset(&lsm, 0, sizeof(lsm));
2003 lsm.cmd_type = LTTNG_LIST_EVENTS;
2004 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
2005 sizeof(lsm.session.name));
2006 lttng_ctl_copy_string(lsm.u.list.channel_name, channel_name,
2007 sizeof(lsm.u.list.channel_name));
2008 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
2009
2010 ret = lttng_ctl_ask_sessiond_fds_varlen(&lsm, NULL, 0, NULL, 0,
2011 (void **) &reception_buffer, (void **) &cmd_header,
2012 &cmd_header_len);
2013 if (ret < 0) {
2014 goto end;
2015 }
2016
2017 if (!cmd_header) {
2018 ret = -LTTNG_ERR_UNK;
2019 goto end;
2020 }
2021
2022 /* Set number of events and free command header */
2023 nb_events = cmd_header->nb_events;
2024 if (nb_events > INT_MAX) {
2025 ret = -EOVERFLOW;
2026 goto end;
2027 }
2028 free(cmd_header);
2029 cmd_header = NULL;
2030
2031 /*
2032 * The buffer that is returned must contain a "flat" version of
2033 * the events that are returned. In other words, all pointers
2034 * within an lttng_event must point to a location within the returned
2035 * buffer so that the user may free everything by simply calling free()
2036 * on the returned buffer. This is needed in order to maintain API
2037 * compatibility.
2038 *
2039 * A first pass is performed to compute the size of the buffer that
2040 * must be allocated. A second pass is then performed to setup
2041 * the returned events so that their members always point within the
2042 * buffer.
2043 *
2044 * The layout of the returned buffer is as follows:
2045 * - struct lttng_event[nb_events],
2046 * - nb_events times the following:
2047 * - struct lttng_event_extended,
2048 * - flattened version of userspace_probe_location
2049 * - filter_expression
2050 * - exclusions
2051 * - padding to align to 64-bits
2052 */
2053 comm_ext_at = reception_buffer +
2054 (nb_events * sizeof(struct lttng_event));
2055 storage_req = nb_events * sizeof(struct lttng_event);
2056
2057 for (i = 0; i < nb_events; i++) {
2058 struct lttcomm_event_extended_header *ext_comm =
2059 (struct lttcomm_event_extended_header *) comm_ext_at;
2060 int probe_storage_req = 0;
2061
2062 comm_ext_at += sizeof(*ext_comm);
2063 comm_ext_at += ext_comm->filter_len;
2064 comm_ext_at +=
2065 ext_comm->nb_exclusions * LTTNG_SYMBOL_NAME_LEN;
2066
2067 if (ext_comm->userspace_probe_location_len) {
2068 struct lttng_userspace_probe_location *probe_location = NULL;
2069 struct lttng_buffer_view probe_location_view;
2070
2071 probe_location_view = lttng_buffer_view_init(
2072 comm_ext_at, 0,
2073 ext_comm->userspace_probe_location_len);
2074
2075 /*
2076 * Create a temporary userspace probe location to
2077 * determine the size needed by a "flattened" version
2078 * of that same probe location.
2079 */
2080 ret = lttng_userspace_probe_location_create_from_buffer(
2081 &probe_location_view, &probe_location);
2082 if (ret < 0) {
2083 ret = -LTTNG_ERR_PROBE_LOCATION_INVAL;
2084 goto end;
2085 }
2086
2087 ret = lttng_userspace_probe_location_flatten(
2088 probe_location, NULL);
2089 lttng_userspace_probe_location_destroy(probe_location);
2090 if (ret < 0) {
2091 ret = -LTTNG_ERR_PROBE_LOCATION_INVAL;
2092 goto end;
2093 }
2094
2095 probe_storage_req = ret;
2096 comm_ext_at += ext_comm->userspace_probe_location_len;
2097 }
2098
2099 storage_req += sizeof(struct lttng_event_extended);
2100 storage_req += ext_comm->filter_len;
2101 storage_req += ext_comm->nb_exclusions * LTTNG_SYMBOL_NAME_LEN;
2102 /* Padding to ensure the flat probe is aligned. */
2103 storage_req = ALIGN_TO(storage_req, sizeof(uint64_t));
2104 storage_req += probe_storage_req;
2105 }
2106
2107 lttng_dynamic_buffer_init(&listing);
2108 /*
2109 * We must ensure that "listing" is never resized so as to preserve
2110 * the validity of the flattened objects.
2111 */
2112 ret = lttng_dynamic_buffer_set_capacity(&listing, storage_req);
2113 if (ret) {
2114 ret = -LTTNG_ERR_NOMEM;
2115 goto end;
2116 }
2117
2118 ret = lttng_dynamic_buffer_append(&listing, reception_buffer,
2119 nb_events * sizeof(struct lttng_event));
2120 if (ret) {
2121 ret = -LTTNG_ERR_NOMEM;
2122 goto free_dynamic_buffer;
2123 }
2124
2125 comm_ext_at = reception_buffer +
2126 (nb_events * sizeof(struct lttng_event));
2127 for (i = 0; i < nb_events; i++) {
2128 struct lttng_event *event = (struct lttng_event *)
2129 (listing.data + (sizeof(struct lttng_event) * i));
2130 struct lttcomm_event_extended_header *ext_comm =
2131 (struct lttcomm_event_extended_header *) comm_ext_at;
2132 struct lttng_event_extended *event_extended =
2133 (struct lttng_event_extended *)
2134 (listing.data + listing.size);
2135
2136 /* Insert struct lttng_event_extended. */
2137 ret = lttng_dynamic_buffer_set_size(&listing,
2138 listing.size + sizeof(*event_extended));
2139 if (ret) {
2140 ret = -LTTNG_ERR_NOMEM;
2141 goto free_dynamic_buffer;
2142 }
2143 event->extended.ptr = event_extended;
2144
2145 comm_ext_at += sizeof(*ext_comm);
2146
2147 /* Insert filter expression. */
2148 if (ext_comm->filter_len) {
2149 event_extended->filter_expression = listing.data +
2150 listing.size;
2151 ret = lttng_dynamic_buffer_append(&listing, comm_ext_at,
2152 ext_comm->filter_len);
2153 if (ret) {
2154 ret = -LTTNG_ERR_NOMEM;
2155 goto free_dynamic_buffer;
2156 }
2157 comm_ext_at += ext_comm->filter_len;
2158 }
2159
2160 /* Insert exclusions. */
2161 if (ext_comm->nb_exclusions) {
2162 event_extended->exclusions.count =
2163 ext_comm->nb_exclusions;
2164 event_extended->exclusions.strings =
2165 listing.data + listing.size;
2166
2167 ret = lttng_dynamic_buffer_append(&listing,
2168 comm_ext_at,
2169 ext_comm->nb_exclusions * LTTNG_SYMBOL_NAME_LEN);
2170 if (ret) {
2171 ret = -LTTNG_ERR_NOMEM;
2172 goto free_dynamic_buffer;
2173 }
2174 comm_ext_at += ext_comm->nb_exclusions * LTTNG_SYMBOL_NAME_LEN;
2175 }
2176
2177 /* Insert padding to align to 64-bits. */
2178 ret = lttng_dynamic_buffer_set_size(&listing,
2179 ALIGN_TO(listing.size, sizeof(uint64_t)));
2180 if (ret) {
2181 ret = -LTTNG_ERR_NOMEM;
2182 goto free_dynamic_buffer;
2183 }
2184
2185 /* Insert flattened userspace probe location. */
2186 if (ext_comm->userspace_probe_location_len) {
2187 struct lttng_userspace_probe_location *probe_location = NULL;
2188 struct lttng_buffer_view probe_location_view;
2189
2190 probe_location_view = lttng_buffer_view_init(
2191 comm_ext_at, 0,
2192 ext_comm->userspace_probe_location_len);
2193
2194 ret = lttng_userspace_probe_location_create_from_buffer(
2195 &probe_location_view, &probe_location);
2196 if (ret < 0) {
2197 ret = -LTTNG_ERR_PROBE_LOCATION_INVAL;
2198 goto free_dynamic_buffer;
2199 }
2200
2201 event_extended->probe_location = (struct lttng_userspace_probe_location *)
2202 (listing.data + listing.size);
2203 ret = lttng_userspace_probe_location_flatten(
2204 probe_location, &listing);
2205 lttng_userspace_probe_location_destroy(probe_location);
2206 if (ret < 0) {
2207 ret = -LTTNG_ERR_PROBE_LOCATION_INVAL;
2208 goto free_dynamic_buffer;
2209 }
2210
2211 comm_ext_at += ext_comm->userspace_probe_location_len;
2212 }
2213 }
2214
2215 /* Don't reset listing buffer as we return its content. */
2216 *events = (struct lttng_event *) listing.data;
2217 lttng_dynamic_buffer_init(&listing);
2218 ret = (int) nb_events;
2219 free_dynamic_buffer:
2220 lttng_dynamic_buffer_reset(&listing);
2221 end:
2222 free(cmd_header);
2223 free(reception_buffer);
2224 return ret;
2225 }
2226
2227 /*
2228 * Sets the tracing_group variable with name.
2229 * This function allocates memory pointed to by tracing_group.
2230 * On success, returns 0, on error, returns -1 (null name) or -ENOMEM.
2231 */
2232 int lttng_set_tracing_group(const char *name)
2233 {
2234 if (name == NULL) {
2235 return -LTTNG_ERR_INVALID;
2236 }
2237
2238 if (asprintf(&tracing_group, "%s", name) < 0) {
2239 return -LTTNG_ERR_FATAL;
2240 }
2241
2242 return 0;
2243 }
2244
2245 int lttng_calibrate(struct lttng_handle *handle,
2246 struct lttng_calibrate *calibrate)
2247 {
2248 /*
2249 * This command was removed in LTTng 2.9.
2250 */
2251 return -LTTNG_ERR_UND;
2252 }
2253
2254 /*
2255 * Set default channel attributes.
2256 * If either or both of the arguments are null, attr content is zeroe'd.
2257 */
2258 void lttng_channel_set_default_attr(struct lttng_domain *domain,
2259 struct lttng_channel_attr *attr)
2260 {
2261 struct lttng_channel_extended *extended;
2262
2263 /* Safety check */
2264 if (attr == NULL || domain == NULL) {
2265 return;
2266 }
2267
2268 extended = (struct lttng_channel_extended *) attr->extended.ptr;
2269 memset(attr, 0, sizeof(struct lttng_channel_attr));
2270
2271 /* Same for all domains. */
2272 attr->overwrite = DEFAULT_CHANNEL_OVERWRITE;
2273 attr->tracefile_size = DEFAULT_CHANNEL_TRACEFILE_SIZE;
2274 attr->tracefile_count = DEFAULT_CHANNEL_TRACEFILE_COUNT;
2275
2276 switch (domain->type) {
2277 case LTTNG_DOMAIN_KERNEL:
2278 attr->switch_timer_interval =
2279 DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER;
2280 attr->read_timer_interval = DEFAULT_KERNEL_CHANNEL_READ_TIMER;
2281 attr->subbuf_size = default_get_kernel_channel_subbuf_size();
2282 attr->num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM;
2283 attr->output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
2284 if (extended) {
2285 extended->monitor_timer_interval =
2286 DEFAULT_KERNEL_CHANNEL_MONITOR_TIMER;
2287 extended->blocking_timeout =
2288 DEFAULT_KERNEL_CHANNEL_BLOCKING_TIMEOUT;
2289 }
2290 break;
2291 case LTTNG_DOMAIN_UST:
2292 switch (domain->buf_type) {
2293 case LTTNG_BUFFER_PER_UID:
2294 attr->subbuf_size = default_get_ust_uid_channel_subbuf_size();
2295 attr->num_subbuf = DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM;
2296 attr->output = DEFAULT_UST_UID_CHANNEL_OUTPUT;
2297 attr->switch_timer_interval =
2298 DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER;
2299 attr->read_timer_interval =
2300 DEFAULT_UST_UID_CHANNEL_READ_TIMER;
2301 if (extended) {
2302 extended->monitor_timer_interval =
2303 DEFAULT_UST_UID_CHANNEL_MONITOR_TIMER;
2304 extended->blocking_timeout =
2305 DEFAULT_UST_UID_CHANNEL_BLOCKING_TIMEOUT;
2306 }
2307 break;
2308 case LTTNG_BUFFER_PER_PID:
2309 default:
2310 attr->subbuf_size = default_get_ust_pid_channel_subbuf_size();
2311 attr->num_subbuf = DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM;
2312 attr->output = DEFAULT_UST_PID_CHANNEL_OUTPUT;
2313 attr->switch_timer_interval =
2314 DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER;
2315 attr->read_timer_interval =
2316 DEFAULT_UST_PID_CHANNEL_READ_TIMER;
2317 if (extended) {
2318 extended->monitor_timer_interval =
2319 DEFAULT_UST_PID_CHANNEL_MONITOR_TIMER;
2320 extended->blocking_timeout =
2321 DEFAULT_UST_PID_CHANNEL_BLOCKING_TIMEOUT;
2322 }
2323 break;
2324 }
2325 default:
2326 /* Default behavior: leave set to 0. */
2327 break;
2328 }
2329
2330 attr->extended.ptr = extended;
2331 }
2332
2333 int lttng_channel_get_discarded_event_count(struct lttng_channel *channel,
2334 uint64_t *discarded_events)
2335 {
2336 int ret = 0;
2337 struct lttng_channel_extended *chan_ext;
2338
2339 if (!channel || !discarded_events) {
2340 ret = -LTTNG_ERR_INVALID;
2341 goto end;
2342 }
2343
2344 chan_ext = channel->attr.extended.ptr;
2345 if (!chan_ext) {
2346 /*
2347 * This can happen since the lttng_channel structure is
2348 * used for other tasks where this pointer is never set.
2349 */
2350 *discarded_events = 0;
2351 goto end;
2352 }
2353
2354 *discarded_events = chan_ext->discarded_events;
2355 end:
2356 return ret;
2357 }
2358
2359 int lttng_channel_get_lost_packet_count(struct lttng_channel *channel,
2360 uint64_t *lost_packets)
2361 {
2362 int ret = 0;
2363 struct lttng_channel_extended *chan_ext;
2364
2365 if (!channel || !lost_packets) {
2366 ret = -LTTNG_ERR_INVALID;
2367 goto end;
2368 }
2369
2370 chan_ext = channel->attr.extended.ptr;
2371 if (!chan_ext) {
2372 /*
2373 * This can happen since the lttng_channel structure is
2374 * used for other tasks where this pointer is never set.
2375 */
2376 *lost_packets = 0;
2377 goto end;
2378 }
2379
2380 *lost_packets = chan_ext->lost_packets;
2381 end:
2382 return ret;
2383 }
2384
2385 int lttng_channel_get_monitor_timer_interval(struct lttng_channel *chan,
2386 uint64_t *monitor_timer_interval)
2387 {
2388 int ret = 0;
2389
2390 if (!chan || !monitor_timer_interval) {
2391 ret = -LTTNG_ERR_INVALID;
2392 goto end;
2393 }
2394
2395 if (!chan->attr.extended.ptr) {
2396 ret = -LTTNG_ERR_INVALID;
2397 goto end;
2398 }
2399
2400 *monitor_timer_interval = ((struct lttng_channel_extended *)
2401 chan->attr.extended.ptr)->monitor_timer_interval;
2402 end:
2403 return ret;
2404 }
2405
2406 int lttng_channel_set_monitor_timer_interval(struct lttng_channel *chan,
2407 uint64_t monitor_timer_interval)
2408 {
2409 int ret = 0;
2410
2411 if (!chan || !chan->attr.extended.ptr) {
2412 ret = -LTTNG_ERR_INVALID;
2413 goto end;
2414 }
2415
2416 ((struct lttng_channel_extended *)
2417 chan->attr.extended.ptr)->monitor_timer_interval =
2418 monitor_timer_interval;
2419 end:
2420 return ret;
2421 }
2422
2423 int lttng_channel_get_blocking_timeout(struct lttng_channel *chan,
2424 int64_t *blocking_timeout)
2425 {
2426 int ret = 0;
2427
2428 if (!chan || !blocking_timeout) {
2429 ret = -LTTNG_ERR_INVALID;
2430 goto end;
2431 }
2432
2433 if (!chan->attr.extended.ptr) {
2434 ret = -LTTNG_ERR_INVALID;
2435 goto end;
2436 }
2437
2438 *blocking_timeout = ((struct lttng_channel_extended *)
2439 chan->attr.extended.ptr)->blocking_timeout;
2440 end:
2441 return ret;
2442 }
2443
2444 int lttng_channel_set_blocking_timeout(struct lttng_channel *chan,
2445 int64_t blocking_timeout)
2446 {
2447 int ret = 0;
2448 int64_t msec_timeout;
2449
2450 if (!chan || !chan->attr.extended.ptr) {
2451 ret = -LTTNG_ERR_INVALID;
2452 goto end;
2453 }
2454
2455 if (blocking_timeout < 0 && blocking_timeout != -1) {
2456 ret = -LTTNG_ERR_INVALID;
2457 goto end;
2458 }
2459
2460 /*
2461 * LTTng-ust's use of poll() to implement this timeout mechanism forces
2462 * us to accept a narrower range of values (msecs expressed as a signed
2463 * 32-bit integer).
2464 */
2465 msec_timeout = blocking_timeout / 1000;
2466 if (msec_timeout != (int32_t) msec_timeout) {
2467 ret = -LTTNG_ERR_INVALID;
2468 goto end;
2469 }
2470
2471 ((struct lttng_channel_extended *)
2472 chan->attr.extended.ptr)->blocking_timeout =
2473 blocking_timeout;
2474 end:
2475 return ret;
2476 }
2477
2478 /*
2479 * Check if session daemon is alive.
2480 *
2481 * Return 1 if alive or 0 if not.
2482 * On error returns a negative value.
2483 */
2484 int lttng_session_daemon_alive(void)
2485 {
2486 int ret;
2487
2488 ret = set_session_daemon_path();
2489 if (ret < 0) {
2490 /* Error. */
2491 return ret;
2492 }
2493
2494 if (*sessiond_sock_path == '\0') {
2495 /*
2496 * No socket path set. Weird error which means the constructor
2497 * was not called.
2498 */
2499 assert(0);
2500 }
2501
2502 ret = try_connect_sessiond(sessiond_sock_path);
2503 if (ret < 0) {
2504 /* Not alive. */
2505 return 0;
2506 }
2507
2508 /* Is alive. */
2509 return 1;
2510 }
2511
2512 /*
2513 * Set URL for a consumer for a session and domain.
2514 *
2515 * Return 0 on success, else a negative value.
2516 */
2517 int lttng_set_consumer_url(struct lttng_handle *handle,
2518 const char *control_url, const char *data_url)
2519 {
2520 int ret;
2521 ssize_t size;
2522 struct lttcomm_session_msg lsm;
2523 struct lttng_uri *uris = NULL;
2524
2525 if (handle == NULL || (control_url == NULL && data_url == NULL)) {
2526 return -LTTNG_ERR_INVALID;
2527 }
2528
2529 memset(&lsm, 0, sizeof(lsm));
2530
2531 lsm.cmd_type = LTTNG_SET_CONSUMER_URI;
2532
2533 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
2534 sizeof(lsm.session.name));
2535 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
2536
2537 size = uri_parse_str_urls(control_url, data_url, &uris);
2538 if (size < 0) {
2539 return -LTTNG_ERR_INVALID;
2540 }
2541
2542 lsm.u.uri.size = size;
2543
2544 ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, uris,
2545 sizeof(struct lttng_uri) * size, NULL);
2546
2547 free(uris);
2548 return ret;
2549 }
2550
2551 /*
2552 * [OBSOLETE]
2553 */
2554 int lttng_enable_consumer(struct lttng_handle *handle)
2555 {
2556 return -ENOSYS;
2557 }
2558
2559 /*
2560 * [OBSOLETE]
2561 */
2562 int lttng_disable_consumer(struct lttng_handle *handle)
2563 {
2564 return -ENOSYS;
2565 }
2566
2567 /*
2568 * This is an extension of create session that is ONLY and SHOULD only be used
2569 * by the lttng command line program. It exists to avoid using URI parsing in
2570 * the lttng client.
2571 *
2572 * We need the date and time for the trace path subdirectory for the case where
2573 * the user does NOT define one using either -o or -U. Using the normal
2574 * lttng_create_session API call, we have no clue on the session daemon side if
2575 * the URL was generated automatically by the client or define by the user.
2576 *
2577 * So this function "wrapper" is hidden from the public API, takes the datetime
2578 * string and appends it if necessary to the URI subdirectory before sending it
2579 * to the session daemon.
2580 *
2581 * With this extra function, the lttng_create_session call behavior is not
2582 * changed and the timestamp is appended to the URI on the session daemon side
2583 * if necessary.
2584 */
2585 int _lttng_create_session_ext(const char *name, const char *url,
2586 const char *datetime)
2587 {
2588 int ret;
2589 ssize_t size;
2590 struct lttcomm_session_msg lsm;
2591 struct lttng_uri *uris = NULL;
2592
2593 if (name == NULL || datetime == NULL) {
2594 return -LTTNG_ERR_INVALID;
2595 }
2596
2597 memset(&lsm, 0, sizeof(lsm));
2598
2599 lsm.cmd_type = LTTNG_CREATE_SESSION;
2600 lttng_ctl_copy_string(lsm.session.name, name, sizeof(lsm.session.name));
2601
2602 /* There should never be a data URL. */
2603 size = uri_parse_str_urls(url, NULL, &uris);
2604 if (size < 0) {
2605 ret = -LTTNG_ERR_INVALID;
2606 goto error;
2607 }
2608
2609 lsm.u.uri.size = size;
2610
2611 if (size > 0 && uris[0].dtype != LTTNG_DST_PATH && strlen(uris[0].subdir) == 0) {
2612 /* Don't append datetime if the name was automatically created. */
2613 if (strncmp(name, DEFAULT_SESSION_NAME "-",
2614 strlen(DEFAULT_SESSION_NAME) + 1)) {
2615 ret = snprintf(uris[0].subdir, sizeof(uris[0].subdir), "%s-%s",
2616 name, datetime);
2617 } else {
2618 ret = snprintf(uris[0].subdir, sizeof(uris[0].subdir), "%s", name);
2619 }
2620 if (ret < 0) {
2621 PERROR("snprintf uri subdir");
2622 ret = -LTTNG_ERR_FATAL;
2623 goto error;
2624 }
2625 }
2626
2627 ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, uris,
2628 sizeof(struct lttng_uri) * size, NULL);
2629
2630 error:
2631 free(uris);
2632 return ret;
2633 }
2634
2635 /*
2636 * For a given session name, this call checks if the data is ready to be read
2637 * or is still being extracted by the consumer(s) hence not ready to be used by
2638 * any readers.
2639 */
2640 int lttng_data_pending(const char *session_name)
2641 {
2642 int ret;
2643 struct lttcomm_session_msg lsm;
2644 uint8_t *pending = NULL;
2645
2646 if (session_name == NULL) {
2647 return -LTTNG_ERR_INVALID;
2648 }
2649
2650 memset(&lsm, 0, sizeof(lsm));
2651 lsm.cmd_type = LTTNG_DATA_PENDING;
2652
2653 lttng_ctl_copy_string(lsm.session.name, session_name,
2654 sizeof(lsm.session.name));
2655
2656 ret = lttng_ctl_ask_sessiond(&lsm, (void **) &pending);
2657 if (ret < 0) {
2658 goto end;
2659 } else if (ret != 1) {
2660 /* Unexpected payload size */
2661 ret = -LTTNG_ERR_INVALID;
2662 goto end;
2663 }
2664
2665 ret = (int) *pending;
2666 end:
2667 free(pending);
2668 return ret;
2669 }
2670
2671 /*
2672 * Create a session exclusively used for snapshot.
2673 *
2674 * Returns LTTNG_OK on success or a negative error code.
2675 */
2676 int lttng_create_session_snapshot(const char *name, const char *snapshot_url)
2677 {
2678 int ret;
2679 ssize_t size;
2680 struct lttcomm_session_msg lsm;
2681 struct lttng_uri *uris = NULL;
2682
2683 if (name == NULL) {
2684 return -LTTNG_ERR_INVALID;
2685 }
2686
2687 memset(&lsm, 0, sizeof(lsm));
2688
2689 lsm.cmd_type = LTTNG_CREATE_SESSION_SNAPSHOT;
2690 lttng_ctl_copy_string(lsm.session.name, name, sizeof(lsm.session.name));
2691
2692 size = uri_parse_str_urls(snapshot_url, NULL, &uris);
2693 if (size < 0) {
2694 return -LTTNG_ERR_INVALID;
2695 }
2696
2697 lsm.u.uri.size = size;
2698
2699 /*
2700 * If the user does not specify a custom subdir, use the session name.
2701 */
2702 if (size > 0 && uris[0].dtype != LTTNG_DST_PATH && strlen(uris[0].subdir) == 0) {
2703 ret = snprintf(uris[0].subdir, sizeof(uris[0].subdir), "%s", name);
2704 if (ret < 0) {
2705 PERROR("snprintf uri subdir");
2706 ret = -LTTNG_ERR_FATAL;
2707 goto error;
2708 }
2709 }
2710
2711 ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, uris,
2712 sizeof(struct lttng_uri) * size, NULL);
2713
2714 error:
2715 free(uris);
2716 return ret;
2717 }
2718
2719 /*
2720 * Create a session exclusively used for live.
2721 *
2722 * Returns LTTNG_OK on success or a negative error code.
2723 */
2724 int lttng_create_session_live(const char *name, const char *url,
2725 unsigned int timer_interval)
2726 {
2727 int ret;
2728 ssize_t size;
2729 struct lttcomm_session_msg lsm;
2730 struct lttng_uri *uris = NULL;
2731
2732 if (name == NULL || timer_interval == 0) {
2733 return -LTTNG_ERR_INVALID;
2734 }
2735
2736 memset(&lsm, 0, sizeof(lsm));
2737
2738 lsm.cmd_type = LTTNG_CREATE_SESSION_LIVE;
2739 lttng_ctl_copy_string(lsm.session.name, name, sizeof(lsm.session.name));
2740
2741 if (url) {
2742 size = uri_parse_str_urls(url, NULL, &uris);
2743 if (size <= 0) {
2744 ret = -LTTNG_ERR_INVALID;
2745 goto end;
2746 }
2747
2748 /* file:// is not accepted for live session. */
2749 if (uris[0].dtype == LTTNG_DST_PATH) {
2750 ret = -LTTNG_ERR_INVALID;
2751 goto end;
2752 }
2753 } else {
2754 size = 0;
2755 }
2756
2757 lsm.u.session_live.nb_uri = size;
2758 lsm.u.session_live.timer_interval = timer_interval;
2759
2760 ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, uris,
2761 sizeof(struct lttng_uri) * size, NULL);
2762
2763 end:
2764 free(uris);
2765 return ret;
2766 }
2767
2768 /*
2769 * List PIDs in the tracker.
2770 *
2771 * enabled is set to whether the PID tracker is enabled.
2772 * pids is set to an allocated array of PIDs currently tracked. On
2773 * success, pids must be freed by the caller.
2774 * nr_pids is set to the number of entries contained by the pids array.
2775 *
2776 * Returns 0 on success, else a negative LTTng error code.
2777 */
2778 int lttng_list_tracker_pids(struct lttng_handle *handle,
2779 int *_enabled, int32_t **_pids, size_t *_nr_pids)
2780 {
2781 int ret;
2782 int enabled = 1;
2783 struct lttcomm_session_msg lsm;
2784 size_t nr_pids;
2785 int32_t *pids = NULL;
2786
2787 if (handle == NULL) {
2788 return -LTTNG_ERR_INVALID;
2789 }
2790
2791 memset(&lsm, 0, sizeof(lsm));
2792 lsm.cmd_type = LTTNG_LIST_TRACKER_PIDS;
2793 lttng_ctl_copy_string(lsm.session.name, handle->session_name,
2794 sizeof(lsm.session.name));
2795 lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
2796
2797 ret = lttng_ctl_ask_sessiond(&lsm, (void **) &pids);
2798 if (ret < 0) {
2799 return ret;
2800 }
2801 nr_pids = ret / sizeof(int32_t);
2802 if (nr_pids > 0 && !pids) {
2803 return -LTTNG_ERR_UNK;
2804 }
2805 if (nr_pids == 1 && pids[0] == -1) {
2806 free(pids);
2807 pids = NULL;
2808 enabled = 0;
2809 nr_pids = 0;
2810 }
2811 *_enabled = enabled;
2812 *_pids = pids;
2813 *_nr_pids = nr_pids;
2814 return 0;
2815 }
2816
2817 /*
2818 * Regenerate the metadata for a session.
2819 * Return 0 on success, a negative error code on error.
2820 */
2821 int lttng_regenerate_metadata(const char *session_name)
2822 {
2823 int ret;
2824 struct lttcomm_session_msg lsm;
2825
2826 if (!session_name) {
2827 ret = -LTTNG_ERR_INVALID;
2828 goto end;
2829 }
2830
2831 memset(&lsm, 0, sizeof(lsm));
2832 lsm.cmd_type = LTTNG_REGENERATE_METADATA;
2833
2834 lttng_ctl_copy_string(lsm.session.name, session_name,
2835 sizeof(lsm.session.name));
2836
2837 ret = lttng_ctl_ask_sessiond(&lsm, NULL);
2838 if (ret < 0) {
2839 goto end;
2840 }
2841
2842 ret = 0;
2843 end:
2844 return ret;
2845 }
2846
2847 /*
2848 * Deprecated, replaced by lttng_regenerate_metadata.
2849 */
2850 int lttng_metadata_regenerate(const char *session_name)
2851 {
2852 return lttng_regenerate_metadata(session_name);
2853 }
2854
2855 /*
2856 * Regenerate the statedump of a session.
2857 * Return 0 on success, a negative error code on error.
2858 */
2859 int lttng_regenerate_statedump(const char *session_name)
2860 {
2861 int ret;
2862 struct lttcomm_session_msg lsm;
2863
2864 if (!session_name) {
2865 ret = -LTTNG_ERR_INVALID;
2866 goto end;
2867 }
2868
2869 memset(&lsm, 0, sizeof(lsm));
2870 lsm.cmd_type = LTTNG_REGENERATE_STATEDUMP;
2871
2872 lttng_ctl_copy_string(lsm.session.name, session_name,
2873 sizeof(lsm.session.name));
2874
2875 ret = lttng_ctl_ask_sessiond(&lsm, NULL);
2876 if (ret < 0) {
2877 goto end;
2878 }
2879
2880 ret = 0;
2881 end:
2882 return ret;
2883 }
2884
2885 int lttng_register_trigger(struct lttng_trigger *trigger)
2886 {
2887 int ret;
2888 struct lttcomm_session_msg lsm;
2889 struct lttng_dynamic_buffer buffer;
2890
2891 lttng_dynamic_buffer_init(&buffer);
2892 if (!trigger) {
2893 ret = -LTTNG_ERR_INVALID;
2894 goto end;
2895 }
2896
2897 if (!lttng_trigger_validate(trigger)) {
2898 ret = -LTTNG_ERR_INVALID_TRIGGER;
2899 goto end;
2900 }
2901
2902 ret = lttng_trigger_serialize(trigger, &buffer);
2903 if (ret < 0) {
2904 ret = -LTTNG_ERR_UNK;
2905 goto end;
2906 }
2907
2908 memset(&lsm, 0, sizeof(lsm));
2909 lsm.cmd_type = LTTNG_REGISTER_TRIGGER;
2910 lsm.u.trigger.length = (uint32_t) buffer.size;
2911 ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buffer.data,
2912 buffer.size, NULL);
2913 end:
2914 lttng_dynamic_buffer_reset(&buffer);
2915 return ret;
2916 }
2917
2918 int lttng_unregister_trigger(struct lttng_trigger *trigger)
2919 {
2920 int ret;
2921 struct lttcomm_session_msg lsm;
2922 struct lttng_dynamic_buffer buffer;
2923
2924 lttng_dynamic_buffer_init(&buffer);
2925 if (!trigger) {
2926 ret = -LTTNG_ERR_INVALID;
2927 goto end;
2928 }
2929
2930 if (!lttng_trigger_validate(trigger)) {
2931 ret = -LTTNG_ERR_INVALID_TRIGGER;
2932 goto end;
2933 }
2934
2935 ret = lttng_trigger_serialize(trigger, &buffer);
2936 if (ret < 0) {
2937 ret = -LTTNG_ERR_UNK;
2938 goto end;
2939 }
2940
2941 memset(&lsm, 0, sizeof(lsm));
2942 lsm.cmd_type = LTTNG_UNREGISTER_TRIGGER;
2943 lsm.u.trigger.length = (uint32_t) buffer.size;
2944 ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buffer.data,
2945 buffer.size, NULL);
2946 end:
2947 lttng_dynamic_buffer_reset(&buffer);
2948 return ret;
2949 }
2950
2951 /*
2952 * lib constructor.
2953 */
2954 static void __attribute__((constructor)) init(void)
2955 {
2956 /* Set default session group */
2957 lttng_set_tracing_group(DEFAULT_TRACING_GROUP);
2958 }
2959
2960 /*
2961 * lib destructor.
2962 */
2963 static void __attribute__((destructor)) lttng_ctl_exit(void)
2964 {
2965 free(tracing_group);
2966 }
This page took 0.118083 seconds and 4 git commands to generate.