2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <urcu/list.h>
23 #include <urcu/uatomic.h>
27 #include <common/defaults.h>
28 #include <common/common.h>
29 #include <common/sessiond-comm/sessiond-comm.h>
30 #include <common/relayd/relayd.h>
31 #include <common/utils.h>
32 #include <common/compat/string.h>
33 #include <common/kernel-ctl/kernel-ctl.h>
34 #include <common/dynamic-buffer.h>
35 #include <common/buffer-view.h>
36 #include <common/trace-chunk.h>
37 #include <lttng/location-internal.h>
38 #include <lttng/trigger/trigger-internal.h>
39 #include <lttng/condition/condition.h>
40 #include <lttng/action/action.h>
41 #include <lttng/channel.h>
42 #include <lttng/channel-internal.h>
43 #include <lttng/rotate-internal.h>
44 #include <lttng/location-internal.h>
45 #include <lttng/session-internal.h>
46 #include <lttng/userspace-probe-internal.h>
47 #include <lttng/session-descriptor-internal.h>
48 #include <common/string-utils/string-utils.h>
53 #include "health-sessiond.h"
55 #include "kernel-consumer.h"
56 #include "lttng-sessiond.h"
58 #include "lttng-syscall.h"
60 #include "buffer-registry.h"
61 #include "notification-thread.h"
62 #include "notification-thread-commands.h"
64 #include "rotation-thread.h"
66 #include "agent-thread.h"
70 /* Sleep for 100ms between each check for the shm path's deletion. */
71 #define SESSION_DESTROY_SHM_PATH_CHECK_DELAY_US 100000
73 struct cmd_destroy_session_reply_context
{
75 bool implicit_rotation_on_destroy
;
78 static enum lttng_error_code
wait_on_path(void *path
);
81 * Command completion handler that is used by the destroy command
82 * when a session that has a non-default shm_path is being destroyed.
84 * See comment in cmd_destroy_session() for the rationale.
86 static struct destroy_completion_handler
{
87 struct cmd_completion_handler handler
;
88 char shm_path
[member_sizeof(struct ltt_session
, shm_path
)];
89 } destroy_completion_handler
= {
92 .data
= destroy_completion_handler
.shm_path
97 static struct cmd_completion_handler
*current_completion_handler
;
100 * Used to keep a unique index for each relayd socket created where this value
101 * is associated with streams on the consumer so it can match the right relayd
102 * to send to. It must be accessed with the relayd_net_seq_idx_lock
105 static pthread_mutex_t relayd_net_seq_idx_lock
= PTHREAD_MUTEX_INITIALIZER
;
106 static uint64_t relayd_net_seq_idx
;
108 static int validate_ust_event_name(const char *);
109 static int cmd_enable_event_internal(struct ltt_session
*session
,
110 struct lttng_domain
*domain
,
111 char *channel_name
, struct lttng_event
*event
,
112 char *filter_expression
,
113 struct lttng_filter_bytecode
*filter
,
114 struct lttng_event_exclusion
*exclusion
,
118 * Create a session path used by list_lttng_sessions for the case that the
119 * session consumer is on the network.
121 static int build_network_session_path(char *dst
, size_t size
,
122 struct ltt_session
*session
)
124 int ret
, kdata_port
, udata_port
;
125 struct lttng_uri
*kuri
= NULL
, *uuri
= NULL
, *uri
= NULL
;
126 char tmp_uurl
[PATH_MAX
], tmp_urls
[PATH_MAX
];
131 memset(tmp_urls
, 0, sizeof(tmp_urls
));
132 memset(tmp_uurl
, 0, sizeof(tmp_uurl
));
134 kdata_port
= udata_port
= DEFAULT_NETWORK_DATA_PORT
;
136 if (session
->kernel_session
&& session
->kernel_session
->consumer
) {
137 kuri
= &session
->kernel_session
->consumer
->dst
.net
.control
;
138 kdata_port
= session
->kernel_session
->consumer
->dst
.net
.data
.port
;
141 if (session
->ust_session
&& session
->ust_session
->consumer
) {
142 uuri
= &session
->ust_session
->consumer
->dst
.net
.control
;
143 udata_port
= session
->ust_session
->consumer
->dst
.net
.data
.port
;
146 if (uuri
== NULL
&& kuri
== NULL
) {
147 uri
= &session
->consumer
->dst
.net
.control
;
148 kdata_port
= session
->consumer
->dst
.net
.data
.port
;
149 } else if (kuri
&& uuri
) {
150 ret
= uri_compare(kuri
, uuri
);
154 /* Build uuri URL string */
155 ret
= uri_to_str_url(uuri
, tmp_uurl
, sizeof(tmp_uurl
));
162 } else if (kuri
&& uuri
== NULL
) {
164 } else if (uuri
&& kuri
== NULL
) {
168 ret
= uri_to_str_url(uri
, tmp_urls
, sizeof(tmp_urls
));
174 * Do we have a UST url set. If yes, this means we have both kernel and UST
177 if (*tmp_uurl
!= '\0') {
178 ret
= snprintf(dst
, size
, "[K]: %s [data: %d] -- [U]: %s [data: %d]",
179 tmp_urls
, kdata_port
, tmp_uurl
, udata_port
);
182 if (kuri
|| (!kuri
&& !uuri
)) {
185 /* No kernel URI, use the UST port. */
188 ret
= snprintf(dst
, size
, "%s [data: %d]", tmp_urls
, dport
);
196 * Get run-time attributes if the session has been started (discarded events,
199 static int get_kernel_runtime_stats(struct ltt_session
*session
,
200 struct ltt_kernel_channel
*kchan
, uint64_t *discarded_events
,
201 uint64_t *lost_packets
)
205 if (!session
->has_been_started
) {
207 *discarded_events
= 0;
212 ret
= consumer_get_discarded_events(session
->id
, kchan
->key
,
213 session
->kernel_session
->consumer
,
219 ret
= consumer_get_lost_packets(session
->id
, kchan
->key
,
220 session
->kernel_session
->consumer
,
231 * Get run-time attributes if the session has been started (discarded events,
234 static int get_ust_runtime_stats(struct ltt_session
*session
,
235 struct ltt_ust_channel
*uchan
, uint64_t *discarded_events
,
236 uint64_t *lost_packets
)
239 struct ltt_ust_session
*usess
;
241 if (!discarded_events
|| !lost_packets
) {
246 usess
= session
->ust_session
;
247 assert(discarded_events
);
248 assert(lost_packets
);
250 if (!usess
|| !session
->has_been_started
) {
251 *discarded_events
= 0;
257 if (usess
->buffer_type
== LTTNG_BUFFER_PER_UID
) {
258 ret
= ust_app_uid_get_channel_runtime_stats(usess
->id
,
259 &usess
->buffer_reg_uid_list
,
260 usess
->consumer
, uchan
->id
,
261 uchan
->attr
.overwrite
,
264 } else if (usess
->buffer_type
== LTTNG_BUFFER_PER_PID
) {
265 ret
= ust_app_pid_get_channel_runtime_stats(usess
,
266 uchan
, usess
->consumer
,
267 uchan
->attr
.overwrite
,
273 *discarded_events
+= uchan
->per_pid_closed_app_discarded
;
274 *lost_packets
+= uchan
->per_pid_closed_app_lost
;
276 ERR("Unsupported buffer type");
287 * Fill lttng_channel array of all channels.
289 static ssize_t
list_lttng_channels(enum lttng_domain_type domain
,
290 struct ltt_session
*session
, struct lttng_channel
*channels
,
291 struct lttng_channel_extended
*chan_exts
)
294 struct ltt_kernel_channel
*kchan
;
296 DBG("Listing channels for session %s", session
->name
);
299 case LTTNG_DOMAIN_KERNEL
:
300 /* Kernel channels */
301 if (session
->kernel_session
!= NULL
) {
302 cds_list_for_each_entry(kchan
,
303 &session
->kernel_session
->channel_list
.head
, list
) {
304 uint64_t discarded_events
, lost_packets
;
305 struct lttng_channel_extended
*extended
;
307 extended
= (struct lttng_channel_extended
*)
308 kchan
->channel
->attr
.extended
.ptr
;
310 ret
= get_kernel_runtime_stats(session
, kchan
,
311 &discarded_events
, &lost_packets
);
315 /* Copy lttng_channel struct to array */
316 memcpy(&channels
[i
], kchan
->channel
, sizeof(struct lttng_channel
));
317 channels
[i
].enabled
= kchan
->enabled
;
318 chan_exts
[i
].discarded_events
=
320 chan_exts
[i
].lost_packets
= lost_packets
;
321 chan_exts
[i
].monitor_timer_interval
=
322 extended
->monitor_timer_interval
;
323 chan_exts
[i
].blocking_timeout
= 0;
328 case LTTNG_DOMAIN_UST
:
330 struct lttng_ht_iter iter
;
331 struct ltt_ust_channel
*uchan
;
334 cds_lfht_for_each_entry(session
->ust_session
->domain_global
.channels
->ht
,
335 &iter
.iter
, uchan
, node
.node
) {
336 uint64_t discarded_events
= 0, lost_packets
= 0;
338 if (lttng_strncpy(channels
[i
].name
, uchan
->name
,
339 LTTNG_SYMBOL_NAME_LEN
)) {
342 channels
[i
].attr
.overwrite
= uchan
->attr
.overwrite
;
343 channels
[i
].attr
.subbuf_size
= uchan
->attr
.subbuf_size
;
344 channels
[i
].attr
.num_subbuf
= uchan
->attr
.num_subbuf
;
345 channels
[i
].attr
.switch_timer_interval
=
346 uchan
->attr
.switch_timer_interval
;
347 channels
[i
].attr
.read_timer_interval
=
348 uchan
->attr
.read_timer_interval
;
349 channels
[i
].enabled
= uchan
->enabled
;
350 channels
[i
].attr
.tracefile_size
= uchan
->tracefile_size
;
351 channels
[i
].attr
.tracefile_count
= uchan
->tracefile_count
;
354 * Map enum lttng_ust_output to enum lttng_event_output.
356 switch (uchan
->attr
.output
) {
358 channels
[i
].attr
.output
= LTTNG_EVENT_MMAP
;
362 * LTTNG_UST_MMAP is the only supported UST
369 chan_exts
[i
].monitor_timer_interval
=
370 uchan
->monitor_timer_interval
;
371 chan_exts
[i
].blocking_timeout
=
372 uchan
->attr
.u
.s
.blocking_timeout
;
374 ret
= get_ust_runtime_stats(session
, uchan
,
375 &discarded_events
, &lost_packets
);
379 chan_exts
[i
].discarded_events
= discarded_events
;
380 chan_exts
[i
].lost_packets
= lost_packets
;
392 return -LTTNG_ERR_FATAL
;
398 static int increment_extended_len(const char *filter_expression
,
399 struct lttng_event_exclusion
*exclusion
,
400 const struct lttng_userspace_probe_location
*probe_location
,
401 size_t *extended_len
)
405 *extended_len
+= sizeof(struct lttcomm_event_extended_header
);
407 if (filter_expression
) {
408 *extended_len
+= strlen(filter_expression
) + 1;
412 *extended_len
+= exclusion
->count
* LTTNG_SYMBOL_NAME_LEN
;
415 if (probe_location
) {
416 ret
= lttng_userspace_probe_location_serialize(probe_location
,
421 *extended_len
+= ret
;
428 static int append_extended_info(const char *filter_expression
,
429 struct lttng_event_exclusion
*exclusion
,
430 struct lttng_userspace_probe_location
*probe_location
,
434 size_t filter_len
= 0;
435 size_t nb_exclusions
= 0;
436 size_t userspace_probe_location_len
= 0;
437 struct lttng_dynamic_buffer location_buffer
;
438 struct lttcomm_event_extended_header extended_header
;
440 if (filter_expression
) {
441 filter_len
= strlen(filter_expression
) + 1;
445 nb_exclusions
= exclusion
->count
;
448 if (probe_location
) {
449 lttng_dynamic_buffer_init(&location_buffer
);
450 ret
= lttng_userspace_probe_location_serialize(probe_location
,
451 &location_buffer
, NULL
);
456 userspace_probe_location_len
= location_buffer
.size
;
459 /* Set header fields */
460 extended_header
.filter_len
= filter_len
;
461 extended_header
.nb_exclusions
= nb_exclusions
;
462 extended_header
.userspace_probe_location_len
= userspace_probe_location_len
;
465 memcpy(*extended_at
, &extended_header
, sizeof(extended_header
));
466 *extended_at
+= sizeof(extended_header
);
468 /* Copy filter string */
469 if (filter_expression
) {
470 memcpy(*extended_at
, filter_expression
, filter_len
);
471 *extended_at
+= filter_len
;
474 /* Copy exclusion names */
476 size_t len
= nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
;
478 memcpy(*extended_at
, &exclusion
->names
, len
);
482 if (probe_location
) {
483 memcpy(*extended_at
, location_buffer
.data
, location_buffer
.size
);
484 *extended_at
+= location_buffer
.size
;
485 lttng_dynamic_buffer_reset(&location_buffer
);
493 * Create a list of agent domain events.
495 * Return number of events in list on success or else a negative value.
497 static int list_lttng_agent_events(struct agent
*agt
,
498 struct lttng_event
**events
, size_t *total_size
)
501 unsigned int nb_event
= 0;
502 struct agent_event
*event
;
503 struct lttng_event
*tmp_events
= NULL
;
504 struct lttng_ht_iter iter
;
505 size_t extended_len
= 0;
511 DBG3("Listing agent events");
514 nb_event
= lttng_ht_get_count(agt
->events
);
522 /* Compute required extended infos size */
523 extended_len
= nb_event
* sizeof(struct lttcomm_event_extended_header
);
526 * This is only valid because the commands which add events are
527 * processed in the same thread as the listing.
530 cds_lfht_for_each_entry(agt
->events
->ht
, &iter
.iter
, event
, node
.node
) {
531 ret
= increment_extended_len(event
->filter_expression
, NULL
, NULL
,
534 DBG("Error computing the length of extended info message");
535 ret
= -LTTNG_ERR_FATAL
;
541 *total_size
= nb_event
* sizeof(*tmp_events
) + extended_len
;
542 tmp_events
= zmalloc(*total_size
);
544 PERROR("zmalloc agent events session");
545 ret
= -LTTNG_ERR_FATAL
;
549 extended_at
= ((uint8_t *) tmp_events
) +
550 nb_event
* sizeof(struct lttng_event
);
553 cds_lfht_for_each_entry(agt
->events
->ht
, &iter
.iter
, event
, node
.node
) {
554 strncpy(tmp_events
[i
].name
, event
->name
, sizeof(tmp_events
[i
].name
));
555 tmp_events
[i
].name
[sizeof(tmp_events
[i
].name
) - 1] = '\0';
556 tmp_events
[i
].enabled
= event
->enabled
;
557 tmp_events
[i
].loglevel
= event
->loglevel_value
;
558 tmp_events
[i
].loglevel_type
= event
->loglevel_type
;
561 /* Append extended info */
562 ret
= append_extended_info(event
->filter_expression
, NULL
, NULL
,
565 DBG("Error appending extended info message");
566 ret
= -LTTNG_ERR_FATAL
;
571 *events
= tmp_events
;
573 assert(nb_event
== i
);
584 * Create a list of ust global domain events.
586 static int list_lttng_ust_global_events(char *channel_name
,
587 struct ltt_ust_domain_global
*ust_global
,
588 struct lttng_event
**events
, size_t *total_size
)
591 unsigned int nb_event
= 0;
592 struct lttng_ht_iter iter
;
593 struct lttng_ht_node_str
*node
;
594 struct ltt_ust_channel
*uchan
;
595 struct ltt_ust_event
*uevent
;
596 struct lttng_event
*tmp
;
597 size_t extended_len
= 0;
600 DBG("Listing UST global events for channel %s", channel_name
);
604 lttng_ht_lookup(ust_global
->channels
, (void *)channel_name
, &iter
);
605 node
= lttng_ht_iter_get_node_str(&iter
);
607 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
611 uchan
= caa_container_of(&node
->node
, struct ltt_ust_channel
, node
.node
);
613 nb_event
= lttng_ht_get_count(uchan
->events
);
620 DBG3("Listing UST global %d events", nb_event
);
622 /* Compute required extended infos size */
623 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
624 if (uevent
->internal
) {
629 ret
= increment_extended_len(uevent
->filter_expression
,
630 uevent
->exclusion
, NULL
, &extended_len
);
632 DBG("Error computing the length of extended info message");
633 ret
= -LTTNG_ERR_FATAL
;
638 /* All events are internal, skip. */
644 *total_size
= nb_event
* sizeof(struct lttng_event
) + extended_len
;
645 tmp
= zmalloc(*total_size
);
647 ret
= -LTTNG_ERR_FATAL
;
651 extended_at
= ((uint8_t *) tmp
) + nb_event
* sizeof(struct lttng_event
);
653 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
654 if (uevent
->internal
) {
655 /* This event should remain hidden from clients */
658 strncpy(tmp
[i
].name
, uevent
->attr
.name
, LTTNG_SYMBOL_NAME_LEN
);
659 tmp
[i
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
660 tmp
[i
].enabled
= uevent
->enabled
;
662 switch (uevent
->attr
.instrumentation
) {
663 case LTTNG_UST_TRACEPOINT
:
664 tmp
[i
].type
= LTTNG_EVENT_TRACEPOINT
;
666 case LTTNG_UST_PROBE
:
667 tmp
[i
].type
= LTTNG_EVENT_PROBE
;
669 case LTTNG_UST_FUNCTION
:
670 tmp
[i
].type
= LTTNG_EVENT_FUNCTION
;
674 tmp
[i
].loglevel
= uevent
->attr
.loglevel
;
675 switch (uevent
->attr
.loglevel_type
) {
676 case LTTNG_UST_LOGLEVEL_ALL
:
677 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
679 case LTTNG_UST_LOGLEVEL_RANGE
:
680 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
682 case LTTNG_UST_LOGLEVEL_SINGLE
:
683 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
686 if (uevent
->filter
) {
689 if (uevent
->exclusion
) {
690 tmp
[i
].exclusion
= 1;
694 /* Append extended info */
695 ret
= append_extended_info(uevent
->filter_expression
,
696 uevent
->exclusion
, NULL
, &extended_at
);
698 DBG("Error appending extended info message");
699 ret
= -LTTNG_ERR_FATAL
;
712 * Fill lttng_event array of all kernel events in the channel.
714 static int list_lttng_kernel_events(char *channel_name
,
715 struct ltt_kernel_session
*kernel_session
,
716 struct lttng_event
**events
, size_t *total_size
)
719 unsigned int nb_event
;
720 struct ltt_kernel_event
*event
;
721 struct ltt_kernel_channel
*kchan
;
722 size_t extended_len
= 0;
725 kchan
= trace_kernel_get_channel_by_name(channel_name
, kernel_session
);
727 ret
= LTTNG_ERR_KERN_CHAN_NOT_FOUND
;
731 nb_event
= kchan
->event_count
;
733 DBG("Listing events for channel %s", kchan
->channel
->name
);
741 /* Compute required extended infos size */
742 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
743 ret
= increment_extended_len(event
->filter_expression
, NULL
,
744 event
->userspace_probe_location
,
747 DBG("Error computing the length of extended info message");
748 ret
= -LTTNG_ERR_FATAL
;
753 *total_size
= nb_event
* sizeof(struct lttng_event
) + extended_len
;
754 *events
= zmalloc(*total_size
);
755 if (*events
== NULL
) {
756 ret
= -LTTNG_ERR_FATAL
;
760 extended_at
= ((void *) *events
) +
761 nb_event
* sizeof(struct lttng_event
);
763 /* Kernel channels */
764 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
765 strncpy((*events
)[i
].name
, event
->event
->name
, LTTNG_SYMBOL_NAME_LEN
);
766 (*events
)[i
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
767 (*events
)[i
].enabled
= event
->enabled
;
768 (*events
)[i
].filter
=
769 (unsigned char) !!event
->filter_expression
;
771 switch (event
->event
->instrumentation
) {
772 case LTTNG_KERNEL_TRACEPOINT
:
773 (*events
)[i
].type
= LTTNG_EVENT_TRACEPOINT
;
775 case LTTNG_KERNEL_KRETPROBE
:
776 (*events
)[i
].type
= LTTNG_EVENT_FUNCTION
;
777 memcpy(&(*events
)[i
].attr
.probe
, &event
->event
->u
.kprobe
,
778 sizeof(struct lttng_kernel_kprobe
));
780 case LTTNG_KERNEL_KPROBE
:
781 (*events
)[i
].type
= LTTNG_EVENT_PROBE
;
782 memcpy(&(*events
)[i
].attr
.probe
, &event
->event
->u
.kprobe
,
783 sizeof(struct lttng_kernel_kprobe
));
785 case LTTNG_KERNEL_UPROBE
:
786 (*events
)[i
].type
= LTTNG_EVENT_USERSPACE_PROBE
;
788 case LTTNG_KERNEL_FUNCTION
:
789 (*events
)[i
].type
= LTTNG_EVENT_FUNCTION
;
790 memcpy(&((*events
)[i
].attr
.ftrace
), &event
->event
->u
.ftrace
,
791 sizeof(struct lttng_kernel_function
));
793 case LTTNG_KERNEL_NOOP
:
794 (*events
)[i
].type
= LTTNG_EVENT_NOOP
;
796 case LTTNG_KERNEL_SYSCALL
:
797 (*events
)[i
].type
= LTTNG_EVENT_SYSCALL
;
799 case LTTNG_KERNEL_ALL
:
807 /* Append extended info */
808 ret
= append_extended_info(event
->filter_expression
, NULL
,
809 event
->userspace_probe_location
, &extended_at
);
811 DBG("Error appending extended info message");
812 ret
= -LTTNG_ERR_FATAL
;
821 /* Negate the error code to differentiate the size from an error */
826 * Add URI so the consumer output object. Set the correct path depending on the
827 * domain adding the default trace directory.
829 static enum lttng_error_code
add_uri_to_consumer(
830 const struct ltt_session
*session
,
831 struct consumer_output
*consumer
,
832 struct lttng_uri
*uri
, enum lttng_domain_type domain
)
835 enum lttng_error_code ret_code
= LTTNG_OK
;
839 if (consumer
== NULL
) {
840 DBG("No consumer detected. Don't add URI. Stopping.");
841 ret_code
= LTTNG_ERR_NO_CONSUMER
;
846 case LTTNG_DOMAIN_KERNEL
:
847 ret
= lttng_strncpy(consumer
->domain_subdir
,
848 DEFAULT_KERNEL_TRACE_DIR
,
849 sizeof(consumer
->domain_subdir
));
851 case LTTNG_DOMAIN_UST
:
852 ret
= lttng_strncpy(consumer
->domain_subdir
,
853 DEFAULT_UST_TRACE_DIR
,
854 sizeof(consumer
->domain_subdir
));
858 * This case is possible is we try to add the URI to the global
859 * tracing session consumer object which in this case there is
862 memset(consumer
->domain_subdir
, 0,
863 sizeof(consumer
->domain_subdir
));
867 ERR("Failed to initialize consumer output domain subdirectory");
868 ret_code
= LTTNG_ERR_FATAL
;
872 switch (uri
->dtype
) {
875 DBG2("Setting network URI to consumer");
877 if (consumer
->type
== CONSUMER_DST_NET
) {
878 if ((uri
->stype
== LTTNG_STREAM_CONTROL
&&
879 consumer
->dst
.net
.control_isset
) ||
880 (uri
->stype
== LTTNG_STREAM_DATA
&&
881 consumer
->dst
.net
.data_isset
)) {
882 ret_code
= LTTNG_ERR_URL_EXIST
;
886 memset(&consumer
->dst
, 0, sizeof(consumer
->dst
));
889 /* Set URI into consumer output object */
890 ret
= consumer_set_network_uri(session
, consumer
, uri
);
894 } else if (ret
== 1) {
896 * URI was the same in the consumer so we do not append the subdir
897 * again so to not duplicate output dir.
904 if (*uri
->dst
.path
!= '/' || strstr(uri
->dst
.path
, "../")) {
905 ret_code
= LTTNG_ERR_INVALID
;
908 DBG2("Setting trace directory path from URI to %s",
910 memset(&consumer
->dst
, 0, sizeof(consumer
->dst
));
912 ret
= lttng_strncpy(consumer
->dst
.session_root_path
,
914 sizeof(consumer
->dst
.session_root_path
));
915 consumer
->type
= CONSUMER_DST_LOCAL
;
925 * Init tracing by creating trace directory and sending fds kernel consumer.
927 static int init_kernel_tracing(struct ltt_kernel_session
*session
)
930 struct lttng_ht_iter iter
;
931 struct consumer_socket
*socket
;
937 if (session
->consumer_fds_sent
== 0 && session
->consumer
!= NULL
) {
938 cds_lfht_for_each_entry(session
->consumer
->socks
->ht
, &iter
.iter
,
940 pthread_mutex_lock(socket
->lock
);
941 ret
= kernel_consumer_send_session(socket
, session
);
942 pthread_mutex_unlock(socket
->lock
);
944 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
956 * Create a socket to the relayd using the URI.
958 * On success, the relayd_sock pointer is set to the created socket.
959 * Else, it remains untouched and an LTTng error code is returned.
961 static enum lttng_error_code
create_connect_relayd(struct lttng_uri
*uri
,
962 struct lttcomm_relayd_sock
**relayd_sock
,
963 struct consumer_output
*consumer
)
966 enum lttng_error_code status
= LTTNG_OK
;
967 struct lttcomm_relayd_sock
*rsock
;
969 rsock
= lttcomm_alloc_relayd_sock(uri
, RELAYD_VERSION_COMM_MAJOR
,
970 RELAYD_VERSION_COMM_MINOR
);
972 status
= LTTNG_ERR_FATAL
;
977 * Connect to relayd so we can proceed with a session creation. This call
978 * can possibly block for an arbitrary amount of time to set the health
979 * state to be in poll execution.
982 ret
= relayd_connect(rsock
);
985 ERR("Unable to reach lttng-relayd");
986 status
= LTTNG_ERR_RELAYD_CONNECT_FAIL
;
990 /* Create socket for control stream. */
991 if (uri
->stype
== LTTNG_STREAM_CONTROL
) {
992 DBG3("Creating relayd stream socket from URI");
994 /* Check relayd version */
995 ret
= relayd_version_check(rsock
);
996 if (ret
== LTTNG_ERR_RELAYD_VERSION_FAIL
) {
997 status
= LTTNG_ERR_RELAYD_VERSION_FAIL
;
999 } else if (ret
< 0) {
1000 ERR("Unable to reach lttng-relayd");
1001 status
= LTTNG_ERR_RELAYD_CONNECT_FAIL
;
1004 consumer
->relay_major_version
= rsock
->major
;
1005 consumer
->relay_minor_version
= rsock
->minor
;
1006 } else if (uri
->stype
== LTTNG_STREAM_DATA
) {
1007 DBG3("Creating relayd data socket from URI");
1009 /* Command is not valid */
1010 ERR("Relayd invalid stream type: %d", uri
->stype
);
1011 status
= LTTNG_ERR_INVALID
;
1015 *relayd_sock
= rsock
;
1020 /* The returned value is not useful since we are on an error path. */
1021 (void) relayd_close(rsock
);
1029 * Connect to the relayd using URI and send the socket to the right consumer.
1031 * The consumer socket lock must be held by the caller.
1033 * Returns LTTNG_OK on success or an LTTng error code on failure.
1035 static enum lttng_error_code
send_consumer_relayd_socket(
1036 unsigned int session_id
,
1037 struct lttng_uri
*relayd_uri
,
1038 struct consumer_output
*consumer
,
1039 struct consumer_socket
*consumer_sock
,
1040 const char *session_name
, const char *hostname
,
1041 int session_live_timer
,
1042 const uint64_t *current_chunk_id
,
1043 time_t session_creation_time
)
1046 struct lttcomm_relayd_sock
*rsock
= NULL
;
1047 enum lttng_error_code status
;
1049 /* Connect to relayd and make version check if uri is the control. */
1050 status
= create_connect_relayd(relayd_uri
, &rsock
, consumer
);
1051 if (status
!= LTTNG_OK
) {
1052 goto relayd_comm_error
;
1056 /* Set the network sequence index if not set. */
1057 if (consumer
->net_seq_index
== (uint64_t) -1ULL) {
1058 pthread_mutex_lock(&relayd_net_seq_idx_lock
);
1060 * Increment net_seq_idx because we are about to transfer the
1061 * new relayd socket to the consumer.
1062 * Assign unique key so the consumer can match streams.
1064 consumer
->net_seq_index
= ++relayd_net_seq_idx
;
1065 pthread_mutex_unlock(&relayd_net_seq_idx_lock
);
1068 /* Send relayd socket to consumer. */
1069 ret
= consumer_send_relayd_socket(consumer_sock
, rsock
, consumer
,
1070 relayd_uri
->stype
, session_id
,
1071 session_name
, hostname
, session_live_timer
,
1072 current_chunk_id
, session_creation_time
);
1074 status
= LTTNG_ERR_ENABLE_CONSUMER_FAIL
;
1078 /* Flag that the corresponding socket was sent. */
1079 if (relayd_uri
->stype
== LTTNG_STREAM_CONTROL
) {
1080 consumer_sock
->control_sock_sent
= 1;
1081 } else if (relayd_uri
->stype
== LTTNG_STREAM_DATA
) {
1082 consumer_sock
->data_sock_sent
= 1;
1086 * Close socket which was dup on the consumer side. The session daemon does
1087 * NOT keep track of the relayd socket(s) once transfer to the consumer.
1091 if (status
!= LTTNG_OK
) {
1093 * The consumer output for this session should not be used anymore
1094 * since the relayd connection failed thus making any tracing or/and
1095 * streaming not usable.
1097 consumer
->enabled
= 0;
1099 (void) relayd_close(rsock
);
1107 * Send both relayd sockets to a specific consumer and domain. This is a
1108 * helper function to facilitate sending the information to the consumer for a
1111 * The consumer socket lock must be held by the caller.
1113 * Returns LTTNG_OK, or an LTTng error code on failure.
1115 static enum lttng_error_code
send_consumer_relayd_sockets(
1116 enum lttng_domain_type domain
,
1117 unsigned int session_id
, struct consumer_output
*consumer
,
1118 struct consumer_socket
*sock
, const char *session_name
,
1119 const char *hostname
, int session_live_timer
,
1120 const uint64_t *current_chunk_id
, time_t session_creation_time
)
1122 enum lttng_error_code status
= LTTNG_OK
;
1127 /* Sending control relayd socket. */
1128 if (!sock
->control_sock_sent
) {
1129 status
= send_consumer_relayd_socket(session_id
,
1130 &consumer
->dst
.net
.control
, consumer
, sock
,
1131 session_name
, hostname
, session_live_timer
,
1132 current_chunk_id
, session_creation_time
);
1133 if (status
!= LTTNG_OK
) {
1138 /* Sending data relayd socket. */
1139 if (!sock
->data_sock_sent
) {
1140 status
= send_consumer_relayd_socket(session_id
,
1141 &consumer
->dst
.net
.data
, consumer
, sock
,
1142 session_name
, hostname
, session_live_timer
,
1143 current_chunk_id
, session_creation_time
);
1144 if (status
!= LTTNG_OK
) {
1154 * Setup relayd connections for a tracing session. First creates the socket to
1155 * the relayd and send them to the right domain consumer. Consumer type MUST be
1158 int cmd_setup_relayd(struct ltt_session
*session
)
1161 struct ltt_ust_session
*usess
;
1162 struct ltt_kernel_session
*ksess
;
1163 struct consumer_socket
*socket
;
1164 struct lttng_ht_iter iter
;
1165 LTTNG_OPTIONAL(uint64_t) current_chunk_id
= {};
1169 usess
= session
->ust_session
;
1170 ksess
= session
->kernel_session
;
1172 DBG("Setting relayd for session %s", session
->name
);
1174 if (session
->current_trace_chunk
) {
1175 enum lttng_trace_chunk_status status
= lttng_trace_chunk_get_id(
1176 session
->current_trace_chunk
, ¤t_chunk_id
.value
);
1178 if (status
== LTTNG_TRACE_CHUNK_STATUS_OK
) {
1179 current_chunk_id
.is_set
= true;
1181 ERR("Failed to get current trace chunk id");
1182 ret
= LTTNG_ERR_UNK
;
1189 if (usess
&& usess
->consumer
&& usess
->consumer
->type
== CONSUMER_DST_NET
1190 && usess
->consumer
->enabled
) {
1191 /* For each consumer socket, send relayd sockets */
1192 cds_lfht_for_each_entry(usess
->consumer
->socks
->ht
, &iter
.iter
,
1193 socket
, node
.node
) {
1194 pthread_mutex_lock(socket
->lock
);
1195 ret
= send_consumer_relayd_sockets(LTTNG_DOMAIN_UST
, session
->id
,
1196 usess
->consumer
, socket
,
1197 session
->name
, session
->hostname
,
1198 session
->live_timer
,
1199 current_chunk_id
.is_set
? ¤t_chunk_id
.value
: NULL
,
1200 session
->creation_time
);
1201 pthread_mutex_unlock(socket
->lock
);
1202 if (ret
!= LTTNG_OK
) {
1205 /* Session is now ready for network streaming. */
1206 session
->net_handle
= 1;
1208 session
->consumer
->relay_major_version
=
1209 usess
->consumer
->relay_major_version
;
1210 session
->consumer
->relay_minor_version
=
1211 usess
->consumer
->relay_minor_version
;
1214 if (ksess
&& ksess
->consumer
&& ksess
->consumer
->type
== CONSUMER_DST_NET
1215 && ksess
->consumer
->enabled
) {
1216 cds_lfht_for_each_entry(ksess
->consumer
->socks
->ht
, &iter
.iter
,
1217 socket
, node
.node
) {
1218 pthread_mutex_lock(socket
->lock
);
1219 ret
= send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL
, session
->id
,
1220 ksess
->consumer
, socket
,
1221 session
->name
, session
->hostname
,
1222 session
->live_timer
,
1223 current_chunk_id
.is_set
? ¤t_chunk_id
.value
: NULL
,
1224 session
->creation_time
);
1225 pthread_mutex_unlock(socket
->lock
);
1226 if (ret
!= LTTNG_OK
) {
1229 /* Session is now ready for network streaming. */
1230 session
->net_handle
= 1;
1232 session
->consumer
->relay_major_version
=
1233 ksess
->consumer
->relay_major_version
;
1234 session
->consumer
->relay_minor_version
=
1235 ksess
->consumer
->relay_minor_version
;
1244 * Start a kernel session by opening all necessary streams.
1246 static int start_kernel_session(struct ltt_kernel_session
*ksess
, int wpipe
)
1249 struct ltt_kernel_channel
*kchan
;
1251 /* Open kernel metadata */
1252 if (ksess
->metadata
== NULL
&& ksess
->output_traces
) {
1253 ret
= kernel_open_metadata(ksess
);
1255 ret
= LTTNG_ERR_KERN_META_FAIL
;
1260 /* Open kernel metadata stream */
1261 if (ksess
->metadata
&& ksess
->metadata_stream_fd
< 0) {
1262 ret
= kernel_open_metadata_stream(ksess
);
1264 ERR("Kernel create metadata stream failed");
1265 ret
= LTTNG_ERR_KERN_STREAM_FAIL
;
1270 /* For each channel */
1271 cds_list_for_each_entry(kchan
, &ksess
->channel_list
.head
, list
) {
1272 if (kchan
->stream_count
== 0) {
1273 ret
= kernel_open_channel_stream(kchan
);
1275 ret
= LTTNG_ERR_KERN_STREAM_FAIL
;
1278 /* Update the stream global counter */
1279 ksess
->stream_count_global
+= ret
;
1283 /* Setup kernel consumer socket and send fds to it */
1284 ret
= init_kernel_tracing(ksess
);
1286 ret
= LTTNG_ERR_KERN_START_FAIL
;
1290 /* This start the kernel tracing */
1291 ret
= kernel_start_session(ksess
);
1293 ret
= LTTNG_ERR_KERN_START_FAIL
;
1297 /* Quiescent wait after starting trace */
1298 kernel_wait_quiescent(wpipe
);
1309 * Command LTTNG_DISABLE_CHANNEL processed by the client thread.
1311 int cmd_disable_channel(struct ltt_session
*session
,
1312 enum lttng_domain_type domain
, char *channel_name
)
1315 struct ltt_ust_session
*usess
;
1317 usess
= session
->ust_session
;
1322 case LTTNG_DOMAIN_KERNEL
:
1324 ret
= channel_kernel_disable(session
->kernel_session
,
1326 if (ret
!= LTTNG_OK
) {
1330 kernel_wait_quiescent(kernel_tracer_fd
);
1333 case LTTNG_DOMAIN_UST
:
1335 struct ltt_ust_channel
*uchan
;
1336 struct lttng_ht
*chan_ht
;
1338 chan_ht
= usess
->domain_global
.channels
;
1340 uchan
= trace_ust_find_channel_by_name(chan_ht
, channel_name
);
1341 if (uchan
== NULL
) {
1342 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1346 ret
= channel_ust_disable(usess
, uchan
);
1347 if (ret
!= LTTNG_OK
) {
1353 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1365 * Command LTTNG_TRACK_PID processed by the client thread.
1367 * Called with session lock held.
1369 int cmd_track_pid(struct ltt_session
*session
, enum lttng_domain_type domain
,
1377 case LTTNG_DOMAIN_KERNEL
:
1379 struct ltt_kernel_session
*ksess
;
1381 ksess
= session
->kernel_session
;
1383 ret
= kernel_track_pid(ksess
, pid
);
1384 if (ret
!= LTTNG_OK
) {
1388 kernel_wait_quiescent(kernel_tracer_fd
);
1391 case LTTNG_DOMAIN_UST
:
1393 struct ltt_ust_session
*usess
;
1395 usess
= session
->ust_session
;
1397 ret
= trace_ust_track_pid(usess
, pid
);
1398 if (ret
!= LTTNG_OK
) {
1404 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1416 * Command LTTNG_UNTRACK_PID processed by the client thread.
1418 * Called with session lock held.
1420 int cmd_untrack_pid(struct ltt_session
*session
, enum lttng_domain_type domain
,
1428 case LTTNG_DOMAIN_KERNEL
:
1430 struct ltt_kernel_session
*ksess
;
1432 ksess
= session
->kernel_session
;
1434 ret
= kernel_untrack_pid(ksess
, pid
);
1435 if (ret
!= LTTNG_OK
) {
1439 kernel_wait_quiescent(kernel_tracer_fd
);
1442 case LTTNG_DOMAIN_UST
:
1444 struct ltt_ust_session
*usess
;
1446 usess
= session
->ust_session
;
1448 ret
= trace_ust_untrack_pid(usess
, pid
);
1449 if (ret
!= LTTNG_OK
) {
1455 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1467 * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
1469 * The wpipe arguments is used as a notifier for the kernel thread.
1471 int cmd_enable_channel(struct ltt_session
*session
,
1472 struct lttng_domain
*domain
, struct lttng_channel
*attr
, int wpipe
)
1475 struct ltt_ust_session
*usess
= session
->ust_session
;
1476 struct lttng_ht
*chan_ht
;
1483 len
= lttng_strnlen(attr
->name
, sizeof(attr
->name
));
1485 /* Validate channel name */
1486 if (attr
->name
[0] == '.' ||
1487 memchr(attr
->name
, '/', len
) != NULL
) {
1488 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1492 DBG("Enabling channel %s for session %s", attr
->name
, session
->name
);
1497 * Don't try to enable a channel if the session has been started at
1498 * some point in time before. The tracer does not allow it.
1500 if (session
->has_been_started
) {
1501 ret
= LTTNG_ERR_TRACE_ALREADY_STARTED
;
1506 * If the session is a live session, remove the switch timer, the
1507 * live timer does the same thing but sends also synchronisation
1508 * beacons for inactive streams.
1510 if (session
->live_timer
> 0) {
1511 attr
->attr
.live_timer_interval
= session
->live_timer
;
1512 attr
->attr
.switch_timer_interval
= 0;
1515 /* Check for feature support */
1516 switch (domain
->type
) {
1517 case LTTNG_DOMAIN_KERNEL
:
1519 if (kernel_supports_ring_buffer_snapshot_sample_positions(kernel_tracer_fd
) != 1) {
1520 /* Sampling position of buffer is not supported */
1521 WARN("Kernel tracer does not support buffer monitoring. "
1522 "Setting the monitor interval timer to 0 "
1523 "(disabled) for channel '%s' of session '%s'",
1524 attr
-> name
, session
->name
);
1525 lttng_channel_set_monitor_timer_interval(attr
, 0);
1529 case LTTNG_DOMAIN_UST
:
1531 case LTTNG_DOMAIN_JUL
:
1532 case LTTNG_DOMAIN_LOG4J
:
1533 case LTTNG_DOMAIN_PYTHON
:
1534 if (!agent_tracing_is_enabled()) {
1535 DBG("Attempted to enable a channel in an agent domain but the agent thread is not running");
1536 ret
= LTTNG_ERR_AGENT_TRACING_DISABLED
;
1541 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1545 switch (domain
->type
) {
1546 case LTTNG_DOMAIN_KERNEL
:
1548 struct ltt_kernel_channel
*kchan
;
1550 kchan
= trace_kernel_get_channel_by_name(attr
->name
,
1551 session
->kernel_session
);
1552 if (kchan
== NULL
) {
1553 if (session
->snapshot
.nb_output
> 0 ||
1554 session
->snapshot_mode
) {
1555 /* Enforce mmap output for snapshot sessions. */
1556 attr
->attr
.output
= LTTNG_EVENT_MMAP
;
1558 ret
= channel_kernel_create(session
->kernel_session
, attr
, wpipe
);
1559 if (attr
->name
[0] != '\0') {
1560 session
->kernel_session
->has_non_default_channel
= 1;
1563 ret
= channel_kernel_enable(session
->kernel_session
, kchan
);
1566 if (ret
!= LTTNG_OK
) {
1570 kernel_wait_quiescent(kernel_tracer_fd
);
1573 case LTTNG_DOMAIN_UST
:
1574 case LTTNG_DOMAIN_JUL
:
1575 case LTTNG_DOMAIN_LOG4J
:
1576 case LTTNG_DOMAIN_PYTHON
:
1578 struct ltt_ust_channel
*uchan
;
1583 * Current agent implementation limitations force us to allow
1584 * only one channel at once in "agent" subdomains. Each
1585 * subdomain has a default channel name which must be strictly
1588 if (domain
->type
== LTTNG_DOMAIN_JUL
) {
1589 if (strncmp(attr
->name
, DEFAULT_JUL_CHANNEL_NAME
,
1590 LTTNG_SYMBOL_NAME_LEN
)) {
1591 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1594 } else if (domain
->type
== LTTNG_DOMAIN_LOG4J
) {
1595 if (strncmp(attr
->name
, DEFAULT_LOG4J_CHANNEL_NAME
,
1596 LTTNG_SYMBOL_NAME_LEN
)) {
1597 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1600 } else if (domain
->type
== LTTNG_DOMAIN_PYTHON
) {
1601 if (strncmp(attr
->name
, DEFAULT_PYTHON_CHANNEL_NAME
,
1602 LTTNG_SYMBOL_NAME_LEN
)) {
1603 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1608 chan_ht
= usess
->domain_global
.channels
;
1610 uchan
= trace_ust_find_channel_by_name(chan_ht
, attr
->name
);
1611 if (uchan
== NULL
) {
1612 ret
= channel_ust_create(usess
, attr
, domain
->buf_type
);
1613 if (attr
->name
[0] != '\0') {
1614 usess
->has_non_default_channel
= 1;
1617 ret
= channel_ust_enable(usess
, uchan
);
1622 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1626 if (ret
== LTTNG_OK
&& attr
->attr
.output
!= LTTNG_EVENT_MMAP
) {
1627 session
->has_non_mmap_channel
= true;
1636 * Command LTTNG_DISABLE_EVENT processed by the client thread.
1638 int cmd_disable_event(struct ltt_session
*session
,
1639 enum lttng_domain_type domain
, char *channel_name
,
1640 struct lttng_event
*event
)
1645 DBG("Disable event command for event \'%s\'", event
->name
);
1647 event_name
= event
->name
;
1649 /* Error out on unhandled search criteria */
1650 if (event
->loglevel_type
|| event
->loglevel
!= -1 || event
->enabled
1651 || event
->pid
|| event
->filter
|| event
->exclusion
) {
1652 ret
= LTTNG_ERR_UNK
;
1659 case LTTNG_DOMAIN_KERNEL
:
1661 struct ltt_kernel_channel
*kchan
;
1662 struct ltt_kernel_session
*ksess
;
1664 ksess
= session
->kernel_session
;
1667 * If a non-default channel has been created in the
1668 * session, explicitely require that -c chan_name needs
1671 if (ksess
->has_non_default_channel
&& channel_name
[0] == '\0') {
1672 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
1676 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksess
);
1677 if (kchan
== NULL
) {
1678 ret
= LTTNG_ERR_KERN_CHAN_NOT_FOUND
;
1682 switch (event
->type
) {
1683 case LTTNG_EVENT_ALL
:
1684 case LTTNG_EVENT_TRACEPOINT
:
1685 case LTTNG_EVENT_SYSCALL
:
1686 case LTTNG_EVENT_PROBE
:
1687 case LTTNG_EVENT_FUNCTION
:
1688 case LTTNG_EVENT_FUNCTION_ENTRY
:/* fall-through */
1689 if (event_name
[0] == '\0') {
1690 ret
= event_kernel_disable_event(kchan
,
1693 ret
= event_kernel_disable_event(kchan
,
1694 event_name
, event
->type
);
1696 if (ret
!= LTTNG_OK
) {
1701 ret
= LTTNG_ERR_UNK
;
1705 kernel_wait_quiescent(kernel_tracer_fd
);
1708 case LTTNG_DOMAIN_UST
:
1710 struct ltt_ust_channel
*uchan
;
1711 struct ltt_ust_session
*usess
;
1713 usess
= session
->ust_session
;
1715 if (validate_ust_event_name(event_name
)) {
1716 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
1721 * If a non-default channel has been created in the
1722 * session, explicitly require that -c chan_name needs
1725 if (usess
->has_non_default_channel
&& channel_name
[0] == '\0') {
1726 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
1730 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
1732 if (uchan
== NULL
) {
1733 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1737 switch (event
->type
) {
1738 case LTTNG_EVENT_ALL
:
1740 * An empty event name means that everything
1741 * should be disabled.
1743 if (event
->name
[0] == '\0') {
1744 ret
= event_ust_disable_all_tracepoints(usess
, uchan
);
1746 ret
= event_ust_disable_tracepoint(usess
, uchan
,
1749 if (ret
!= LTTNG_OK
) {
1754 ret
= LTTNG_ERR_UNK
;
1758 DBG3("Disable UST event %s in channel %s completed", event_name
,
1762 case LTTNG_DOMAIN_LOG4J
:
1763 case LTTNG_DOMAIN_JUL
:
1764 case LTTNG_DOMAIN_PYTHON
:
1767 struct ltt_ust_session
*usess
= session
->ust_session
;
1771 switch (event
->type
) {
1772 case LTTNG_EVENT_ALL
:
1775 ret
= LTTNG_ERR_UNK
;
1779 agt
= trace_ust_find_agent(usess
, domain
);
1781 ret
= -LTTNG_ERR_UST_EVENT_NOT_FOUND
;
1785 * An empty event name means that everything
1786 * should be disabled.
1788 if (event
->name
[0] == '\0') {
1789 ret
= event_agent_disable_all(usess
, agt
);
1791 ret
= event_agent_disable(usess
, agt
, event_name
);
1793 if (ret
!= LTTNG_OK
) {
1800 ret
= LTTNG_ERR_UND
;
1813 * Command LTTNG_ADD_CONTEXT processed by the client thread.
1815 int cmd_add_context(struct ltt_session
*session
, enum lttng_domain_type domain
,
1816 char *channel_name
, struct lttng_event_context
*ctx
, int kwpipe
)
1818 int ret
, chan_kern_created
= 0, chan_ust_created
= 0;
1819 char *app_ctx_provider_name
= NULL
, *app_ctx_name
= NULL
;
1822 * Don't try to add a context if the session has been started at
1823 * some point in time before. The tracer does not allow it and would
1824 * result in a corrupted trace.
1826 if (session
->has_been_started
) {
1827 ret
= LTTNG_ERR_TRACE_ALREADY_STARTED
;
1831 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
1832 app_ctx_provider_name
= ctx
->u
.app_ctx
.provider_name
;
1833 app_ctx_name
= ctx
->u
.app_ctx
.ctx_name
;
1837 case LTTNG_DOMAIN_KERNEL
:
1838 assert(session
->kernel_session
);
1840 if (session
->kernel_session
->channel_count
== 0) {
1841 /* Create default channel */
1842 ret
= channel_kernel_create(session
->kernel_session
, NULL
, kwpipe
);
1843 if (ret
!= LTTNG_OK
) {
1846 chan_kern_created
= 1;
1848 /* Add kernel context to kernel tracer */
1849 ret
= context_kernel_add(session
->kernel_session
, ctx
, channel_name
);
1850 if (ret
!= LTTNG_OK
) {
1854 case LTTNG_DOMAIN_JUL
:
1855 case LTTNG_DOMAIN_LOG4J
:
1858 * Validate channel name.
1859 * If no channel name is given and the domain is JUL or LOG4J,
1860 * set it to the appropriate domain-specific channel name. If
1861 * a name is provided but does not match the expexted channel
1862 * name, return an error.
1864 if (domain
== LTTNG_DOMAIN_JUL
&& *channel_name
&&
1865 strcmp(channel_name
,
1866 DEFAULT_JUL_CHANNEL_NAME
)) {
1867 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1869 } else if (domain
== LTTNG_DOMAIN_LOG4J
&& *channel_name
&&
1870 strcmp(channel_name
,
1871 DEFAULT_LOG4J_CHANNEL_NAME
)) {
1872 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1875 /* break is _not_ missing here. */
1877 case LTTNG_DOMAIN_UST
:
1879 struct ltt_ust_session
*usess
= session
->ust_session
;
1880 unsigned int chan_count
;
1884 chan_count
= lttng_ht_get_count(usess
->domain_global
.channels
);
1885 if (chan_count
== 0) {
1886 struct lttng_channel
*attr
;
1887 /* Create default channel */
1888 attr
= channel_new_default_attr(domain
, usess
->buffer_type
);
1890 ret
= LTTNG_ERR_FATAL
;
1894 ret
= channel_ust_create(usess
, attr
, usess
->buffer_type
);
1895 if (ret
!= LTTNG_OK
) {
1899 channel_attr_destroy(attr
);
1900 chan_ust_created
= 1;
1903 ret
= context_ust_add(usess
, domain
, ctx
, channel_name
);
1904 free(app_ctx_provider_name
);
1906 app_ctx_name
= NULL
;
1907 app_ctx_provider_name
= NULL
;
1908 if (ret
!= LTTNG_OK
) {
1914 ret
= LTTNG_ERR_UND
;
1922 if (chan_kern_created
) {
1923 struct ltt_kernel_channel
*kchan
=
1924 trace_kernel_get_channel_by_name(DEFAULT_CHANNEL_NAME
,
1925 session
->kernel_session
);
1926 /* Created previously, this should NOT fail. */
1928 kernel_destroy_channel(kchan
);
1931 if (chan_ust_created
) {
1932 struct ltt_ust_channel
*uchan
=
1933 trace_ust_find_channel_by_name(
1934 session
->ust_session
->domain_global
.channels
,
1935 DEFAULT_CHANNEL_NAME
);
1936 /* Created previously, this should NOT fail. */
1938 /* Remove from the channel list of the session. */
1939 trace_ust_delete_channel(session
->ust_session
->domain_global
.channels
,
1941 trace_ust_destroy_channel(uchan
);
1944 free(app_ctx_provider_name
);
1949 static inline bool name_starts_with(const char *name
, const char *prefix
)
1951 const size_t max_cmp_len
= min(strlen(prefix
), LTTNG_SYMBOL_NAME_LEN
);
1953 return !strncmp(name
, prefix
, max_cmp_len
);
1956 /* Perform userspace-specific event name validation */
1957 static int validate_ust_event_name(const char *name
)
1967 * Check name against all internal UST event component namespaces used
1970 if (name_starts_with(name
, DEFAULT_JUL_EVENT_COMPONENT
) ||
1971 name_starts_with(name
, DEFAULT_LOG4J_EVENT_COMPONENT
) ||
1972 name_starts_with(name
, DEFAULT_PYTHON_EVENT_COMPONENT
)) {
1981 * Internal version of cmd_enable_event() with a supplemental
1982 * "internal_event" flag which is used to enable internal events which should
1983 * be hidden from clients. Such events are used in the agent implementation to
1984 * enable the events through which all "agent" events are funeled.
1986 static int _cmd_enable_event(struct ltt_session
*session
,
1987 struct lttng_domain
*domain
,
1988 char *channel_name
, struct lttng_event
*event
,
1989 char *filter_expression
,
1990 struct lttng_filter_bytecode
*filter
,
1991 struct lttng_event_exclusion
*exclusion
,
1992 int wpipe
, bool internal_event
)
1994 int ret
= 0, channel_created
= 0;
1995 struct lttng_channel
*attr
= NULL
;
1999 assert(channel_name
);
2001 /* If we have a filter, we must have its filter expression */
2002 assert(!(!!filter_expression
^ !!filter
));
2004 /* Normalize event name as a globbing pattern */
2005 strutils_normalize_star_glob_pattern(event
->name
);
2007 /* Normalize exclusion names as globbing patterns */
2011 for (i
= 0; i
< exclusion
->count
; i
++) {
2012 char *name
= LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, i
);
2014 strutils_normalize_star_glob_pattern(name
);
2018 DBG("Enable event command for event \'%s\'", event
->name
);
2022 switch (domain
->type
) {
2023 case LTTNG_DOMAIN_KERNEL
:
2025 struct ltt_kernel_channel
*kchan
;
2028 * If a non-default channel has been created in the
2029 * session, explicitely require that -c chan_name needs
2032 if (session
->kernel_session
->has_non_default_channel
2033 && channel_name
[0] == '\0') {
2034 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
2038 kchan
= trace_kernel_get_channel_by_name(channel_name
,
2039 session
->kernel_session
);
2040 if (kchan
== NULL
) {
2041 attr
= channel_new_default_attr(LTTNG_DOMAIN_KERNEL
,
2042 LTTNG_BUFFER_GLOBAL
);
2044 ret
= LTTNG_ERR_FATAL
;
2047 if (lttng_strncpy(attr
->name
, channel_name
,
2048 sizeof(attr
->name
))) {
2049 ret
= LTTNG_ERR_INVALID
;
2053 ret
= cmd_enable_channel(session
, domain
, attr
, wpipe
);
2054 if (ret
!= LTTNG_OK
) {
2057 channel_created
= 1;
2060 /* Get the newly created kernel channel pointer */
2061 kchan
= trace_kernel_get_channel_by_name(channel_name
,
2062 session
->kernel_session
);
2063 if (kchan
== NULL
) {
2064 /* This sould not happen... */
2065 ret
= LTTNG_ERR_FATAL
;
2069 switch (event
->type
) {
2070 case LTTNG_EVENT_ALL
:
2072 char *filter_expression_a
= NULL
;
2073 struct lttng_filter_bytecode
*filter_a
= NULL
;
2076 * We need to duplicate filter_expression and filter,
2077 * because ownership is passed to first enable
2080 if (filter_expression
) {
2081 filter_expression_a
= strdup(filter_expression
);
2082 if (!filter_expression_a
) {
2083 ret
= LTTNG_ERR_FATAL
;
2088 filter_a
= zmalloc(sizeof(*filter_a
) + filter
->len
);
2090 free(filter_expression_a
);
2091 ret
= LTTNG_ERR_FATAL
;
2094 memcpy(filter_a
, filter
, sizeof(*filter_a
) + filter
->len
);
2096 event
->type
= LTTNG_EVENT_TRACEPOINT
; /* Hack */
2097 ret
= event_kernel_enable_event(kchan
, event
,
2098 filter_expression
, filter
);
2099 /* We have passed ownership */
2100 filter_expression
= NULL
;
2102 if (ret
!= LTTNG_OK
) {
2103 if (channel_created
) {
2104 /* Let's not leak a useless channel. */
2105 kernel_destroy_channel(kchan
);
2107 free(filter_expression_a
);
2111 event
->type
= LTTNG_EVENT_SYSCALL
; /* Hack */
2112 ret
= event_kernel_enable_event(kchan
, event
,
2113 filter_expression_a
, filter_a
);
2114 /* We have passed ownership */
2115 filter_expression_a
= NULL
;
2117 if (ret
!= LTTNG_OK
) {
2122 case LTTNG_EVENT_PROBE
:
2123 case LTTNG_EVENT_USERSPACE_PROBE
:
2124 case LTTNG_EVENT_FUNCTION
:
2125 case LTTNG_EVENT_FUNCTION_ENTRY
:
2126 case LTTNG_EVENT_TRACEPOINT
:
2127 ret
= event_kernel_enable_event(kchan
, event
,
2128 filter_expression
, filter
);
2129 /* We have passed ownership */
2130 filter_expression
= NULL
;
2132 if (ret
!= LTTNG_OK
) {
2133 if (channel_created
) {
2134 /* Let's not leak a useless channel. */
2135 kernel_destroy_channel(kchan
);
2140 case LTTNG_EVENT_SYSCALL
:
2141 ret
= event_kernel_enable_event(kchan
, event
,
2142 filter_expression
, filter
);
2143 /* We have passed ownership */
2144 filter_expression
= NULL
;
2146 if (ret
!= LTTNG_OK
) {
2151 ret
= LTTNG_ERR_UNK
;
2155 kernel_wait_quiescent(kernel_tracer_fd
);
2158 case LTTNG_DOMAIN_UST
:
2160 struct ltt_ust_channel
*uchan
;
2161 struct ltt_ust_session
*usess
= session
->ust_session
;
2166 * If a non-default channel has been created in the
2167 * session, explicitely require that -c chan_name needs
2170 if (usess
->has_non_default_channel
&& channel_name
[0] == '\0') {
2171 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
2175 /* Get channel from global UST domain */
2176 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
2178 if (uchan
== NULL
) {
2179 /* Create default channel */
2180 attr
= channel_new_default_attr(LTTNG_DOMAIN_UST
,
2181 usess
->buffer_type
);
2183 ret
= LTTNG_ERR_FATAL
;
2186 if (lttng_strncpy(attr
->name
, channel_name
,
2187 sizeof(attr
->name
))) {
2188 ret
= LTTNG_ERR_INVALID
;
2192 ret
= cmd_enable_channel(session
, domain
, attr
, wpipe
);
2193 if (ret
!= LTTNG_OK
) {
2197 /* Get the newly created channel reference back */
2198 uchan
= trace_ust_find_channel_by_name(
2199 usess
->domain_global
.channels
, channel_name
);
2203 if (uchan
->domain
!= LTTNG_DOMAIN_UST
&& !internal_event
) {
2205 * Don't allow users to add UST events to channels which
2206 * are assigned to a userspace subdomain (JUL, Log4J,
2209 ret
= LTTNG_ERR_INVALID_CHANNEL_DOMAIN
;
2213 if (!internal_event
) {
2215 * Ensure the event name is not reserved for internal
2218 ret
= validate_ust_event_name(event
->name
);
2220 WARN("Userspace event name %s failed validation.",
2222 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
2227 /* At this point, the session and channel exist on the tracer */
2228 ret
= event_ust_enable_tracepoint(usess
, uchan
, event
,
2229 filter_expression
, filter
, exclusion
,
2231 /* We have passed ownership */
2232 filter_expression
= NULL
;
2235 if (ret
== LTTNG_ERR_UST_EVENT_ENABLED
) {
2236 goto already_enabled
;
2237 } else if (ret
!= LTTNG_OK
) {
2242 case LTTNG_DOMAIN_LOG4J
:
2243 case LTTNG_DOMAIN_JUL
:
2244 case LTTNG_DOMAIN_PYTHON
:
2246 const char *default_event_name
, *default_chan_name
;
2248 struct lttng_event uevent
;
2249 struct lttng_domain tmp_dom
;
2250 struct ltt_ust_session
*usess
= session
->ust_session
;
2254 if (!agent_tracing_is_enabled()) {
2255 DBG("Attempted to enable an event in an agent domain but the agent thread is not running");
2256 ret
= LTTNG_ERR_AGENT_TRACING_DISABLED
;
2260 agt
= trace_ust_find_agent(usess
, domain
->type
);
2262 agt
= agent_create(domain
->type
);
2264 ret
= LTTNG_ERR_NOMEM
;
2267 agent_add(agt
, usess
->agents
);
2270 /* Create the default tracepoint. */
2271 memset(&uevent
, 0, sizeof(uevent
));
2272 uevent
.type
= LTTNG_EVENT_TRACEPOINT
;
2273 uevent
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
2274 default_event_name
= event_get_default_agent_ust_name(
2276 if (!default_event_name
) {
2277 ret
= LTTNG_ERR_FATAL
;
2280 strncpy(uevent
.name
, default_event_name
, sizeof(uevent
.name
));
2281 uevent
.name
[sizeof(uevent
.name
) - 1] = '\0';
2284 * The domain type is changed because we are about to enable the
2285 * default channel and event for the JUL domain that are hardcoded.
2286 * This happens in the UST domain.
2288 memcpy(&tmp_dom
, domain
, sizeof(tmp_dom
));
2289 tmp_dom
.type
= LTTNG_DOMAIN_UST
;
2291 switch (domain
->type
) {
2292 case LTTNG_DOMAIN_LOG4J
:
2293 default_chan_name
= DEFAULT_LOG4J_CHANNEL_NAME
;
2295 case LTTNG_DOMAIN_JUL
:
2296 default_chan_name
= DEFAULT_JUL_CHANNEL_NAME
;
2298 case LTTNG_DOMAIN_PYTHON
:
2299 default_chan_name
= DEFAULT_PYTHON_CHANNEL_NAME
;
2302 /* The switch/case we are in makes this impossible */
2307 char *filter_expression_copy
= NULL
;
2308 struct lttng_filter_bytecode
*filter_copy
= NULL
;
2311 const size_t filter_size
= sizeof(
2312 struct lttng_filter_bytecode
)
2315 filter_copy
= zmalloc(filter_size
);
2317 ret
= LTTNG_ERR_NOMEM
;
2320 memcpy(filter_copy
, filter
, filter_size
);
2322 filter_expression_copy
=
2323 strdup(filter_expression
);
2324 if (!filter_expression
) {
2325 ret
= LTTNG_ERR_NOMEM
;
2328 if (!filter_expression_copy
|| !filter_copy
) {
2329 free(filter_expression_copy
);
2335 ret
= cmd_enable_event_internal(session
, &tmp_dom
,
2336 (char *) default_chan_name
,
2337 &uevent
, filter_expression_copy
,
2338 filter_copy
, NULL
, wpipe
);
2341 if (ret
== LTTNG_ERR_UST_EVENT_ENABLED
) {
2342 goto already_enabled
;
2343 } else if (ret
!= LTTNG_OK
) {
2347 /* The wild card * means that everything should be enabled. */
2348 if (strncmp(event
->name
, "*", 1) == 0 && strlen(event
->name
) == 1) {
2349 ret
= event_agent_enable_all(usess
, agt
, event
, filter
,
2352 ret
= event_agent_enable(usess
, agt
, event
, filter
,
2356 filter_expression
= NULL
;
2357 if (ret
!= LTTNG_OK
) {
2364 ret
= LTTNG_ERR_UND
;
2372 free(filter_expression
);
2375 channel_attr_destroy(attr
);
2381 * Command LTTNG_ENABLE_EVENT processed by the client thread.
2382 * We own filter, exclusion, and filter_expression.
2384 int cmd_enable_event(struct ltt_session
*session
, struct lttng_domain
*domain
,
2385 char *channel_name
, struct lttng_event
*event
,
2386 char *filter_expression
,
2387 struct lttng_filter_bytecode
*filter
,
2388 struct lttng_event_exclusion
*exclusion
,
2391 return _cmd_enable_event(session
, domain
, channel_name
, event
,
2392 filter_expression
, filter
, exclusion
, wpipe
, false);
2396 * Enable an event which is internal to LTTng. An internal should
2397 * never be made visible to clients and are immune to checks such as
2400 static int cmd_enable_event_internal(struct ltt_session
*session
,
2401 struct lttng_domain
*domain
,
2402 char *channel_name
, struct lttng_event
*event
,
2403 char *filter_expression
,
2404 struct lttng_filter_bytecode
*filter
,
2405 struct lttng_event_exclusion
*exclusion
,
2408 return _cmd_enable_event(session
, domain
, channel_name
, event
,
2409 filter_expression
, filter
, exclusion
, wpipe
, true);
2413 * Command LTTNG_LIST_TRACEPOINTS processed by the client thread.
2415 ssize_t
cmd_list_tracepoints(enum lttng_domain_type domain
,
2416 struct lttng_event
**events
)
2419 ssize_t nb_events
= 0;
2422 case LTTNG_DOMAIN_KERNEL
:
2423 nb_events
= kernel_list_events(kernel_tracer_fd
, events
);
2424 if (nb_events
< 0) {
2425 ret
= LTTNG_ERR_KERN_LIST_FAIL
;
2429 case LTTNG_DOMAIN_UST
:
2430 nb_events
= ust_app_list_events(events
);
2431 if (nb_events
< 0) {
2432 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2436 case LTTNG_DOMAIN_LOG4J
:
2437 case LTTNG_DOMAIN_JUL
:
2438 case LTTNG_DOMAIN_PYTHON
:
2439 nb_events
= agent_list_events(events
, domain
);
2440 if (nb_events
< 0) {
2441 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2446 ret
= LTTNG_ERR_UND
;
2453 /* Return negative value to differentiate return code */
2458 * Command LTTNG_LIST_TRACEPOINT_FIELDS processed by the client thread.
2460 ssize_t
cmd_list_tracepoint_fields(enum lttng_domain_type domain
,
2461 struct lttng_event_field
**fields
)
2464 ssize_t nb_fields
= 0;
2467 case LTTNG_DOMAIN_UST
:
2468 nb_fields
= ust_app_list_event_fields(fields
);
2469 if (nb_fields
< 0) {
2470 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2474 case LTTNG_DOMAIN_KERNEL
:
2475 default: /* fall-through */
2476 ret
= LTTNG_ERR_UND
;
2483 /* Return negative value to differentiate return code */
2487 ssize_t
cmd_list_syscalls(struct lttng_event
**events
)
2489 return syscall_table_list(events
);
2493 * Command LTTNG_LIST_TRACKER_PIDS processed by the client thread.
2495 * Called with session lock held.
2497 ssize_t
cmd_list_tracker_pids(struct ltt_session
*session
,
2498 enum lttng_domain_type domain
, int32_t **pids
)
2501 ssize_t nr_pids
= 0;
2504 case LTTNG_DOMAIN_KERNEL
:
2506 struct ltt_kernel_session
*ksess
;
2508 ksess
= session
->kernel_session
;
2509 nr_pids
= kernel_list_tracker_pids(ksess
, pids
);
2511 ret
= LTTNG_ERR_KERN_LIST_FAIL
;
2516 case LTTNG_DOMAIN_UST
:
2518 struct ltt_ust_session
*usess
;
2520 usess
= session
->ust_session
;
2521 nr_pids
= trace_ust_list_tracker_pids(usess
, pids
);
2523 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2528 case LTTNG_DOMAIN_LOG4J
:
2529 case LTTNG_DOMAIN_JUL
:
2530 case LTTNG_DOMAIN_PYTHON
:
2532 ret
= LTTNG_ERR_UND
;
2539 /* Return negative value to differentiate return code */
2544 * Command LTTNG_START_TRACE processed by the client thread.
2546 * Called with session mutex held.
2548 int cmd_start_trace(struct ltt_session
*session
)
2550 enum lttng_error_code ret
;
2551 unsigned long nb_chan
= 0;
2552 struct ltt_kernel_session
*ksession
;
2553 struct ltt_ust_session
*usess
;
2557 /* Ease our life a bit ;) */
2558 ksession
= session
->kernel_session
;
2559 usess
= session
->ust_session
;
2561 /* Is the session already started? */
2562 if (session
->active
) {
2563 ret
= LTTNG_ERR_TRACE_ALREADY_STARTED
;
2568 * Starting a session without channel is useless since after that it's not
2569 * possible to enable channel thus inform the client.
2571 if (usess
&& usess
->domain_global
.channels
) {
2572 nb_chan
+= lttng_ht_get_count(usess
->domain_global
.channels
);
2575 nb_chan
+= ksession
->channel_count
;
2578 ret
= LTTNG_ERR_NO_CHANNEL
;
2582 if (session
->output_traces
&& !session
->current_trace_chunk
&&
2583 session_output_supports_trace_chunks(session
)) {
2584 struct lttng_trace_chunk
*trace_chunk
;
2586 trace_chunk
= session_create_new_trace_chunk(
2587 session
, NULL
, NULL
, NULL
);
2589 ret
= LTTNG_ERR_CREATE_DIR_FAIL
;
2592 assert(!session
->current_trace_chunk
);
2593 ret
= session_set_trace_chunk(session
, trace_chunk
, NULL
);
2594 lttng_trace_chunk_put(trace_chunk
);
2596 ret
= LTTNG_ERR_CREATE_TRACE_CHUNK_FAIL_CONSUMER
;
2601 /* Kernel tracing */
2602 if (ksession
!= NULL
) {
2603 DBG("Start kernel tracing session %s", session
->name
);
2604 ret
= start_kernel_session(ksession
, kernel_tracer_fd
);
2605 if (ret
!= LTTNG_OK
) {
2610 /* Flag session that trace should start automatically */
2612 int int_ret
= ust_app_start_trace_all(usess
);
2615 ret
= LTTNG_ERR_UST_START_FAIL
;
2620 /* Flag this after a successful start. */
2621 session
->has_been_started
= 1;
2622 session
->active
= 1;
2625 * Clear the flag that indicates that a rotation was done while the
2626 * session was stopped.
2628 session
->rotated_after_last_stop
= false;
2630 if (session
->rotate_timer_period
) {
2631 int int_ret
= timer_session_rotation_schedule_timer_start(
2632 session
, session
->rotate_timer_period
);
2635 ERR("Failed to enable rotate timer");
2636 ret
= LTTNG_ERR_UNK
;
2648 * Command LTTNG_STOP_TRACE processed by the client thread.
2650 int cmd_stop_trace(struct ltt_session
*session
)
2653 struct ltt_kernel_channel
*kchan
;
2654 struct ltt_kernel_session
*ksession
;
2655 struct ltt_ust_session
*usess
;
2656 bool error_occurred
= false;
2660 DBG("Begin stop session %s (id %" PRIu64
")", session
->name
, session
->id
);
2662 ksession
= session
->kernel_session
;
2663 usess
= session
->ust_session
;
2665 /* Session is not active. Skip everythong and inform the client. */
2666 if (!session
->active
) {
2667 ret
= LTTNG_ERR_TRACE_ALREADY_STOPPED
;
2672 if (ksession
&& ksession
->active
) {
2673 DBG("Stop kernel tracing");
2675 ret
= kernel_stop_session(ksession
);
2677 ret
= LTTNG_ERR_KERN_STOP_FAIL
;
2681 kernel_wait_quiescent(kernel_tracer_fd
);
2683 /* Flush metadata after stopping (if exists) */
2684 if (ksession
->metadata_stream_fd
>= 0) {
2685 ret
= kernel_metadata_flush_buffer(ksession
->metadata_stream_fd
);
2687 ERR("Kernel metadata flush failed");
2691 /* Flush all buffers after stopping */
2692 cds_list_for_each_entry(kchan
, &ksession
->channel_list
.head
, list
) {
2693 ret
= kernel_flush_buffer(kchan
);
2695 ERR("Kernel flush buffer error");
2699 ksession
->active
= 0;
2700 DBG("Kernel session stopped %s (id %" PRIu64
")", session
->name
,
2704 if (usess
&& usess
->active
) {
2705 ret
= ust_app_stop_trace_all(usess
);
2707 ret
= LTTNG_ERR_UST_STOP_FAIL
;
2712 /* Flag inactive after a successful stop. */
2713 session
->active
= 0;
2714 ret
= !error_occurred
? LTTNG_OK
: LTTNG_ERR_UNK
;
2721 * Command LTTNG_SET_CONSUMER_URI processed by the client thread.
2723 int cmd_set_consumer_uri(struct ltt_session
*session
, size_t nb_uri
,
2724 struct lttng_uri
*uris
)
2727 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
2728 struct ltt_ust_session
*usess
= session
->ust_session
;
2734 /* Can't set consumer URI if the session is active. */
2735 if (session
->active
) {
2736 ret
= LTTNG_ERR_TRACE_ALREADY_STARTED
;
2740 /* Set the "global" consumer URIs */
2741 for (i
= 0; i
< nb_uri
; i
++) {
2742 ret
= add_uri_to_consumer(session
,
2744 &uris
[i
], LTTNG_DOMAIN_NONE
);
2745 if (ret
!= LTTNG_OK
) {
2750 /* Set UST session URIs */
2751 if (session
->ust_session
) {
2752 for (i
= 0; i
< nb_uri
; i
++) {
2753 ret
= add_uri_to_consumer(session
,
2754 session
->ust_session
->consumer
,
2755 &uris
[i
], LTTNG_DOMAIN_UST
);
2756 if (ret
!= LTTNG_OK
) {
2762 /* Set kernel session URIs */
2763 if (session
->kernel_session
) {
2764 for (i
= 0; i
< nb_uri
; i
++) {
2765 ret
= add_uri_to_consumer(session
,
2766 session
->kernel_session
->consumer
,
2767 &uris
[i
], LTTNG_DOMAIN_KERNEL
);
2768 if (ret
!= LTTNG_OK
) {
2775 * Make sure to set the session in output mode after we set URI since a
2776 * session can be created without URL (thus flagged in no output mode).
2778 session
->output_traces
= 1;
2780 ksess
->output_traces
= 1;
2784 usess
->output_traces
= 1;
2795 enum lttng_error_code
set_session_output_from_descriptor(
2796 struct ltt_session
*session
,
2797 const struct lttng_session_descriptor
*descriptor
)
2800 enum lttng_error_code ret_code
= LTTNG_OK
;
2801 enum lttng_session_descriptor_type session_type
=
2802 lttng_session_descriptor_get_type(descriptor
);
2803 enum lttng_session_descriptor_output_type output_type
=
2804 lttng_session_descriptor_get_output_type(descriptor
);
2805 struct lttng_uri uris
[2] = {};
2806 size_t uri_count
= 0;
2808 switch (output_type
) {
2809 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE
:
2811 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL
:
2812 lttng_session_descriptor_get_local_output_uri(descriptor
,
2816 case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK
:
2817 lttng_session_descriptor_get_network_output_uris(descriptor
,
2818 &uris
[0], &uris
[1]);
2822 ret_code
= LTTNG_ERR_INVALID
;
2826 switch (session_type
) {
2827 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
2829 struct snapshot_output
*new_output
= NULL
;
2831 new_output
= snapshot_output_alloc();
2833 ret_code
= LTTNG_ERR_NOMEM
;
2837 ret
= snapshot_output_init_with_uri(session
,
2838 DEFAULT_SNAPSHOT_MAX_SIZE
,
2839 NULL
, uris
, uri_count
, session
->consumer
,
2840 new_output
, &session
->snapshot
);
2842 ret_code
= (ret
== -ENOMEM
) ?
2843 LTTNG_ERR_NOMEM
: LTTNG_ERR_INVALID
;
2844 snapshot_output_destroy(new_output
);
2847 snapshot_add_output(&session
->snapshot
, new_output
);
2850 case LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR
:
2851 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
2853 ret_code
= cmd_set_consumer_uri(session
, uri_count
, uris
);
2857 ret_code
= LTTNG_ERR_INVALID
;
2865 enum lttng_error_code
cmd_create_session_from_descriptor(
2866 struct lttng_session_descriptor
*descriptor
,
2867 const lttng_sock_cred
*creds
,
2868 const char *home_path
)
2871 enum lttng_error_code ret_code
;
2872 const char *session_name
;
2873 struct ltt_session
*new_session
= NULL
;
2874 enum lttng_session_descriptor_status descriptor_status
;
2876 session_lock_list();
2878 if (*home_path
!= '/') {
2879 ERR("Home path provided by client is not absolute");
2880 ret_code
= LTTNG_ERR_INVALID
;
2885 descriptor_status
= lttng_session_descriptor_get_session_name(
2886 descriptor
, &session_name
);
2887 switch (descriptor_status
) {
2888 case LTTNG_SESSION_DESCRIPTOR_STATUS_OK
:
2890 case LTTNG_SESSION_DESCRIPTOR_STATUS_UNSET
:
2891 session_name
= NULL
;
2894 ret_code
= LTTNG_ERR_INVALID
;
2897 ret_code
= session_create(session_name
, creds
->uid
, creds
->gid
,
2899 if (ret_code
!= LTTNG_OK
) {
2903 if (!session_name
) {
2904 ret
= lttng_session_descriptor_set_session_name(descriptor
,
2907 ret_code
= LTTNG_ERR_SESSION_FAIL
;
2912 if (!lttng_session_descriptor_is_output_destination_initialized(
2915 * Only include the session's creation time in the output
2916 * destination if the name of the session itself was
2917 * not auto-generated.
2919 ret_code
= lttng_session_descriptor_set_default_output(
2921 session_name
? &new_session
->creation_time
: NULL
,
2923 if (ret_code
!= LTTNG_OK
) {
2927 new_session
->has_user_specified_directory
=
2928 lttng_session_descriptor_has_output_directory(
2932 switch (lttng_session_descriptor_get_type(descriptor
)) {
2933 case LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT
:
2934 new_session
->snapshot_mode
= 1;
2936 case LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE
:
2937 new_session
->live_timer
=
2938 lttng_session_descriptor_live_get_timer_interval(
2945 ret_code
= set_session_output_from_descriptor(new_session
, descriptor
);
2946 if (ret_code
!= LTTNG_OK
) {
2949 new_session
->consumer
->enabled
= 1;
2950 ret_code
= LTTNG_OK
;
2952 /* Release reference provided by the session_create function. */
2953 session_put(new_session
);
2954 if (ret_code
!= LTTNG_OK
&& new_session
) {
2955 /* Release the global reference on error. */
2956 session_destroy(new_session
);
2958 session_unlock_list();
2962 enum lttng_error_code
cmd_create_session(struct command_ctx
*cmd_ctx
, int sock
,
2963 struct lttng_session_descriptor
**return_descriptor
)
2966 size_t payload_size
;
2967 struct lttng_dynamic_buffer payload
;
2968 struct lttng_buffer_view home_dir_view
;
2969 struct lttng_buffer_view session_descriptor_view
;
2970 struct lttng_session_descriptor
*session_descriptor
= NULL
;
2971 enum lttng_error_code ret_code
;
2973 lttng_dynamic_buffer_init(&payload
);
2974 if (cmd_ctx
->lsm
->u
.create_session
.home_dir_size
>=
2976 ret_code
= LTTNG_ERR_INVALID
;
2979 if (cmd_ctx
->lsm
->u
.create_session
.session_descriptor_size
>
2980 LTTNG_SESSION_DESCRIPTOR_MAX_LEN
) {
2981 ret_code
= LTTNG_ERR_INVALID
;
2985 payload_size
= cmd_ctx
->lsm
->u
.create_session
.home_dir_size
+
2986 cmd_ctx
->lsm
->u
.create_session
.session_descriptor_size
;
2987 ret
= lttng_dynamic_buffer_set_size(&payload
, payload_size
);
2989 ret_code
= LTTNG_ERR_NOMEM
;
2993 ret
= lttcomm_recv_unix_sock(sock
, payload
.data
, payload
.size
);
2995 ERR("Reception of session descriptor failed, aborting.");
2996 ret_code
= LTTNG_ERR_SESSION_FAIL
;
3000 home_dir_view
= lttng_buffer_view_from_dynamic_buffer(
3003 cmd_ctx
->lsm
->u
.create_session
.home_dir_size
);
3004 session_descriptor_view
= lttng_buffer_view_from_dynamic_buffer(
3006 cmd_ctx
->lsm
->u
.create_session
.home_dir_size
,
3007 cmd_ctx
->lsm
->u
.create_session
.session_descriptor_size
);
3009 ret
= lttng_session_descriptor_create_from_buffer(
3010 &session_descriptor_view
, &session_descriptor
);
3012 ERR("Failed to create session descriptor from payload of \"create session\" command");
3013 ret_code
= LTTNG_ERR_INVALID
;
3018 * Sets the descriptor's auto-generated properties (name, output) if
3021 ret_code
= cmd_create_session_from_descriptor(session_descriptor
,
3023 home_dir_view
.size
? home_dir_view
.data
: NULL
);
3024 if (ret_code
!= LTTNG_OK
) {
3028 ret_code
= LTTNG_OK
;
3029 *return_descriptor
= session_descriptor
;
3030 session_descriptor
= NULL
;
3032 lttng_dynamic_buffer_reset(&payload
);
3033 lttng_session_descriptor_destroy(session_descriptor
);
3038 void cmd_destroy_session_reply(const struct ltt_session
*session
,
3039 void *_reply_context
)
3043 const struct cmd_destroy_session_reply_context
*reply_context
=
3045 struct lttng_dynamic_buffer payload
;
3046 struct lttcomm_session_destroy_command_header cmd_header
;
3047 struct lttng_trace_archive_location
*location
= NULL
;
3048 struct lttcomm_lttng_msg llm
= {
3049 .cmd_type
= LTTNG_DESTROY_SESSION
,
3050 .ret_code
= LTTNG_OK
,
3053 sizeof(struct lttcomm_session_destroy_command_header
),
3056 size_t payload_size_before_location
;
3058 lttng_dynamic_buffer_init(&payload
);
3060 ret
= lttng_dynamic_buffer_append(&payload
, &llm
, sizeof(llm
));
3062 ERR("Failed to append session destruction message");
3066 cmd_header
.rotation_state
=
3067 (int32_t) (reply_context
->implicit_rotation_on_destroy
?
3068 session
->rotation_state
:
3069 LTTNG_ROTATION_STATE_NO_ROTATION
);
3070 ret
= lttng_dynamic_buffer_append(&payload
, &cmd_header
,
3071 sizeof(cmd_header
));
3073 ERR("Failed to append session destruction command header");
3077 if (!reply_context
->implicit_rotation_on_destroy
) {
3078 DBG("No implicit rotation performed during the destruction of session \"%s\", sending reply",
3082 if (session
->rotation_state
!= LTTNG_ROTATION_STATE_COMPLETED
) {
3083 DBG("Rotation state of session \"%s\" is not \"completed\", sending session destruction reply",
3088 location
= session_get_trace_archive_location(session
);
3090 ERR("Failed to get the location of the trace archive produced during the destruction of session \"%s\"",
3095 payload_size_before_location
= payload
.size
;
3096 comm_ret
= lttng_trace_archive_location_serialize(location
,
3099 ERR("Failed to serialize the location of the trace archive produced during the destruction of session \"%s\"",
3103 /* Update the message to indicate the location's length. */
3104 ((struct lttcomm_lttng_msg
*) payload
.data
)->data_size
=
3105 payload
.size
- payload_size_before_location
;
3107 comm_ret
= lttcomm_send_unix_sock(reply_context
->reply_sock_fd
,
3108 payload
.data
, payload
.size
);
3109 if (comm_ret
!= (ssize_t
) payload
.size
) {
3110 ERR("Failed to send result of the destruction of session \"%s\" to client",
3114 ret
= close(reply_context
->reply_sock_fd
);
3116 PERROR("Failed to close client socket in deferred session destroy reply");
3118 lttng_dynamic_buffer_reset(&payload
);
3119 free(_reply_context
);
3123 * Command LTTNG_DESTROY_SESSION processed by the client thread.
3125 * Called with session lock held.
3127 int cmd_destroy_session(struct ltt_session
*session
,
3128 struct notification_thread_handle
*notification_thread_handle
,
3132 struct cmd_destroy_session_reply_context
*reply_context
= NULL
;
3135 reply_context
= zmalloc(sizeof(*reply_context
));
3136 if (!reply_context
) {
3137 ret
= LTTNG_ERR_NOMEM
;
3140 reply_context
->reply_sock_fd
= *sock_fd
;
3146 DBG("Begin destroy session %s (id %" PRIu64
")", session
->name
,
3148 if (session
->active
) {
3149 DBG("Session \"%s\" is active, attempting to stop it before destroying it",
3151 ret
= cmd_stop_trace(session
);
3152 if (ret
!= LTTNG_OK
&& ret
!= LTTNG_ERR_TRACE_ALREADY_STOPPED
) {
3153 /* Carry on with the destruction of the session. */
3154 ERR("Failed to stop session \"%s\" as part of its destruction: %s",
3155 session
->name
, lttng_strerror(-ret
));
3159 if (session
->rotation_schedule_timer_enabled
) {
3160 if (timer_session_rotation_schedule_timer_stop(
3162 ERR("Failed to stop the \"rotation schedule\" timer of session %s",
3167 if (session
->rotate_size
) {
3168 unsubscribe_session_consumed_size_rotation(session
, notification_thread_handle
);
3169 session
->rotate_size
= 0;
3172 if (session
->most_recent_chunk_id
.is_set
&&
3173 session
->most_recent_chunk_id
.value
!= 0 &&
3174 session
->current_trace_chunk
&& session
->output_traces
) {
3176 * Perform a last rotation on destruction if rotations have
3177 * occurred during the session's lifetime.
3179 ret
= cmd_rotate_session(session
, NULL
);
3180 if (ret
!= LTTNG_OK
) {
3181 ERR("Failed to perform an implicit rotation as part of the destruction of session \"%s\": %s",
3182 session
->name
, lttng_strerror(-ret
));
3184 if (reply_context
) {
3185 reply_context
->implicit_rotation_on_destroy
= true;
3189 if (session
->shm_path
[0]) {
3191 * When a session is created with an explicit shm_path,
3192 * the consumer daemon will create its shared memory files
3193 * at that location and will *not* unlink them. This is normal
3194 * as the intention of that feature is to make it possible
3195 * to retrieve the content of those files should a crash occur.
3197 * To ensure the content of those files can be used, the
3198 * sessiond daemon will replicate the content of the metadata
3199 * cache in a metadata file.
3201 * On clean-up, it is expected that the consumer daemon will
3202 * unlink the shared memory files and that the session daemon
3203 * will unlink the metadata file. Then, the session's directory
3204 * in the shm path can be removed.
3206 * Unfortunately, a flaw in the design of the sessiond's and
3207 * consumerd's tear down of channels makes it impossible to
3208 * determine when the sessiond _and_ the consumerd have both
3209 * destroyed their representation of a channel. For one, the
3210 * unlinking, close, and rmdir happen in deferred 'call_rcu'
3211 * callbacks in both daemons.
3213 * However, it is also impossible for the sessiond to know when
3214 * the consumer daemon is done destroying its channel(s) since
3215 * it occurs as a reaction to the closing of the channel's file
3216 * descriptor. There is no resulting communication initiated
3217 * from the consumerd to the sessiond to confirm that the
3218 * operation is completed (and was successful).
3220 * Until this is all fixed, the session daemon checks for the
3221 * removal of the session's shm path which makes it possible
3222 * to safely advertise a session as having been destroyed.
3224 * Prior to this fix, it was not possible to reliably save
3225 * a session making use of the --shm-path option, destroy it,
3226 * and load it again. This is because the creation of the
3227 * session would fail upon seeing the session's shm path
3228 * already in existence.
3230 * Note that none of the error paths in the check for the
3231 * directory's existence return an error. This is normal
3232 * as there isn't much that can be done. The session will
3233 * be destroyed properly, except that we can't offer the
3234 * guarantee that the same session can be re-created.
3236 current_completion_handler
= &destroy_completion_handler
.handler
;
3237 ret
= lttng_strncpy(destroy_completion_handler
.shm_path
,
3239 sizeof(destroy_completion_handler
.shm_path
));
3244 * The session is destroyed. However, note that the command context
3245 * still holds a reference to the session, thus delaying its destruction
3246 * _at least_ up to the point when that reference is released.
3248 session_destroy(session
);
3249 if (reply_context
) {
3250 ret
= session_add_destroy_notifier(session
,
3251 cmd_destroy_session_reply
,
3252 (void *) reply_context
);
3254 ret
= LTTNG_ERR_FATAL
;
3266 * Command LTTNG_REGISTER_CONSUMER processed by the client thread.
3268 int cmd_register_consumer(struct ltt_session
*session
,
3269 enum lttng_domain_type domain
, const char *sock_path
,
3270 struct consumer_data
*cdata
)
3273 struct consumer_socket
*socket
= NULL
;
3280 case LTTNG_DOMAIN_KERNEL
:
3282 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3286 /* Can't register a consumer if there is already one */
3287 if (ksess
->consumer_fds_sent
!= 0) {
3288 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
3292 sock
= lttcomm_connect_unix_sock(sock_path
);
3294 ret
= LTTNG_ERR_CONNECT_FAIL
;
3297 cdata
->cmd_sock
= sock
;
3299 socket
= consumer_allocate_socket(&cdata
->cmd_sock
);
3300 if (socket
== NULL
) {
3303 PERROR("close register consumer");
3305 cdata
->cmd_sock
= -1;
3306 ret
= LTTNG_ERR_FATAL
;
3310 socket
->lock
= zmalloc(sizeof(pthread_mutex_t
));
3311 if (socket
->lock
== NULL
) {
3312 PERROR("zmalloc pthread mutex");
3313 ret
= LTTNG_ERR_FATAL
;
3316 pthread_mutex_init(socket
->lock
, NULL
);
3317 socket
->registered
= 1;
3320 consumer_add_socket(socket
, ksess
->consumer
);
3323 pthread_mutex_lock(&cdata
->pid_mutex
);
3325 pthread_mutex_unlock(&cdata
->pid_mutex
);
3330 /* TODO: Userspace tracing */
3331 ret
= LTTNG_ERR_UND
;
3339 consumer_destroy_socket(socket
);
3345 * Command LTTNG_LIST_DOMAINS processed by the client thread.
3347 ssize_t
cmd_list_domains(struct ltt_session
*session
,
3348 struct lttng_domain
**domains
)
3353 struct lttng_ht_iter iter
;
3355 if (session
->kernel_session
!= NULL
) {
3356 DBG3("Listing domains found kernel domain");
3360 if (session
->ust_session
!= NULL
) {
3361 DBG3("Listing domains found UST global domain");
3365 cds_lfht_for_each_entry(session
->ust_session
->agents
->ht
, &iter
.iter
,
3367 if (agt
->being_used
) {
3378 *domains
= zmalloc(nb_dom
* sizeof(struct lttng_domain
));
3379 if (*domains
== NULL
) {
3380 ret
= LTTNG_ERR_FATAL
;
3384 if (session
->kernel_session
!= NULL
) {
3385 (*domains
)[index
].type
= LTTNG_DOMAIN_KERNEL
;
3387 /* Kernel session buffer type is always GLOBAL */
3388 (*domains
)[index
].buf_type
= LTTNG_BUFFER_GLOBAL
;
3393 if (session
->ust_session
!= NULL
) {
3394 (*domains
)[index
].type
= LTTNG_DOMAIN_UST
;
3395 (*domains
)[index
].buf_type
= session
->ust_session
->buffer_type
;
3399 cds_lfht_for_each_entry(session
->ust_session
->agents
->ht
, &iter
.iter
,
3401 if (agt
->being_used
) {
3402 (*domains
)[index
].type
= agt
->domain
;
3403 (*domains
)[index
].buf_type
= session
->ust_session
->buffer_type
;
3413 /* Return negative value to differentiate return code */
3419 * Command LTTNG_LIST_CHANNELS processed by the client thread.
3421 ssize_t
cmd_list_channels(enum lttng_domain_type domain
,
3422 struct ltt_session
*session
, struct lttng_channel
**channels
)
3424 ssize_t nb_chan
= 0, payload_size
= 0, ret
;
3427 case LTTNG_DOMAIN_KERNEL
:
3428 if (session
->kernel_session
!= NULL
) {
3429 nb_chan
= session
->kernel_session
->channel_count
;
3431 DBG3("Number of kernel channels %zd", nb_chan
);
3433 ret
= -LTTNG_ERR_KERN_CHAN_NOT_FOUND
;
3437 case LTTNG_DOMAIN_UST
:
3438 if (session
->ust_session
!= NULL
) {
3440 nb_chan
= lttng_ht_get_count(
3441 session
->ust_session
->domain_global
.channels
);
3444 DBG3("Number of UST global channels %zd", nb_chan
);
3446 ret
= -LTTNG_ERR_UST_CHAN_NOT_FOUND
;
3451 ret
= -LTTNG_ERR_UND
;
3456 const size_t channel_size
= sizeof(struct lttng_channel
) +
3457 sizeof(struct lttng_channel_extended
);
3458 struct lttng_channel_extended
*channel_exts
;
3460 payload_size
= nb_chan
* channel_size
;
3461 *channels
= zmalloc(payload_size
);
3462 if (*channels
== NULL
) {
3463 ret
= -LTTNG_ERR_FATAL
;
3467 channel_exts
= ((void *) *channels
) +
3468 (nb_chan
* sizeof(struct lttng_channel
));
3469 ret
= list_lttng_channels(domain
, session
, *channels
, channel_exts
);
3470 if (ret
!= LTTNG_OK
) {
3485 * Command LTTNG_LIST_EVENTS processed by the client thread.
3487 ssize_t
cmd_list_events(enum lttng_domain_type domain
,
3488 struct ltt_session
*session
, char *channel_name
,
3489 struct lttng_event
**events
, size_t *total_size
)
3492 ssize_t nb_event
= 0;
3495 case LTTNG_DOMAIN_KERNEL
:
3496 if (session
->kernel_session
!= NULL
) {
3497 nb_event
= list_lttng_kernel_events(channel_name
,
3498 session
->kernel_session
, events
,
3502 case LTTNG_DOMAIN_UST
:
3504 if (session
->ust_session
!= NULL
) {
3505 nb_event
= list_lttng_ust_global_events(channel_name
,
3506 &session
->ust_session
->domain_global
, events
,
3511 case LTTNG_DOMAIN_LOG4J
:
3512 case LTTNG_DOMAIN_JUL
:
3513 case LTTNG_DOMAIN_PYTHON
:
3514 if (session
->ust_session
) {
3515 struct lttng_ht_iter iter
;
3519 cds_lfht_for_each_entry(session
->ust_session
->agents
->ht
,
3520 &iter
.iter
, agt
, node
.node
) {
3521 if (agt
->domain
== domain
) {
3522 nb_event
= list_lttng_agent_events(
3532 ret
= LTTNG_ERR_UND
;
3539 /* Return negative value to differentiate return code */
3544 * Using the session list, filled a lttng_session array to send back to the
3545 * client for session listing.
3547 * The session list lock MUST be acquired before calling this function. Use
3548 * session_lock_list() and session_unlock_list().
3550 void cmd_list_lttng_sessions(struct lttng_session
*sessions
,
3551 size_t session_count
, uid_t uid
, gid_t gid
)
3555 struct ltt_session
*session
;
3556 struct ltt_session_list
*list
= session_get_list();
3557 struct lttng_session_extended
*extended
=
3558 (typeof(extended
)) (&sessions
[session_count
]);
3560 DBG("Getting all available session for UID %d GID %d",
3563 * Iterate over session list and append data after the control struct in
3566 cds_list_for_each_entry(session
, &list
->head
, list
) {
3567 if (!session_get(session
)) {
3571 * Only list the sessions the user can control.
3573 if (!session_access_ok(session
, uid
, gid
) ||
3574 session
->destroyed
) {
3575 session_put(session
);
3579 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3580 struct ltt_ust_session
*usess
= session
->ust_session
;
3582 if (session
->consumer
->type
== CONSUMER_DST_NET
||
3583 (ksess
&& ksess
->consumer
->type
== CONSUMER_DST_NET
) ||
3584 (usess
&& usess
->consumer
->type
== CONSUMER_DST_NET
)) {
3585 ret
= build_network_session_path(sessions
[i
].path
,
3586 sizeof(sessions
[i
].path
), session
);
3588 ret
= snprintf(sessions
[i
].path
, sizeof(sessions
[i
].path
), "%s",
3589 session
->consumer
->dst
.session_root_path
);
3592 PERROR("snprintf session path");
3593 session_put(session
);
3597 strncpy(sessions
[i
].name
, session
->name
, NAME_MAX
);
3598 sessions
[i
].name
[NAME_MAX
- 1] = '\0';
3599 sessions
[i
].enabled
= session
->active
;
3600 sessions
[i
].snapshot_mode
= session
->snapshot_mode
;
3601 sessions
[i
].live_timer_interval
= session
->live_timer
;
3602 extended
[i
].creation_time
.value
= (uint64_t) session
->creation_time
;
3603 extended
[i
].creation_time
.is_set
= 1;
3605 session_put(session
);
3610 * Command LTTNG_DATA_PENDING returning 0 if the data is NOT pending meaning
3611 * ready for trace analysis (or any kind of reader) or else 1 for pending data.
3613 int cmd_data_pending(struct ltt_session
*session
)
3616 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3617 struct ltt_ust_session
*usess
= session
->ust_session
;
3621 DBG("Data pending for session %s", session
->name
);
3623 /* Session MUST be stopped to ask for data availability. */
3624 if (session
->active
) {
3625 ret
= LTTNG_ERR_SESSION_STARTED
;
3629 * If stopped, just make sure we've started before else the above call
3630 * will always send that there is data pending.
3632 * The consumer assumes that when the data pending command is received,
3633 * the trace has been started before or else no output data is written
3634 * by the streams which is a condition for data pending. So, this is
3635 * *VERY* important that we don't ask the consumer before a start
3638 if (!session
->has_been_started
) {
3644 /* A rotation is still pending, we have to wait. */
3645 if (session
->rotation_state
== LTTNG_ROTATION_STATE_ONGOING
) {
3646 DBG("Rotate still pending for session %s", session
->name
);
3651 if (ksess
&& ksess
->consumer
) {
3652 ret
= consumer_is_data_pending(ksess
->id
, ksess
->consumer
);
3654 /* Data is still being extracted for the kernel. */
3659 if (usess
&& usess
->consumer
) {
3660 ret
= consumer_is_data_pending(usess
->id
, usess
->consumer
);
3662 /* Data is still being extracted for the kernel. */
3667 /* Data is ready to be read by a viewer */
3675 * Command LTTNG_SNAPSHOT_ADD_OUTPUT from the lttng ctl library.
3677 * Return LTTNG_OK on success or else a LTTNG_ERR code.
3679 int cmd_snapshot_add_output(struct ltt_session
*session
,
3680 struct lttng_snapshot_output
*output
, uint32_t *id
)
3683 struct snapshot_output
*new_output
;
3688 DBG("Cmd snapshot add output for session %s", session
->name
);
3691 * Can't create an output if the session is not set in no-output mode.
3693 if (session
->output_traces
) {
3694 ret
= LTTNG_ERR_NOT_SNAPSHOT_SESSION
;
3698 if (session
->has_non_mmap_channel
) {
3699 ret
= LTTNG_ERR_SNAPSHOT_UNSUPPORTED
;
3703 /* Only one output is allowed until we have the "tee" feature. */
3704 if (session
->snapshot
.nb_output
== 1) {
3705 ret
= LTTNG_ERR_SNAPSHOT_OUTPUT_EXIST
;
3709 new_output
= snapshot_output_alloc();
3711 ret
= LTTNG_ERR_NOMEM
;
3715 ret
= snapshot_output_init(session
, output
->max_size
, output
->name
,
3716 output
->ctrl_url
, output
->data_url
, session
->consumer
, new_output
,
3717 &session
->snapshot
);
3719 if (ret
== -ENOMEM
) {
3720 ret
= LTTNG_ERR_NOMEM
;
3722 ret
= LTTNG_ERR_INVALID
;
3728 snapshot_add_output(&session
->snapshot
, new_output
);
3730 *id
= new_output
->id
;
3737 snapshot_output_destroy(new_output
);
3743 * Command LTTNG_SNAPSHOT_DEL_OUTPUT from lib lttng ctl.
3745 * Return LTTNG_OK on success or else a LTTNG_ERR code.
3747 int cmd_snapshot_del_output(struct ltt_session
*session
,
3748 struct lttng_snapshot_output
*output
)
3751 struct snapshot_output
*sout
= NULL
;
3759 * Permission denied to create an output if the session is not
3760 * set in no output mode.
3762 if (session
->output_traces
) {
3763 ret
= LTTNG_ERR_NOT_SNAPSHOT_SESSION
;
3768 DBG("Cmd snapshot del output id %" PRIu32
" for session %s", output
->id
,
3770 sout
= snapshot_find_output_by_id(output
->id
, &session
->snapshot
);
3771 } else if (*output
->name
!= '\0') {
3772 DBG("Cmd snapshot del output name %s for session %s", output
->name
,
3774 sout
= snapshot_find_output_by_name(output
->name
, &session
->snapshot
);
3777 ret
= LTTNG_ERR_INVALID
;
3781 snapshot_delete_output(&session
->snapshot
, sout
);
3782 snapshot_output_destroy(sout
);
3791 * Command LTTNG_SNAPSHOT_LIST_OUTPUT from lib lttng ctl.
3793 * If no output is available, outputs is untouched and 0 is returned.
3795 * Return the size of the newly allocated outputs or a negative LTTNG_ERR code.
3797 ssize_t
cmd_snapshot_list_outputs(struct ltt_session
*session
,
3798 struct lttng_snapshot_output
**outputs
)
3801 struct lttng_snapshot_output
*list
= NULL
;
3802 struct lttng_ht_iter iter
;
3803 struct snapshot_output
*output
;
3808 DBG("Cmd snapshot list outputs for session %s", session
->name
);
3811 * Permission denied to create an output if the session is not
3812 * set in no output mode.
3814 if (session
->output_traces
) {
3815 ret
= -LTTNG_ERR_NOT_SNAPSHOT_SESSION
;
3819 if (session
->snapshot
.nb_output
== 0) {
3824 list
= zmalloc(session
->snapshot
.nb_output
* sizeof(*list
));
3826 ret
= -LTTNG_ERR_NOMEM
;
3830 /* Copy list from session to the new list object. */
3832 cds_lfht_for_each_entry(session
->snapshot
.output_ht
->ht
, &iter
.iter
,
3833 output
, node
.node
) {
3834 assert(output
->consumer
);
3835 list
[idx
].id
= output
->id
;
3836 list
[idx
].max_size
= output
->max_size
;
3837 if (lttng_strncpy(list
[idx
].name
, output
->name
,
3838 sizeof(list
[idx
].name
))) {
3839 ret
= -LTTNG_ERR_INVALID
;
3842 if (output
->consumer
->type
== CONSUMER_DST_LOCAL
) {
3843 if (lttng_strncpy(list
[idx
].ctrl_url
,
3844 output
->consumer
->dst
.session_root_path
,
3845 sizeof(list
[idx
].ctrl_url
))) {
3846 ret
= -LTTNG_ERR_INVALID
;
3851 ret
= uri_to_str_url(&output
->consumer
->dst
.net
.control
,
3852 list
[idx
].ctrl_url
, sizeof(list
[idx
].ctrl_url
));
3854 ret
= -LTTNG_ERR_NOMEM
;
3859 ret
= uri_to_str_url(&output
->consumer
->dst
.net
.data
,
3860 list
[idx
].data_url
, sizeof(list
[idx
].data_url
));
3862 ret
= -LTTNG_ERR_NOMEM
;
3871 ret
= session
->snapshot
.nb_output
;
3880 * Check if we can regenerate the metadata for this session.
3881 * Only kernel, UST per-uid and non-live sessions are supported.
3883 * Return 0 if the metadata can be generated, a LTTNG_ERR code otherwise.
3886 int check_regenerate_metadata_support(struct ltt_session
*session
)
3892 if (session
->live_timer
!= 0) {
3893 ret
= LTTNG_ERR_LIVE_SESSION
;
3896 if (!session
->active
) {
3897 ret
= LTTNG_ERR_SESSION_NOT_STARTED
;
3900 if (session
->ust_session
) {
3901 switch (session
->ust_session
->buffer_type
) {
3902 case LTTNG_BUFFER_PER_UID
:
3904 case LTTNG_BUFFER_PER_PID
:
3905 ret
= LTTNG_ERR_PER_PID_SESSION
;
3909 ret
= LTTNG_ERR_UNK
;
3913 if (session
->consumer
->type
== CONSUMER_DST_NET
&&
3914 session
->consumer
->relay_minor_version
< 8) {
3915 ret
= LTTNG_ERR_RELAYD_VERSION_FAIL
;
3925 int clear_metadata_file(int fd
)
3930 lseek_ret
= lseek(fd
, 0, SEEK_SET
);
3931 if (lseek_ret
< 0) {
3937 ret
= ftruncate(fd
, 0);
3939 PERROR("ftruncate");
3948 int ust_regenerate_metadata(struct ltt_ust_session
*usess
)
3951 struct buffer_reg_uid
*uid_reg
= NULL
;
3952 struct buffer_reg_session
*session_reg
= NULL
;
3955 cds_list_for_each_entry(uid_reg
, &usess
->buffer_reg_uid_list
, lnode
) {
3956 struct ust_registry_session
*registry
;
3957 struct ust_registry_channel
*chan
;
3958 struct lttng_ht_iter iter_chan
;
3960 session_reg
= uid_reg
->registry
;
3961 registry
= session_reg
->reg
.ust
;
3963 pthread_mutex_lock(®istry
->lock
);
3964 registry
->metadata_len_sent
= 0;
3965 memset(registry
->metadata
, 0, registry
->metadata_alloc_len
);
3966 registry
->metadata_len
= 0;
3967 registry
->metadata_version
++;
3968 if (registry
->metadata_fd
> 0) {
3969 /* Clear the metadata file's content. */
3970 ret
= clear_metadata_file(registry
->metadata_fd
);
3972 pthread_mutex_unlock(®istry
->lock
);
3977 ret
= ust_metadata_session_statedump(registry
, NULL
,
3978 registry
->major
, registry
->minor
);
3980 pthread_mutex_unlock(®istry
->lock
);
3981 ERR("Failed to generate session metadata (err = %d)",
3985 cds_lfht_for_each_entry(registry
->channels
->ht
, &iter_chan
.iter
,
3987 struct ust_registry_event
*event
;
3988 struct lttng_ht_iter iter_event
;
3990 ret
= ust_metadata_channel_statedump(registry
, chan
);
3992 pthread_mutex_unlock(®istry
->lock
);
3993 ERR("Failed to generate channel metadata "
3997 cds_lfht_for_each_entry(chan
->ht
->ht
, &iter_event
.iter
,
3999 ret
= ust_metadata_event_statedump(registry
,
4002 pthread_mutex_unlock(®istry
->lock
);
4003 ERR("Failed to generate event metadata "
4009 pthread_mutex_unlock(®istry
->lock
);
4018 * Command LTTNG_REGENERATE_METADATA from the lttng-ctl library.
4020 * Ask the consumer to truncate the existing metadata file(s) and
4021 * then regenerate the metadata. Live and per-pid sessions are not
4022 * supported and return an error.
4024 * Return 0 on success or else a LTTNG_ERR code.
4026 int cmd_regenerate_metadata(struct ltt_session
*session
)
4032 ret
= check_regenerate_metadata_support(session
);
4037 if (session
->kernel_session
) {
4038 ret
= kernctl_session_regenerate_metadata(
4039 session
->kernel_session
->fd
);
4041 ERR("Failed to regenerate the kernel metadata");
4046 if (session
->ust_session
) {
4047 ret
= ust_regenerate_metadata(session
->ust_session
);
4049 ERR("Failed to regenerate the UST metadata");
4053 DBG("Cmd metadata regenerate for session %s", session
->name
);
4061 * Command LTTNG_REGENERATE_STATEDUMP from the lttng-ctl library.
4063 * Ask the tracer to regenerate a new statedump.
4065 * Return 0 on success or else a LTTNG_ERR code.
4067 int cmd_regenerate_statedump(struct ltt_session
*session
)
4073 if (!session
->active
) {
4074 ret
= LTTNG_ERR_SESSION_NOT_STARTED
;
4078 if (session
->kernel_session
) {
4079 ret
= kernctl_session_regenerate_statedump(
4080 session
->kernel_session
->fd
);
4082 * Currently, the statedump in kernel can only fail if out
4086 if (ret
== -ENOMEM
) {
4087 ret
= LTTNG_ERR_REGEN_STATEDUMP_NOMEM
;
4089 ret
= LTTNG_ERR_REGEN_STATEDUMP_FAIL
;
4091 ERR("Failed to regenerate the kernel statedump");
4096 if (session
->ust_session
) {
4097 ret
= ust_app_regenerate_statedump_all(session
->ust_session
);
4099 * Currently, the statedump in UST always returns 0.
4102 ret
= LTTNG_ERR_REGEN_STATEDUMP_FAIL
;
4103 ERR("Failed to regenerate the UST statedump");
4107 DBG("Cmd regenerate statedump for session %s", session
->name
);
4114 int cmd_register_trigger(struct command_ctx
*cmd_ctx
, int sock
,
4115 struct notification_thread_handle
*notification_thread
)
4119 ssize_t sock_recv_len
;
4120 struct lttng_trigger
*trigger
= NULL
;
4121 struct lttng_buffer_view view
;
4122 struct lttng_dynamic_buffer trigger_buffer
;
4124 lttng_dynamic_buffer_init(&trigger_buffer
);
4125 trigger_len
= (size_t) cmd_ctx
->lsm
->u
.trigger
.length
;
4126 ret
= lttng_dynamic_buffer_set_size(&trigger_buffer
, trigger_len
);
4128 ret
= LTTNG_ERR_NOMEM
;
4132 sock_recv_len
= lttcomm_recv_unix_sock(sock
, trigger_buffer
.data
,
4134 if (sock_recv_len
< 0 || sock_recv_len
!= trigger_len
) {
4135 ERR("Failed to receive \"register trigger\" command payload");
4136 /* TODO: should this be a new error enum ? */
4137 ret
= LTTNG_ERR_INVALID_TRIGGER
;
4141 view
= lttng_buffer_view_from_dynamic_buffer(&trigger_buffer
, 0, -1);
4142 if (lttng_trigger_create_from_buffer(&view
, &trigger
) !=
4144 ERR("Invalid trigger payload received in \"register trigger\" command");
4145 ret
= LTTNG_ERR_INVALID_TRIGGER
;
4149 ret
= notification_thread_command_register_trigger(notification_thread
,
4151 /* Ownership of trigger was transferred. */
4154 lttng_trigger_destroy(trigger
);
4155 lttng_dynamic_buffer_reset(&trigger_buffer
);
4159 int cmd_unregister_trigger(struct command_ctx
*cmd_ctx
, int sock
,
4160 struct notification_thread_handle
*notification_thread
)
4164 ssize_t sock_recv_len
;
4165 struct lttng_trigger
*trigger
= NULL
;
4166 struct lttng_buffer_view view
;
4167 struct lttng_dynamic_buffer trigger_buffer
;
4169 lttng_dynamic_buffer_init(&trigger_buffer
);
4170 trigger_len
= (size_t) cmd_ctx
->lsm
->u
.trigger
.length
;
4171 ret
= lttng_dynamic_buffer_set_size(&trigger_buffer
, trigger_len
);
4173 ret
= LTTNG_ERR_NOMEM
;
4177 sock_recv_len
= lttcomm_recv_unix_sock(sock
, trigger_buffer
.data
,
4179 if (sock_recv_len
< 0 || sock_recv_len
!= trigger_len
) {
4180 ERR("Failed to receive \"unregister trigger\" command payload");
4181 /* TODO: should this be a new error enum ? */
4182 ret
= LTTNG_ERR_INVALID_TRIGGER
;
4186 view
= lttng_buffer_view_from_dynamic_buffer(&trigger_buffer
, 0, -1);
4187 if (lttng_trigger_create_from_buffer(&view
, &trigger
) !=
4189 ERR("Invalid trigger payload received in \"unregister trigger\" command");
4190 ret
= LTTNG_ERR_INVALID_TRIGGER
;
4194 ret
= notification_thread_command_unregister_trigger(notification_thread
,
4197 lttng_trigger_destroy(trigger
);
4198 lttng_dynamic_buffer_reset(&trigger_buffer
);
4203 * Send relayd sockets from snapshot output to consumer. Ignore request if the
4204 * snapshot output is *not* set with a remote destination.
4206 * Return LTTNG_OK on success or a LTTNG_ERR code.
4208 static enum lttng_error_code
set_relayd_for_snapshot(
4209 struct consumer_output
*output
,
4210 const struct ltt_session
*session
)
4212 enum lttng_error_code status
= LTTNG_OK
;
4213 struct lttng_ht_iter iter
;
4214 struct consumer_socket
*socket
;
4215 LTTNG_OPTIONAL(uint64_t) current_chunk_id
= {};
4220 DBG2("Set relayd object from snapshot output");
4222 if (session
->current_trace_chunk
) {
4223 enum lttng_trace_chunk_status chunk_status
=
4224 lttng_trace_chunk_get_id(
4225 session
->current_trace_chunk
,
4226 ¤t_chunk_id
.value
);
4228 if (chunk_status
== LTTNG_TRACE_CHUNK_STATUS_OK
) {
4229 current_chunk_id
.is_set
= true;
4231 ERR("Failed to get current trace chunk id");
4232 status
= LTTNG_ERR_UNK
;
4237 /* Ignore if snapshot consumer output is not network. */
4238 if (output
->type
!= CONSUMER_DST_NET
) {
4243 * For each consumer socket, create and send the relayd object of the
4247 cds_lfht_for_each_entry(output
->socks
->ht
, &iter
.iter
,
4248 socket
, node
.node
) {
4249 pthread_mutex_lock(socket
->lock
);
4250 status
= send_consumer_relayd_sockets(0, session
->id
,
4252 session
->name
, session
->hostname
,
4253 session
->live_timer
,
4254 current_chunk_id
.is_set
? ¤t_chunk_id
.value
: NULL
,
4255 session
->creation_time
);
4256 pthread_mutex_unlock(socket
->lock
);
4257 if (status
!= LTTNG_OK
) {
4269 * Record a kernel snapshot.
4271 * Return LTTNG_OK on success or a LTTNG_ERR code.
4273 static enum lttng_error_code
record_kernel_snapshot(
4274 struct ltt_kernel_session
*ksess
,
4275 const struct consumer_output
*output
,
4276 const struct ltt_session
*session
,
4277 int wait
, uint64_t nb_packets_per_stream
)
4279 enum lttng_error_code status
;
4285 status
= kernel_snapshot_record(
4286 ksess
, output
, wait
, nb_packets_per_stream
);
4291 * Record a UST snapshot.
4293 * Returns LTTNG_OK on success or a LTTNG_ERR error code.
4295 static enum lttng_error_code
record_ust_snapshot(struct ltt_ust_session
*usess
,
4296 const struct consumer_output
*output
,
4297 const struct ltt_session
*session
,
4298 int wait
, uint64_t nb_packets_per_stream
)
4300 enum lttng_error_code status
;
4306 status
= ust_app_snapshot_record(
4307 usess
, output
, wait
, nb_packets_per_stream
);
4312 uint64_t get_session_size_one_more_packet_per_stream(
4313 const struct ltt_session
*session
, uint64_t cur_nr_packets
)
4315 uint64_t tot_size
= 0;
4317 if (session
->kernel_session
) {
4318 struct ltt_kernel_channel
*chan
;
4319 const struct ltt_kernel_session
*ksess
=
4320 session
->kernel_session
;
4322 cds_list_for_each_entry(chan
, &ksess
->channel_list
.head
, list
) {
4323 if (cur_nr_packets
>= chan
->channel
->attr
.num_subbuf
) {
4325 * Don't take channel into account if we
4326 * already grab all its packets.
4330 tot_size
+= chan
->channel
->attr
.subbuf_size
4331 * chan
->stream_count
;
4335 if (session
->ust_session
) {
4336 const struct ltt_ust_session
*usess
= session
->ust_session
;
4338 tot_size
+= ust_app_get_size_one_more_packet_per_stream(usess
,
4346 * Calculate the number of packets we can grab from each stream that
4347 * fits within the overall snapshot max size.
4349 * Returns -1 on error, 0 means infinite number of packets, else > 0 is
4350 * the number of packets per stream.
4352 * TODO: this approach is not perfect: we consider the worse case
4353 * (packet filling the sub-buffers) as an upper bound, but we could do
4354 * better if we do this calculation while we actually grab the packet
4355 * content: we would know how much padding we don't actually store into
4358 * This algorithm is currently bounded by the number of packets per
4361 * Since we call this algorithm before actually grabbing the data, it's
4362 * an approximation: for instance, applications could appear/disappear
4363 * in between this call and actually grabbing data.
4366 int64_t get_session_nb_packets_per_stream(const struct ltt_session
*session
,
4370 uint64_t cur_nb_packets
= 0;
4373 return 0; /* Infinite */
4376 size_left
= max_size
;
4378 uint64_t one_more_packet_tot_size
;
4380 one_more_packet_tot_size
= get_session_size_one_more_packet_per_stream(
4381 session
, cur_nb_packets
);
4382 if (!one_more_packet_tot_size
) {
4383 /* We are already grabbing all packets. */
4386 size_left
-= one_more_packet_tot_size
;
4387 if (size_left
< 0) {
4392 if (!cur_nb_packets
) {
4393 /* Not enough room to grab one packet of each stream, error. */
4396 return cur_nb_packets
;
4400 enum lttng_error_code
snapshot_record(struct ltt_session
*session
,
4401 const struct snapshot_output
*snapshot_output
, int wait
)
4403 int64_t nb_packets_per_stream
;
4404 char snapshot_chunk_name
[LTTNG_NAME_MAX
];
4406 enum lttng_error_code ret_code
= LTTNG_OK
;
4407 struct lttng_trace_chunk
*snapshot_trace_chunk
;
4408 struct consumer_output
*original_ust_consumer_output
= NULL
;
4409 struct consumer_output
*original_kernel_consumer_output
= NULL
;
4410 struct consumer_output
*snapshot_ust_consumer_output
= NULL
;
4411 struct consumer_output
*snapshot_kernel_consumer_output
= NULL
;
4413 ret
= snprintf(snapshot_chunk_name
, sizeof(snapshot_chunk_name
),
4415 snapshot_output
->name
,
4416 snapshot_output
->datetime
,
4417 snapshot_output
->nb_snapshot
);
4418 if (ret
< 0 || ret
>= sizeof(snapshot_chunk_name
)) {
4419 ERR("Failed to format snapshot name");
4420 ret_code
= LTTNG_ERR_INVALID
;
4423 DBG("Recording snapshot \"%s\" for session \"%s\" with chunk name \"%s\"",
4424 snapshot_output
->name
, session
->name
,
4425 snapshot_chunk_name
);
4426 if (!session
->kernel_session
&& !session
->ust_session
) {
4427 ERR("Failed to record snapshot as no channels exist");
4428 ret_code
= LTTNG_ERR_NO_CHANNEL
;
4432 if (session
->kernel_session
) {
4433 original_kernel_consumer_output
=
4434 session
->kernel_session
->consumer
;
4435 snapshot_kernel_consumer_output
=
4436 consumer_copy_output(snapshot_output
->consumer
);
4437 ret
= consumer_copy_sockets(snapshot_kernel_consumer_output
,
4438 original_kernel_consumer_output
);
4440 ERR("Failed to copy consumer sockets from snapshot output configuration");
4441 ret_code
= LTTNG_ERR_NOMEM
;
4444 ret_code
= set_relayd_for_snapshot(
4445 snapshot_kernel_consumer_output
, session
);
4446 if (ret_code
!= LTTNG_OK
) {
4447 ERR("Failed to setup relay daemon for kernel tracer snapshot");
4450 session
->kernel_session
->consumer
=
4451 snapshot_kernel_consumer_output
;
4453 if (session
->ust_session
) {
4454 original_ust_consumer_output
= session
->ust_session
->consumer
;
4455 snapshot_ust_consumer_output
=
4456 consumer_copy_output(snapshot_output
->consumer
);
4457 ret
= consumer_copy_sockets(snapshot_ust_consumer_output
,
4458 original_ust_consumer_output
);
4460 ERR("Failed to copy consumer sockets from snapshot output configuration");
4461 ret_code
= LTTNG_ERR_NOMEM
;
4464 ret_code
= set_relayd_for_snapshot(
4465 snapshot_ust_consumer_output
, session
);
4466 if (ret_code
!= LTTNG_OK
) {
4467 ERR("Failed to setup relay daemon for userspace tracer snapshot");
4470 session
->ust_session
->consumer
=
4471 snapshot_ust_consumer_output
;
4474 snapshot_trace_chunk
= session_create_new_trace_chunk(session
,
4475 snapshot_kernel_consumer_output
?:
4476 snapshot_ust_consumer_output
,
4477 consumer_output_get_base_path(
4478 snapshot_output
->consumer
),
4479 snapshot_chunk_name
);
4480 if (!snapshot_trace_chunk
) {
4481 ERR("Failed to create temporary trace chunk to record a snapshot of session \"%s\"",
4483 ret_code
= LTTNG_ERR_CREATE_DIR_FAIL
;
4486 assert(!session
->current_trace_chunk
);
4487 ret
= session_set_trace_chunk(session
, snapshot_trace_chunk
, NULL
);
4488 lttng_trace_chunk_put(snapshot_trace_chunk
);
4489 snapshot_trace_chunk
= NULL
;
4491 ERR("Failed to set temporary trace chunk to record a snapshot of session \"%s\"",
4493 ret_code
= LTTNG_ERR_CREATE_TRACE_CHUNK_FAIL_CONSUMER
;
4497 nb_packets_per_stream
= get_session_nb_packets_per_stream(session
,
4498 snapshot_output
->max_size
);
4499 if (nb_packets_per_stream
< 0) {
4500 ret_code
= LTTNG_ERR_MAX_SIZE_INVALID
;
4504 if (session
->kernel_session
) {
4505 ret_code
= record_kernel_snapshot(session
->kernel_session
,
4506 snapshot_kernel_consumer_output
, session
,
4507 wait
, nb_packets_per_stream
);
4508 if (ret_code
!= LTTNG_OK
) {
4513 if (session
->ust_session
) {
4514 ret_code
= record_ust_snapshot(session
->ust_session
,
4515 snapshot_ust_consumer_output
, session
,
4516 wait
, nb_packets_per_stream
);
4517 if (ret_code
!= LTTNG_OK
) {
4522 if (session_close_trace_chunk(
4523 session
, session
->current_trace_chunk
, NULL
)) {
4525 * Don't goto end; make sure the chunk is closed for the session
4526 * to allow future snapshots.
4528 ERR("Failed to close snapshot trace chunk of session \"%s\"",
4530 ret_code
= LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER
;
4532 if (session_set_trace_chunk(session
, NULL
, NULL
)) {
4533 ERR("Failed to release the current trace chunk of session \"%s\"",
4535 ret_code
= LTTNG_ERR_UNK
;
4538 if (original_ust_consumer_output
) {
4539 session
->ust_session
->consumer
= original_ust_consumer_output
;
4541 if (original_kernel_consumer_output
) {
4542 session
->kernel_session
->consumer
=
4543 original_kernel_consumer_output
;
4545 consumer_output_put(snapshot_ust_consumer_output
);
4546 consumer_output_put(snapshot_kernel_consumer_output
);
4551 * Command LTTNG_SNAPSHOT_RECORD from lib lttng ctl.
4553 * The wait parameter is ignored so this call always wait for the snapshot to
4554 * complete before returning.
4556 * Return LTTNG_OK on success or else a LTTNG_ERR code.
4558 int cmd_snapshot_record(struct ltt_session
*session
,
4559 struct lttng_snapshot_output
*output
, int wait
)
4561 enum lttng_error_code cmd_ret
= LTTNG_OK
;
4563 unsigned int snapshot_success
= 0;
4565 struct snapshot_output
*tmp_output
= NULL
;
4570 DBG("Cmd snapshot record for session %s", session
->name
);
4572 /* Get the datetime for the snapshot output directory. */
4573 ret
= utils_get_current_time_str("%Y%m%d-%H%M%S", datetime
,
4576 cmd_ret
= LTTNG_ERR_INVALID
;
4581 * Permission denied to create an output if the session is not
4582 * set in no output mode.
4584 if (session
->output_traces
) {
4585 cmd_ret
= LTTNG_ERR_NOT_SNAPSHOT_SESSION
;
4589 /* The session needs to be started at least once. */
4590 if (!session
->has_been_started
) {
4591 cmd_ret
= LTTNG_ERR_START_SESSION_ONCE
;
4595 /* Use temporary output for the session. */
4596 if (*output
->ctrl_url
!= '\0') {
4597 tmp_output
= snapshot_output_alloc();
4599 cmd_ret
= LTTNG_ERR_NOMEM
;
4603 ret
= snapshot_output_init(session
, output
->max_size
,
4605 output
->ctrl_url
, output
->data_url
,
4609 if (ret
== -ENOMEM
) {
4610 cmd_ret
= LTTNG_ERR_NOMEM
;
4612 cmd_ret
= LTTNG_ERR_INVALID
;
4616 /* Use the global session count for the temporary snapshot. */
4617 tmp_output
->nb_snapshot
= session
->snapshot
.nb_snapshot
;
4619 /* Use the global datetime */
4620 memcpy(tmp_output
->datetime
, datetime
, sizeof(datetime
));
4621 cmd_ret
= snapshot_record(session
, tmp_output
, wait
);
4622 if (cmd_ret
!= LTTNG_OK
) {
4625 snapshot_success
= 1;
4627 struct snapshot_output
*sout
;
4628 struct lttng_ht_iter iter
;
4631 cds_lfht_for_each_entry(session
->snapshot
.output_ht
->ht
,
4632 &iter
.iter
, sout
, node
.node
) {
4633 struct snapshot_output output_copy
;
4636 * Make a local copy of the output and override output
4637 * parameters with those provided as part of the
4640 memcpy(&output_copy
, sout
, sizeof(output_copy
));
4642 if (output
->max_size
!= (uint64_t) -1ULL) {
4643 output_copy
.max_size
= output
->max_size
;
4646 output_copy
.nb_snapshot
= session
->snapshot
.nb_snapshot
;
4647 memcpy(output_copy
.datetime
, datetime
,
4650 /* Use temporary name. */
4651 if (*output
->name
!= '\0') {
4652 if (lttng_strncpy(output_copy
.name
,
4654 sizeof(output_copy
.name
))) {
4655 cmd_ret
= LTTNG_ERR_INVALID
;
4661 cmd_ret
= snapshot_record(session
, &output_copy
, wait
);
4662 if (cmd_ret
!= LTTNG_OK
) {
4666 snapshot_success
= 1;
4671 if (snapshot_success
) {
4672 session
->snapshot
.nb_snapshot
++;
4674 cmd_ret
= LTTNG_ERR_SNAPSHOT_FAIL
;
4679 snapshot_output_destroy(tmp_output
);
4685 * Command LTTNG_SET_SESSION_SHM_PATH processed by the client thread.
4687 int cmd_set_session_shm_path(struct ltt_session
*session
,
4688 const char *shm_path
)
4694 * Can only set shm path before session is started.
4696 if (session
->has_been_started
) {
4697 return LTTNG_ERR_SESSION_STARTED
;
4700 strncpy(session
->shm_path
, shm_path
,
4701 sizeof(session
->shm_path
));
4702 session
->shm_path
[sizeof(session
->shm_path
) - 1] = '\0';
4708 * Command LTTNG_ROTATE_SESSION from the lttng-ctl library.
4710 * Ask the consumer to rotate the session output directory.
4711 * The session lock must be held.
4713 * Returns LTTNG_OK on success or else a negative LTTng error code.
4715 int cmd_rotate_session(struct ltt_session
*session
,
4716 struct lttng_rotate_session_return
*rotate_return
)
4719 uint64_t ongoing_rotation_chunk_id
;
4720 enum lttng_error_code cmd_ret
= LTTNG_OK
;
4721 struct lttng_trace_chunk
*chunk_being_archived
= NULL
;
4722 struct lttng_trace_chunk
*new_trace_chunk
= NULL
;
4723 enum lttng_trace_chunk_status chunk_status
;
4727 if (!session
->has_been_started
) {
4728 cmd_ret
= LTTNG_ERR_START_SESSION_ONCE
;
4732 if (session
->live_timer
|| !session
->output_traces
) {
4733 cmd_ret
= LTTNG_ERR_ROTATION_NOT_AVAILABLE
;
4737 /* Unsupported feature in lttng-relayd before 2.11. */
4738 if (session
->consumer
->type
== CONSUMER_DST_NET
&&
4739 (session
->consumer
->relay_major_version
== 2 &&
4740 session
->consumer
->relay_minor_version
< 11)) {
4741 cmd_ret
= LTTNG_ERR_ROTATION_NOT_AVAILABLE_RELAY
;
4745 if (session
->rotation_state
== LTTNG_ROTATION_STATE_ONGOING
) {
4746 DBG("Refusing to launch a rotation; a rotation is already in progress for session %s",
4748 cmd_ret
= LTTNG_ERR_ROTATION_PENDING
;
4753 * After a stop, we only allow one rotation to occur, the other ones are
4754 * useless until a new start.
4756 if (session
->rotated_after_last_stop
) {
4757 DBG("Session \"%s\" was already rotated after stop, refusing rotation",
4759 cmd_ret
= LTTNG_ERR_ROTATION_MULTIPLE_AFTER_STOP
;
4763 session
->rotation_state
= LTTNG_ROTATION_STATE_ONGOING
;
4765 if (session
->active
) {
4766 new_trace_chunk
= session_create_new_trace_chunk(session
, NULL
,
4768 if (!new_trace_chunk
) {
4769 cmd_ret
= LTTNG_ERR_CREATE_DIR_FAIL
;
4774 /* The current trace chunk becomes the chunk being archived. */
4775 ret
= session_set_trace_chunk(session
, new_trace_chunk
,
4776 &chunk_being_archived
);
4778 cmd_ret
= LTTNG_ERR_CREATE_TRACE_CHUNK_FAIL_CONSUMER
;
4782 assert(chunk_being_archived
);
4783 chunk_status
= lttng_trace_chunk_get_id(chunk_being_archived
,
4784 &ongoing_rotation_chunk_id
);
4785 assert(chunk_status
== LTTNG_TRACE_CHUNK_STATUS_OK
);
4787 if (session
->kernel_session
) {
4788 cmd_ret
= kernel_rotate_session(session
);
4789 if (cmd_ret
!= LTTNG_OK
) {
4793 if (session
->ust_session
) {
4794 cmd_ret
= ust_app_rotate_session(session
);
4795 if (cmd_ret
!= LTTNG_OK
) {
4800 ret
= session_close_trace_chunk(session
, chunk_being_archived
,
4801 &((enum lttng_trace_chunk_command_type
) {
4802 LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED
}));
4804 cmd_ret
= LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER
;
4808 ret
= timer_session_rotation_pending_check_start(session
,
4809 DEFAULT_ROTATE_PENDING_TIMER
);
4811 cmd_ret
= LTTNG_ERR_UNK
;
4815 if (!session
->active
) {
4816 session
->rotated_after_last_stop
= true;
4819 if (rotate_return
) {
4820 rotate_return
->rotation_id
= ongoing_rotation_chunk_id
;
4823 session
->chunk_being_archived
= chunk_being_archived
;
4824 chunk_being_archived
= NULL
;
4825 ret
= notification_thread_command_session_rotation_ongoing(
4826 notification_thread_handle
,
4827 session
->name
, session
->uid
, session
->gid
,
4828 ongoing_rotation_chunk_id
);
4829 if (ret
!= LTTNG_OK
) {
4830 ERR("Failed to notify notification thread that a session rotation is ongoing for session %s",
4835 DBG("Cmd rotate session %s, archive_id %" PRIu64
" sent",
4836 session
->name
, ongoing_rotation_chunk_id
);
4838 lttng_trace_chunk_put(new_trace_chunk
);
4839 lttng_trace_chunk_put(chunk_being_archived
);
4840 ret
= (cmd_ret
== LTTNG_OK
) ? cmd_ret
: -((int) cmd_ret
);
4843 if (session_reset_rotation_state(session
,
4844 LTTNG_ROTATION_STATE_ERROR
)) {
4845 ERR("Failed to reset rotation state of session \"%s\"",
4852 * Command LTTNG_ROTATION_GET_INFO from the lttng-ctl library.
4854 * Check if the session has finished its rotation.
4856 * Return LTTNG_OK on success or else an LTTNG_ERR code.
4858 int cmd_rotate_get_info(struct ltt_session
*session
,
4859 struct lttng_rotation_get_info_return
*info_return
,
4860 uint64_t rotation_id
)
4862 enum lttng_error_code cmd_ret
= LTTNG_OK
;
4863 enum lttng_rotation_state rotation_state
;
4865 DBG("Cmd rotate_get_info session %s, rotation id %" PRIu64
, session
->name
,
4866 session
->most_recent_chunk_id
.value
);
4868 if (session
->chunk_being_archived
) {
4869 enum lttng_trace_chunk_status chunk_status
;
4872 chunk_status
= lttng_trace_chunk_get_id(
4873 session
->chunk_being_archived
,
4875 assert(chunk_status
== LTTNG_TRACE_CHUNK_STATUS_OK
);
4877 rotation_state
= rotation_id
== chunk_id
?
4878 LTTNG_ROTATION_STATE_ONGOING
:
4879 LTTNG_ROTATION_STATE_EXPIRED
;
4881 if (session
->last_archived_chunk_id
.is_set
&&
4882 rotation_id
!= session
->last_archived_chunk_id
.value
) {
4883 rotation_state
= LTTNG_ROTATION_STATE_EXPIRED
;
4885 rotation_state
= session
->rotation_state
;
4889 switch (rotation_state
) {
4890 case LTTNG_ROTATION_STATE_NO_ROTATION
:
4891 DBG("Reporting that no rotation has occured within the lifetime of session \"%s\"",
4894 case LTTNG_ROTATION_STATE_EXPIRED
:
4895 DBG("Reporting that the rotation state of rotation id %" PRIu64
" of session \"%s\" has expired",
4896 rotation_id
, session
->name
);
4898 case LTTNG_ROTATION_STATE_ONGOING
:
4899 DBG("Reporting that rotation id %" PRIu64
" of session \"%s\" is still pending",
4900 rotation_id
, session
->name
);
4902 case LTTNG_ROTATION_STATE_COMPLETED
:
4906 char *current_tracing_path_reply
;
4907 size_t current_tracing_path_reply_len
;
4909 DBG("Reporting that rotation id %" PRIu64
" of session \"%s\" is completed",
4910 rotation_id
, session
->name
);
4912 switch (session_get_consumer_destination_type(session
)) {
4913 case CONSUMER_DST_LOCAL
:
4914 current_tracing_path_reply
=
4915 info_return
->location
.local
.absolute_path
;
4916 current_tracing_path_reply_len
=
4917 sizeof(info_return
->location
.local
.absolute_path
);
4918 info_return
->location_type
=
4919 (int8_t) LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
;
4921 case CONSUMER_DST_NET
:
4922 current_tracing_path_reply
=
4923 info_return
->location
.relay
.relative_path
;
4924 current_tracing_path_reply_len
=
4925 sizeof(info_return
->location
.relay
.relative_path
);
4926 /* Currently the only supported relay protocol. */
4927 info_return
->location
.relay
.protocol
=
4928 (int8_t) LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP
;
4930 fmt_ret
= lttng_strncpy(info_return
->location
.relay
.host
,
4931 session_get_net_consumer_hostname(session
),
4932 sizeof(info_return
->location
.relay
.host
));
4934 ERR("Failed to copy host name to rotate_get_info reply");
4935 info_return
->status
= LTTNG_ROTATION_STATUS_ERROR
;
4936 cmd_ret
= LTTNG_ERR_SET_URL
;
4940 session_get_net_consumer_ports(session
,
4941 &info_return
->location
.relay
.ports
.control
,
4942 &info_return
->location
.relay
.ports
.data
);
4943 info_return
->location_type
=
4944 (int8_t) LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
;
4949 fmt_ret
= asprintf(&chunk_path
,
4950 "%s/" DEFAULT_ARCHIVED_TRACE_CHUNKS_DIRECTORY
"/%s",
4951 session_get_base_path(session
),
4952 session
->last_archived_chunk_name
);
4953 if (fmt_ret
== -1) {
4954 PERROR("Failed to format the path of the last archived trace chunk");
4955 info_return
->status
= LTTNG_ROTATION_STATUS_ERROR
;
4956 cmd_ret
= LTTNG_ERR_UNK
;
4960 fmt_ret
= lttng_strncpy(current_tracing_path_reply
,
4961 chunk_path
, current_tracing_path_reply_len
);
4964 ERR("Failed to copy path of the last archived trace chunk to rotate_get_info reply");
4965 info_return
->status
= LTTNG_ROTATION_STATUS_ERROR
;
4966 cmd_ret
= LTTNG_ERR_UNK
;
4972 case LTTNG_ROTATION_STATE_ERROR
:
4973 DBG("Reporting that an error occurred during rotation %" PRIu64
" of session \"%s\"",
4974 rotation_id
, session
->name
);
4982 info_return
->status
= (int32_t) rotation_state
;
4987 * Command LTTNG_ROTATION_SET_SCHEDULE from the lttng-ctl library.
4989 * Configure the automatic rotation parameters.
4990 * 'activate' to true means activate the rotation schedule type with 'new_value'.
4991 * 'activate' to false means deactivate the rotation schedule and validate that
4992 * 'new_value' has the same value as the currently active value.
4994 * Return 0 on success or else a positive LTTNG_ERR code.
4996 int cmd_rotation_set_schedule(struct ltt_session
*session
,
4997 bool activate
, enum lttng_rotation_schedule_type schedule_type
,
4999 struct notification_thread_handle
*notification_thread_handle
)
5002 uint64_t *parameter_value
;
5006 DBG("Cmd rotate set schedule session %s", session
->name
);
5008 if (session
->live_timer
|| !session
->output_traces
) {
5009 DBG("Failing ROTATION_SET_SCHEDULE command as the rotation feature is not available for this session");
5010 ret
= LTTNG_ERR_ROTATION_NOT_AVAILABLE
;
5014 switch (schedule_type
) {
5015 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
5016 parameter_value
= &session
->rotate_size
;
5018 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
5019 parameter_value
= &session
->rotate_timer_period
;
5020 if (new_value
>= UINT_MAX
) {
5021 DBG("Failing ROTATION_SET_SCHEDULE command as the value requested for a periodic rotation schedule is invalid: %" PRIu64
" > %u (UINT_MAX)",
5022 new_value
, UINT_MAX
);
5023 ret
= LTTNG_ERR_INVALID
;
5028 WARN("Failing ROTATION_SET_SCHEDULE command on unknown schedule type");
5029 ret
= LTTNG_ERR_INVALID
;
5033 /* Improper use of the API. */
5034 if (new_value
== -1ULL) {
5035 WARN("Failing ROTATION_SET_SCHEDULE command as the value requested is -1");
5036 ret
= LTTNG_ERR_INVALID
;
5041 * As indicated in struct ltt_session's comments, a value of == 0 means
5042 * this schedule rotation type is not in use.
5044 * Reject the command if we were asked to activate a schedule that was
5047 if (activate
&& *parameter_value
!= 0) {
5048 DBG("Failing ROTATION_SET_SCHEDULE (activate) command as the schedule is already active");
5049 ret
= LTTNG_ERR_ROTATION_SCHEDULE_SET
;
5054 * Reject the command if we were asked to deactivate a schedule that was
5057 if (!activate
&& *parameter_value
== 0) {
5058 DBG("Failing ROTATION_SET_SCHEDULE (deactivate) command as the schedule is already inactive");
5059 ret
= LTTNG_ERR_ROTATION_SCHEDULE_NOT_SET
;
5064 * Reject the command if we were asked to deactivate a schedule that
5067 if (!activate
&& *parameter_value
!= new_value
) {
5068 DBG("Failing ROTATION_SET_SCHEDULE (deactivate) command as an inexistant schedule was provided");
5069 ret
= LTTNG_ERR_ROTATION_SCHEDULE_NOT_SET
;
5073 *parameter_value
= activate
? new_value
: 0;
5075 switch (schedule_type
) {
5076 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
5077 if (activate
&& session
->active
) {
5079 * Only start the timer if the session is active,
5080 * otherwise it will be started when the session starts.
5082 ret
= timer_session_rotation_schedule_timer_start(
5083 session
, new_value
);
5085 ERR("Failed to enable session rotation timer in ROTATION_SET_SCHEDULE command");
5086 ret
= LTTNG_ERR_UNK
;
5090 ret
= timer_session_rotation_schedule_timer_stop(
5093 ERR("Failed to disable session rotation timer in ROTATION_SET_SCHEDULE command");
5094 ret
= LTTNG_ERR_UNK
;
5099 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
5101 ret
= subscribe_session_consumed_size_rotation(session
,
5102 new_value
, notification_thread_handle
);
5104 ERR("Failed to enable consumed-size notification in ROTATION_SET_SCHEDULE command");
5105 ret
= LTTNG_ERR_UNK
;
5109 ret
= unsubscribe_session_consumed_size_rotation(session
,
5110 notification_thread_handle
);
5112 ERR("Failed to disable consumed-size notification in ROTATION_SET_SCHEDULE command");
5113 ret
= LTTNG_ERR_UNK
;
5120 /* Would have been caught before. */
5132 /* Wait for a given path to be removed before continuing. */
5133 static enum lttng_error_code
wait_on_path(void *path_data
)
5135 const char *shm_path
= path_data
;
5137 DBG("Waiting for the shm path at %s to be removed before completing session destruction",
5143 ret
= stat(shm_path
, &st
);
5145 if (errno
!= ENOENT
) {
5146 PERROR("stat() returned an error while checking for the existence of the shm path");
5148 DBG("shm path no longer exists, completing the destruction of session");
5152 if (!S_ISDIR(st
.st_mode
)) {
5153 ERR("The type of shm path %s returned by stat() is not a directory; aborting the wait for shm path removal",
5158 usleep(SESSION_DESTROY_SHM_PATH_CHECK_DELAY_US
);
5164 * Returns a pointer to a handler to run on completion of a command.
5165 * Returns NULL if no handler has to be run for the last command executed.
5167 const struct cmd_completion_handler
*cmd_pop_completion_handler(void)
5169 struct cmd_completion_handler
*handler
= current_completion_handler
;
5171 current_completion_handler
= NULL
;
5176 * Init command subsystem.
5181 * Set network sequence index to 1 for streams to match a relayd
5182 * socket on the consumer side.
5184 pthread_mutex_lock(&relayd_net_seq_idx_lock
);
5185 relayd_net_seq_idx
= 1;
5186 pthread_mutex_unlock(&relayd_net_seq_idx_lock
);
5188 DBG("Command subsystem initialized");