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>
25 #include <common/defaults.h>
26 #include <common/common.h>
27 #include <common/sessiond-comm/sessiond-comm.h>
28 #include <common/relayd/relayd.h>
29 #include <common/utils.h>
30 #include <common/compat/string.h>
35 #include "health-sessiond.h"
37 #include "kernel-consumer.h"
38 #include "lttng-sessiond.h"
46 * Used to keep a unique index for each relayd socket created where this value
47 * is associated with streams on the consumer so it can match the right relayd
48 * to send to. It must be accessed with the relayd_net_seq_idx_lock
51 static pthread_mutex_t relayd_net_seq_idx_lock
= PTHREAD_MUTEX_INITIALIZER
;
52 static uint64_t relayd_net_seq_idx
;
54 static int validate_event_name(const char *);
55 static int validate_ust_event_name(const char *);
56 static int cmd_enable_event_internal(struct ltt_session
*session
,
57 struct lttng_domain
*domain
,
58 char *channel_name
, struct lttng_event
*event
,
59 char *filter_expression
,
60 struct lttng_filter_bytecode
*filter
,
61 struct lttng_event_exclusion
*exclusion
,
65 * Create a session path used by list_lttng_sessions for the case that the
66 * session consumer is on the network.
68 static int build_network_session_path(char *dst
, size_t size
,
69 struct ltt_session
*session
)
71 int ret
, kdata_port
, udata_port
;
72 struct lttng_uri
*kuri
= NULL
, *uuri
= NULL
, *uri
= NULL
;
73 char tmp_uurl
[PATH_MAX
], tmp_urls
[PATH_MAX
];
78 memset(tmp_urls
, 0, sizeof(tmp_urls
));
79 memset(tmp_uurl
, 0, sizeof(tmp_uurl
));
81 kdata_port
= udata_port
= DEFAULT_NETWORK_DATA_PORT
;
83 if (session
->kernel_session
&& session
->kernel_session
->consumer
) {
84 kuri
= &session
->kernel_session
->consumer
->dst
.net
.control
;
85 kdata_port
= session
->kernel_session
->consumer
->dst
.net
.data
.port
;
88 if (session
->ust_session
&& session
->ust_session
->consumer
) {
89 uuri
= &session
->ust_session
->consumer
->dst
.net
.control
;
90 udata_port
= session
->ust_session
->consumer
->dst
.net
.data
.port
;
93 if (uuri
== NULL
&& kuri
== NULL
) {
94 uri
= &session
->consumer
->dst
.net
.control
;
95 kdata_port
= session
->consumer
->dst
.net
.data
.port
;
96 } else if (kuri
&& uuri
) {
97 ret
= uri_compare(kuri
, uuri
);
101 /* Build uuri URL string */
102 ret
= uri_to_str_url(uuri
, tmp_uurl
, sizeof(tmp_uurl
));
109 } else if (kuri
&& uuri
== NULL
) {
111 } else if (uuri
&& kuri
== NULL
) {
115 ret
= uri_to_str_url(uri
, tmp_urls
, sizeof(tmp_urls
));
121 * Do we have a UST url set. If yes, this means we have both kernel and UST
124 if (*tmp_uurl
!= '\0') {
125 ret
= snprintf(dst
, size
, "[K]: %s [data: %d] -- [U]: %s [data: %d]",
126 tmp_urls
, kdata_port
, tmp_uurl
, udata_port
);
129 if (kuri
|| (!kuri
&& !uuri
)) {
132 /* No kernel URI, use the UST port. */
135 ret
= snprintf(dst
, size
, "%s [data: %d]", tmp_urls
, dport
);
143 * Get run-time attributes if the session has been started (discarded events,
146 static int get_kernel_runtime_stats(struct ltt_session
*session
,
147 struct ltt_kernel_channel
*kchan
, uint64_t *discarded_events
,
148 uint64_t *lost_packets
)
152 if (!session
->has_been_started
) {
154 *discarded_events
= 0;
159 ret
= consumer_get_discarded_events(session
->id
, kchan
->fd
,
160 session
->kernel_session
->consumer
,
166 ret
= consumer_get_lost_packets(session
->id
, kchan
->fd
,
167 session
->kernel_session
->consumer
,
178 * Get run-time attributes if the session has been started (discarded events,
181 static int get_ust_runtime_stats(struct ltt_session
*session
,
182 struct ltt_ust_channel
*uchan
, uint64_t *discarded_events
,
183 uint64_t *lost_packets
)
186 struct ltt_ust_session
*usess
;
188 usess
= session
->ust_session
;
190 if (!usess
|| !session
->has_been_started
) {
191 *discarded_events
= 0;
197 if (usess
->buffer_type
== LTTNG_BUFFER_PER_UID
) {
198 ret
= ust_app_uid_get_channel_runtime_stats(usess
->id
,
199 &usess
->buffer_reg_uid_list
,
200 usess
->consumer
, uchan
->id
,
201 uchan
->attr
.overwrite
,
204 } else if (usess
->buffer_type
== LTTNG_BUFFER_PER_PID
) {
205 ret
= ust_app_pid_get_channel_runtime_stats(usess
,
206 uchan
, usess
->consumer
,
207 uchan
->attr
.overwrite
,
213 *discarded_events
+= uchan
->per_pid_closed_app_discarded
;
214 *lost_packets
+= uchan
->per_pid_closed_app_lost
;
216 ERR("Unsupported buffer type");
226 * Fill lttng_channel array of all channels.
228 static void list_lttng_channels(enum lttng_domain_type domain
,
229 struct ltt_session
*session
, struct lttng_channel
*channels
,
230 struct lttcomm_channel_extended
*chan_exts
)
233 struct ltt_kernel_channel
*kchan
;
235 DBG("Listing channels for session %s", session
->name
);
238 case LTTNG_DOMAIN_KERNEL
:
239 /* Kernel channels */
240 if (session
->kernel_session
!= NULL
) {
241 cds_list_for_each_entry(kchan
,
242 &session
->kernel_session
->channel_list
.head
, list
) {
243 uint64_t discarded_events
, lost_packets
;
245 ret
= get_kernel_runtime_stats(session
, kchan
,
246 &discarded_events
, &lost_packets
);
250 /* Copy lttng_channel struct to array */
251 memcpy(&channels
[i
], kchan
->channel
, sizeof(struct lttng_channel
));
252 channels
[i
].enabled
= kchan
->enabled
;
253 chan_exts
[i
].discarded_events
=
255 chan_exts
[i
].lost_packets
= lost_packets
;
260 case LTTNG_DOMAIN_UST
:
262 struct lttng_ht_iter iter
;
263 struct ltt_ust_channel
*uchan
;
266 cds_lfht_for_each_entry(session
->ust_session
->domain_global
.channels
->ht
,
267 &iter
.iter
, uchan
, node
.node
) {
268 uint64_t discarded_events
, lost_packets
;
270 strncpy(channels
[i
].name
, uchan
->name
, LTTNG_SYMBOL_NAME_LEN
);
271 channels
[i
].attr
.overwrite
= uchan
->attr
.overwrite
;
272 channels
[i
].attr
.subbuf_size
= uchan
->attr
.subbuf_size
;
273 channels
[i
].attr
.num_subbuf
= uchan
->attr
.num_subbuf
;
274 channels
[i
].attr
.switch_timer_interval
=
275 uchan
->attr
.switch_timer_interval
;
276 channels
[i
].attr
.read_timer_interval
=
277 uchan
->attr
.read_timer_interval
;
278 channels
[i
].enabled
= uchan
->enabled
;
279 channels
[i
].attr
.tracefile_size
= uchan
->tracefile_size
;
280 channels
[i
].attr
.tracefile_count
= uchan
->tracefile_count
;
281 switch (uchan
->attr
.output
) {
284 channels
[i
].attr
.output
= LTTNG_EVENT_MMAP
;
288 ret
= get_ust_runtime_stats(session
, uchan
,
289 &discarded_events
, &lost_packets
);
293 chan_exts
[i
].discarded_events
= discarded_events
;
294 chan_exts
[i
].lost_packets
= lost_packets
;
308 static void increment_extended_len(const char *filter_expression
,
309 struct lttng_event_exclusion
*exclusion
, size_t *extended_len
)
311 *extended_len
+= sizeof(struct lttcomm_event_extended_header
);
313 if (filter_expression
) {
314 *extended_len
+= strlen(filter_expression
) + 1;
318 *extended_len
+= exclusion
->count
* LTTNG_SYMBOL_NAME_LEN
;
322 static void append_extended_info(const char *filter_expression
,
323 struct lttng_event_exclusion
*exclusion
, void **extended_at
)
325 struct lttcomm_event_extended_header extended_header
;
326 size_t filter_len
= 0;
327 size_t nb_exclusions
= 0;
329 if (filter_expression
) {
330 filter_len
= strlen(filter_expression
) + 1;
334 nb_exclusions
= exclusion
->count
;
337 /* Set header fields */
338 extended_header
.filter_len
= filter_len
;
339 extended_header
.nb_exclusions
= nb_exclusions
;
342 memcpy(*extended_at
, &extended_header
, sizeof(extended_header
));
343 *extended_at
+= sizeof(extended_header
);
345 /* Copy filter string */
346 if (filter_expression
) {
347 memcpy(*extended_at
, filter_expression
, filter_len
);
348 *extended_at
+= filter_len
;
351 /* Copy exclusion names */
353 size_t len
= nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
;
355 memcpy(*extended_at
, &exclusion
->names
, len
);
361 * Create a list of agent domain events.
363 * Return number of events in list on success or else a negative value.
365 static int list_lttng_agent_events(struct agent
*agt
,
366 struct lttng_event
**events
, size_t *total_size
)
369 unsigned int nb_event
= 0;
370 struct agent_event
*event
;
371 struct lttng_event
*tmp_events
;
372 struct lttng_ht_iter iter
;
373 size_t extended_len
= 0;
379 DBG3("Listing agent events");
382 nb_event
= lttng_ht_get_count(agt
->events
);
390 /* Compute required extended infos size */
391 extended_len
= nb_event
* sizeof(struct lttcomm_event_extended_header
);
394 * This is only valid because the commands which add events are
395 * processed in the same thread as the listing.
398 cds_lfht_for_each_entry(agt
->events
->ht
, &iter
.iter
, event
, node
.node
) {
399 increment_extended_len(event
->filter_expression
, NULL
,
404 *total_size
= nb_event
* sizeof(*tmp_events
) + extended_len
;
405 tmp_events
= zmalloc(*total_size
);
407 PERROR("zmalloc agent events session");
408 ret
= -LTTNG_ERR_FATAL
;
412 extended_at
= ((uint8_t *) tmp_events
) +
413 nb_event
* sizeof(struct lttng_event
);
416 cds_lfht_for_each_entry(agt
->events
->ht
, &iter
.iter
, event
, node
.node
) {
417 strncpy(tmp_events
[i
].name
, event
->name
, sizeof(tmp_events
[i
].name
));
418 tmp_events
[i
].name
[sizeof(tmp_events
[i
].name
) - 1] = '\0';
419 tmp_events
[i
].enabled
= event
->enabled
;
420 tmp_events
[i
].loglevel
= event
->loglevel_value
;
421 tmp_events
[i
].loglevel_type
= event
->loglevel_type
;
424 /* Append extended info */
425 append_extended_info(event
->filter_expression
, NULL
,
430 *events
= tmp_events
;
434 assert(nb_event
== i
);
439 * Create a list of ust global domain events.
441 static int list_lttng_ust_global_events(char *channel_name
,
442 struct ltt_ust_domain_global
*ust_global
,
443 struct lttng_event
**events
, size_t *total_size
)
446 unsigned int nb_event
= 0;
447 struct lttng_ht_iter iter
;
448 struct lttng_ht_node_str
*node
;
449 struct ltt_ust_channel
*uchan
;
450 struct ltt_ust_event
*uevent
;
451 struct lttng_event
*tmp
;
452 size_t extended_len
= 0;
455 DBG("Listing UST global events for channel %s", channel_name
);
459 lttng_ht_lookup(ust_global
->channels
, (void *)channel_name
, &iter
);
460 node
= lttng_ht_iter_get_node_str(&iter
);
462 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
466 uchan
= caa_container_of(&node
->node
, struct ltt_ust_channel
, node
.node
);
468 nb_event
= lttng_ht_get_count(uchan
->events
);
475 DBG3("Listing UST global %d events", nb_event
);
477 /* Compute required extended infos size */
478 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
479 if (uevent
->internal
) {
484 increment_extended_len(uevent
->filter_expression
,
485 uevent
->exclusion
, &extended_len
);
488 /* All events are internal, skip. */
494 *total_size
= nb_event
* sizeof(struct lttng_event
) + extended_len
;
495 tmp
= zmalloc(*total_size
);
497 ret
= -LTTNG_ERR_FATAL
;
501 extended_at
= ((uint8_t *) tmp
) + nb_event
* sizeof(struct lttng_event
);
503 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
504 if (uevent
->internal
) {
505 /* This event should remain hidden from clients */
508 strncpy(tmp
[i
].name
, uevent
->attr
.name
, LTTNG_SYMBOL_NAME_LEN
);
509 tmp
[i
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
510 tmp
[i
].enabled
= uevent
->enabled
;
512 switch (uevent
->attr
.instrumentation
) {
513 case LTTNG_UST_TRACEPOINT
:
514 tmp
[i
].type
= LTTNG_EVENT_TRACEPOINT
;
516 case LTTNG_UST_PROBE
:
517 tmp
[i
].type
= LTTNG_EVENT_PROBE
;
519 case LTTNG_UST_FUNCTION
:
520 tmp
[i
].type
= LTTNG_EVENT_FUNCTION
;
524 tmp
[i
].loglevel
= uevent
->attr
.loglevel
;
525 switch (uevent
->attr
.loglevel_type
) {
526 case LTTNG_UST_LOGLEVEL_ALL
:
527 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
529 case LTTNG_UST_LOGLEVEL_RANGE
:
530 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
532 case LTTNG_UST_LOGLEVEL_SINGLE
:
533 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
536 if (uevent
->filter
) {
539 if (uevent
->exclusion
) {
540 tmp
[i
].exclusion
= 1;
544 /* Append extended info */
545 append_extended_info(uevent
->filter_expression
,
546 uevent
->exclusion
, &extended_at
);
557 * Fill lttng_event array of all kernel events in the channel.
559 static int list_lttng_kernel_events(char *channel_name
,
560 struct ltt_kernel_session
*kernel_session
,
561 struct lttng_event
**events
, size_t *total_size
)
564 unsigned int nb_event
;
565 struct ltt_kernel_event
*event
;
566 struct ltt_kernel_channel
*kchan
;
567 size_t extended_len
= 0;
570 kchan
= trace_kernel_get_channel_by_name(channel_name
, kernel_session
);
572 ret
= LTTNG_ERR_KERN_CHAN_NOT_FOUND
;
576 nb_event
= kchan
->event_count
;
578 DBG("Listing events for channel %s", kchan
->channel
->name
);
586 /* Compute required extended infos size */
587 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
588 increment_extended_len(event
->filter_expression
, NULL
,
592 *total_size
= nb_event
* sizeof(struct lttng_event
) + extended_len
;
593 *events
= zmalloc(*total_size
);
594 if (*events
== NULL
) {
595 ret
= LTTNG_ERR_FATAL
;
599 extended_at
= ((uint8_t *) events
) +
600 nb_event
* sizeof(struct lttng_event
);
602 /* Kernel channels */
603 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
604 strncpy((*events
)[i
].name
, event
->event
->name
, LTTNG_SYMBOL_NAME_LEN
);
605 (*events
)[i
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
606 (*events
)[i
].enabled
= event
->enabled
;
607 (*events
)[i
].filter
=
608 (unsigned char) !!event
->filter_expression
;
610 switch (event
->event
->instrumentation
) {
611 case LTTNG_KERNEL_TRACEPOINT
:
612 (*events
)[i
].type
= LTTNG_EVENT_TRACEPOINT
;
614 case LTTNG_KERNEL_KRETPROBE
:
615 (*events
)[i
].type
= LTTNG_EVENT_FUNCTION
;
616 memcpy(&(*events
)[i
].attr
.probe
, &event
->event
->u
.kprobe
,
617 sizeof(struct lttng_kernel_kprobe
));
619 case LTTNG_KERNEL_KPROBE
:
620 (*events
)[i
].type
= LTTNG_EVENT_PROBE
;
621 memcpy(&(*events
)[i
].attr
.probe
, &event
->event
->u
.kprobe
,
622 sizeof(struct lttng_kernel_kprobe
));
624 case LTTNG_KERNEL_FUNCTION
:
625 (*events
)[i
].type
= LTTNG_EVENT_FUNCTION
;
626 memcpy(&((*events
)[i
].attr
.ftrace
), &event
->event
->u
.ftrace
,
627 sizeof(struct lttng_kernel_function
));
629 case LTTNG_KERNEL_NOOP
:
630 (*events
)[i
].type
= LTTNG_EVENT_NOOP
;
632 case LTTNG_KERNEL_SYSCALL
:
633 (*events
)[i
].type
= LTTNG_EVENT_SYSCALL
;
635 case LTTNG_KERNEL_ALL
:
641 /* Append extended info */
642 append_extended_info(event
->filter_expression
, NULL
,
650 new_size
= syscall_list_channel(kchan
, events
, nb_event
);
662 /* Negate the error code to differentiate the size from an error */
667 * Add URI so the consumer output object. Set the correct path depending on the
668 * domain adding the default trace directory.
670 static int add_uri_to_consumer(struct consumer_output
*consumer
,
671 struct lttng_uri
*uri
, enum lttng_domain_type domain
,
672 const char *session_name
)
675 const char *default_trace_dir
;
679 if (consumer
== NULL
) {
680 DBG("No consumer detected. Don't add URI. Stopping.");
681 ret
= LTTNG_ERR_NO_CONSUMER
;
686 case LTTNG_DOMAIN_KERNEL
:
687 default_trace_dir
= DEFAULT_KERNEL_TRACE_DIR
;
689 case LTTNG_DOMAIN_UST
:
690 default_trace_dir
= DEFAULT_UST_TRACE_DIR
;
694 * This case is possible is we try to add the URI to the global tracing
695 * session consumer object which in this case there is no subdir.
697 default_trace_dir
= "";
700 switch (uri
->dtype
) {
703 DBG2("Setting network URI to consumer");
705 if (consumer
->type
== CONSUMER_DST_NET
) {
706 if ((uri
->stype
== LTTNG_STREAM_CONTROL
&&
707 consumer
->dst
.net
.control_isset
) ||
708 (uri
->stype
== LTTNG_STREAM_DATA
&&
709 consumer
->dst
.net
.data_isset
)) {
710 ret
= LTTNG_ERR_URL_EXIST
;
714 memset(&consumer
->dst
.net
, 0, sizeof(consumer
->dst
.net
));
717 consumer
->type
= CONSUMER_DST_NET
;
719 /* Set URI into consumer output object */
720 ret
= consumer_set_network_uri(consumer
, uri
);
724 } else if (ret
== 1) {
726 * URI was the same in the consumer so we do not append the subdir
727 * again so to not duplicate output dir.
733 if (uri
->stype
== LTTNG_STREAM_CONTROL
&& strlen(uri
->subdir
) == 0) {
734 ret
= consumer_set_subdir(consumer
, session_name
);
736 ret
= LTTNG_ERR_FATAL
;
741 if (uri
->stype
== LTTNG_STREAM_CONTROL
) {
742 /* On a new subdir, reappend the default trace dir. */
743 strncat(consumer
->subdir
, default_trace_dir
,
744 sizeof(consumer
->subdir
) - strlen(consumer
->subdir
) - 1);
745 DBG3("Append domain trace name to subdir %s", consumer
->subdir
);
750 DBG2("Setting trace directory path from URI to %s", uri
->dst
.path
);
751 memset(consumer
->dst
.trace_path
, 0,
752 sizeof(consumer
->dst
.trace_path
));
753 strncpy(consumer
->dst
.trace_path
, uri
->dst
.path
,
754 sizeof(consumer
->dst
.trace_path
));
755 /* Append default trace dir */
756 strncat(consumer
->dst
.trace_path
, default_trace_dir
,
757 sizeof(consumer
->dst
.trace_path
) -
758 strlen(consumer
->dst
.trace_path
) - 1);
759 /* Flag consumer as local. */
760 consumer
->type
= CONSUMER_DST_LOCAL
;
771 * Init tracing by creating trace directory and sending fds kernel consumer.
773 static int init_kernel_tracing(struct ltt_kernel_session
*session
)
776 struct lttng_ht_iter iter
;
777 struct consumer_socket
*socket
;
783 if (session
->consumer_fds_sent
== 0 && session
->consumer
!= NULL
) {
784 cds_lfht_for_each_entry(session
->consumer
->socks
->ht
, &iter
.iter
,
786 pthread_mutex_lock(socket
->lock
);
787 ret
= kernel_consumer_send_session(socket
, session
);
788 pthread_mutex_unlock(socket
->lock
);
790 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
802 * Create a socket to the relayd using the URI.
804 * On success, the relayd_sock pointer is set to the created socket.
805 * Else, it's stays untouched and a lttcomm error code is returned.
807 static int create_connect_relayd(struct lttng_uri
*uri
,
808 struct lttcomm_relayd_sock
**relayd_sock
)
811 struct lttcomm_relayd_sock
*rsock
;
813 rsock
= lttcomm_alloc_relayd_sock(uri
, RELAYD_VERSION_COMM_MAJOR
,
814 RELAYD_VERSION_COMM_MINOR
);
816 ret
= LTTNG_ERR_FATAL
;
821 * Connect to relayd so we can proceed with a session creation. This call
822 * can possibly block for an arbitrary amount of time to set the health
823 * state to be in poll execution.
826 ret
= relayd_connect(rsock
);
829 ERR("Unable to reach lttng-relayd");
830 ret
= LTTNG_ERR_RELAYD_CONNECT_FAIL
;
834 /* Create socket for control stream. */
835 if (uri
->stype
== LTTNG_STREAM_CONTROL
) {
836 DBG3("Creating relayd stream socket from URI");
838 /* Check relayd version */
839 ret
= relayd_version_check(rsock
);
841 ret
= LTTNG_ERR_RELAYD_VERSION_FAIL
;
844 } else if (uri
->stype
== LTTNG_STREAM_DATA
) {
845 DBG3("Creating relayd data socket from URI");
847 /* Command is not valid */
848 ERR("Relayd invalid stream type: %d", uri
->stype
);
849 ret
= LTTNG_ERR_INVALID
;
853 *relayd_sock
= rsock
;
858 /* The returned value is not useful since we are on an error path. */
859 (void) relayd_close(rsock
);
867 * Connect to the relayd using URI and send the socket to the right consumer.
869 static int send_consumer_relayd_socket(enum lttng_domain_type domain
,
870 unsigned int session_id
, struct lttng_uri
*relayd_uri
,
871 struct consumer_output
*consumer
,
872 struct consumer_socket
*consumer_sock
,
873 char *session_name
, char *hostname
, int session_live_timer
)
876 struct lttcomm_relayd_sock
*rsock
= NULL
;
878 /* Connect to relayd and make version check if uri is the control. */
879 ret
= create_connect_relayd(relayd_uri
, &rsock
);
880 if (ret
!= LTTNG_OK
) {
885 /* Set the network sequence index if not set. */
886 if (consumer
->net_seq_index
== (uint64_t) -1ULL) {
887 pthread_mutex_lock(&relayd_net_seq_idx_lock
);
889 * Increment net_seq_idx because we are about to transfer the
890 * new relayd socket to the consumer.
891 * Assign unique key so the consumer can match streams.
893 consumer
->net_seq_index
= ++relayd_net_seq_idx
;
894 pthread_mutex_unlock(&relayd_net_seq_idx_lock
);
897 /* Send relayd socket to consumer. */
898 ret
= consumer_send_relayd_socket(consumer_sock
, rsock
, consumer
,
899 relayd_uri
->stype
, session_id
,
900 session_name
, hostname
, session_live_timer
);
902 ret
= LTTNG_ERR_ENABLE_CONSUMER_FAIL
;
906 /* Flag that the corresponding socket was sent. */
907 if (relayd_uri
->stype
== LTTNG_STREAM_CONTROL
) {
908 consumer_sock
->control_sock_sent
= 1;
909 } else if (relayd_uri
->stype
== LTTNG_STREAM_DATA
) {
910 consumer_sock
->data_sock_sent
= 1;
916 * Close socket which was dup on the consumer side. The session daemon does
917 * NOT keep track of the relayd socket(s) once transfer to the consumer.
921 (void) relayd_close(rsock
);
925 if (ret
!= LTTNG_OK
) {
927 * The consumer output for this session should not be used anymore
928 * since the relayd connection failed thus making any tracing or/and
929 * streaming not usable.
931 consumer
->enabled
= 0;
937 * Send both relayd sockets to a specific consumer and domain. This is a
938 * helper function to facilitate sending the information to the consumer for a
941 static int send_consumer_relayd_sockets(enum lttng_domain_type domain
,
942 unsigned int session_id
, struct consumer_output
*consumer
,
943 struct consumer_socket
*sock
, char *session_name
,
944 char *hostname
, int session_live_timer
)
951 /* Sending control relayd socket. */
952 if (!sock
->control_sock_sent
) {
953 ret
= send_consumer_relayd_socket(domain
, session_id
,
954 &consumer
->dst
.net
.control
, consumer
, sock
,
955 session_name
, hostname
, session_live_timer
);
956 if (ret
!= LTTNG_OK
) {
961 /* Sending data relayd socket. */
962 if (!sock
->data_sock_sent
) {
963 ret
= send_consumer_relayd_socket(domain
, session_id
,
964 &consumer
->dst
.net
.data
, consumer
, sock
,
965 session_name
, hostname
, session_live_timer
);
966 if (ret
!= LTTNG_OK
) {
976 * Setup relayd connections for a tracing session. First creates the socket to
977 * the relayd and send them to the right domain consumer. Consumer type MUST be
980 int cmd_setup_relayd(struct ltt_session
*session
)
983 struct ltt_ust_session
*usess
;
984 struct ltt_kernel_session
*ksess
;
985 struct consumer_socket
*socket
;
986 struct lttng_ht_iter iter
;
990 usess
= session
->ust_session
;
991 ksess
= session
->kernel_session
;
993 DBG("Setting relayd for session %s", session
->name
);
997 if (usess
&& usess
->consumer
&& usess
->consumer
->type
== CONSUMER_DST_NET
998 && usess
->consumer
->enabled
) {
999 /* For each consumer socket, send relayd sockets */
1000 cds_lfht_for_each_entry(usess
->consumer
->socks
->ht
, &iter
.iter
,
1001 socket
, node
.node
) {
1002 pthread_mutex_lock(socket
->lock
);
1003 ret
= send_consumer_relayd_sockets(LTTNG_DOMAIN_UST
, session
->id
,
1004 usess
->consumer
, socket
,
1005 session
->name
, session
->hostname
,
1006 session
->live_timer
);
1007 pthread_mutex_unlock(socket
->lock
);
1008 if (ret
!= LTTNG_OK
) {
1011 /* Session is now ready for network streaming. */
1012 session
->net_handle
= 1;
1016 if (ksess
&& ksess
->consumer
&& ksess
->consumer
->type
== CONSUMER_DST_NET
1017 && ksess
->consumer
->enabled
) {
1018 cds_lfht_for_each_entry(ksess
->consumer
->socks
->ht
, &iter
.iter
,
1019 socket
, node
.node
) {
1020 pthread_mutex_lock(socket
->lock
);
1021 ret
= send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL
, session
->id
,
1022 ksess
->consumer
, socket
,
1023 session
->name
, session
->hostname
,
1024 session
->live_timer
);
1025 pthread_mutex_unlock(socket
->lock
);
1026 if (ret
!= LTTNG_OK
) {
1029 /* Session is now ready for network streaming. */
1030 session
->net_handle
= 1;
1040 * Start a kernel session by opening all necessary streams.
1042 static int start_kernel_session(struct ltt_kernel_session
*ksess
, int wpipe
)
1045 struct ltt_kernel_channel
*kchan
;
1047 /* Open kernel metadata */
1048 if (ksess
->metadata
== NULL
&& ksess
->output_traces
) {
1049 ret
= kernel_open_metadata(ksess
);
1051 ret
= LTTNG_ERR_KERN_META_FAIL
;
1056 /* Open kernel metadata stream */
1057 if (ksess
->metadata
&& ksess
->metadata_stream_fd
< 0) {
1058 ret
= kernel_open_metadata_stream(ksess
);
1060 ERR("Kernel create metadata stream failed");
1061 ret
= LTTNG_ERR_KERN_STREAM_FAIL
;
1066 /* For each channel */
1067 cds_list_for_each_entry(kchan
, &ksess
->channel_list
.head
, list
) {
1068 if (kchan
->stream_count
== 0) {
1069 ret
= kernel_open_channel_stream(kchan
);
1071 ret
= LTTNG_ERR_KERN_STREAM_FAIL
;
1074 /* Update the stream global counter */
1075 ksess
->stream_count_global
+= ret
;
1079 /* Setup kernel consumer socket and send fds to it */
1080 ret
= init_kernel_tracing(ksess
);
1082 ret
= LTTNG_ERR_KERN_START_FAIL
;
1086 /* This start the kernel tracing */
1087 ret
= kernel_start_session(ksess
);
1089 ret
= LTTNG_ERR_KERN_START_FAIL
;
1093 /* Quiescent wait after starting trace */
1094 kernel_wait_quiescent(kernel_tracer_fd
);
1105 * Command LTTNG_DISABLE_CHANNEL processed by the client thread.
1107 int cmd_disable_channel(struct ltt_session
*session
,
1108 enum lttng_domain_type domain
, char *channel_name
)
1111 struct ltt_ust_session
*usess
;
1113 usess
= session
->ust_session
;
1118 case LTTNG_DOMAIN_KERNEL
:
1120 ret
= channel_kernel_disable(session
->kernel_session
,
1122 if (ret
!= LTTNG_OK
) {
1126 kernel_wait_quiescent(kernel_tracer_fd
);
1129 case LTTNG_DOMAIN_UST
:
1131 struct ltt_ust_channel
*uchan
;
1132 struct lttng_ht
*chan_ht
;
1134 chan_ht
= usess
->domain_global
.channels
;
1136 uchan
= trace_ust_find_channel_by_name(chan_ht
, channel_name
);
1137 if (uchan
== NULL
) {
1138 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1142 ret
= channel_ust_disable(usess
, uchan
);
1143 if (ret
!= LTTNG_OK
) {
1149 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1161 * Command LTTNG_TRACK_PID processed by the client thread.
1163 * Called with session lock held.
1165 int cmd_track_pid(struct ltt_session
*session
, enum lttng_domain_type domain
,
1173 case LTTNG_DOMAIN_KERNEL
:
1175 struct ltt_kernel_session
*ksess
;
1177 ksess
= session
->kernel_session
;
1179 ret
= kernel_track_pid(ksess
, pid
);
1180 if (ret
!= LTTNG_OK
) {
1184 kernel_wait_quiescent(kernel_tracer_fd
);
1187 case LTTNG_DOMAIN_UST
:
1189 struct ltt_ust_session
*usess
;
1191 usess
= session
->ust_session
;
1193 ret
= trace_ust_track_pid(usess
, pid
);
1194 if (ret
!= LTTNG_OK
) {
1200 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1212 * Command LTTNG_UNTRACK_PID processed by the client thread.
1214 * Called with session lock held.
1216 int cmd_untrack_pid(struct ltt_session
*session
, enum lttng_domain_type domain
,
1224 case LTTNG_DOMAIN_KERNEL
:
1226 struct ltt_kernel_session
*ksess
;
1228 ksess
= session
->kernel_session
;
1230 ret
= kernel_untrack_pid(ksess
, pid
);
1231 if (ret
!= LTTNG_OK
) {
1235 kernel_wait_quiescent(kernel_tracer_fd
);
1238 case LTTNG_DOMAIN_UST
:
1240 struct ltt_ust_session
*usess
;
1242 usess
= session
->ust_session
;
1244 ret
= trace_ust_untrack_pid(usess
, pid
);
1245 if (ret
!= LTTNG_OK
) {
1251 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1263 * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
1265 * The wpipe arguments is used as a notifier for the kernel thread.
1267 int cmd_enable_channel(struct ltt_session
*session
,
1268 struct lttng_domain
*domain
, struct lttng_channel
*attr
, int wpipe
)
1271 struct ltt_ust_session
*usess
= session
->ust_session
;
1272 struct lttng_ht
*chan_ht
;
1279 len
= lttng_strnlen(attr
->name
, sizeof(attr
->name
));
1281 /* Validate channel name */
1282 if (attr
->name
[0] == '.' ||
1283 memchr(attr
->name
, '/', len
) != NULL
) {
1284 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1288 DBG("Enabling channel %s for session %s", attr
->name
, session
->name
);
1293 * Don't try to enable a channel if the session has been started at
1294 * some point in time before. The tracer does not allow it.
1296 if (session
->has_been_started
) {
1297 ret
= LTTNG_ERR_TRACE_ALREADY_STARTED
;
1302 * If the session is a live session, remove the switch timer, the
1303 * live timer does the same thing but sends also synchronisation
1304 * beacons for inactive streams.
1306 if (session
->live_timer
> 0) {
1307 attr
->attr
.live_timer_interval
= session
->live_timer
;
1308 attr
->attr
.switch_timer_interval
= 0;
1312 * The ringbuffer (both in user space and kernel) behave badly in overwrite
1313 * mode and with less than 2 subbuf so block it right away and send back an
1314 * invalid attribute error.
1316 if (attr
->attr
.overwrite
&& attr
->attr
.num_subbuf
< 2) {
1317 ret
= LTTNG_ERR_INVALID
;
1321 switch (domain
->type
) {
1322 case LTTNG_DOMAIN_KERNEL
:
1324 struct ltt_kernel_channel
*kchan
;
1326 kchan
= trace_kernel_get_channel_by_name(attr
->name
,
1327 session
->kernel_session
);
1328 if (kchan
== NULL
) {
1329 ret
= channel_kernel_create(session
->kernel_session
, attr
, wpipe
);
1330 if (attr
->name
[0] != '\0') {
1331 session
->kernel_session
->has_non_default_channel
= 1;
1334 ret
= channel_kernel_enable(session
->kernel_session
, kchan
);
1337 if (ret
!= LTTNG_OK
) {
1341 kernel_wait_quiescent(kernel_tracer_fd
);
1344 case LTTNG_DOMAIN_UST
:
1345 case LTTNG_DOMAIN_JUL
:
1346 case LTTNG_DOMAIN_LOG4J
:
1347 case LTTNG_DOMAIN_PYTHON
:
1349 struct ltt_ust_channel
*uchan
;
1354 * Current agent implementation limitations force us to allow
1355 * only one channel at once in "agent" subdomains. Each
1356 * subdomain has a default channel name which must be strictly
1359 if (domain
->type
== LTTNG_DOMAIN_JUL
) {
1360 if (strncmp(attr
->name
, DEFAULT_JUL_CHANNEL_NAME
,
1361 LTTNG_SYMBOL_NAME_LEN
)) {
1362 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1365 } else if (domain
->type
== LTTNG_DOMAIN_LOG4J
) {
1366 if (strncmp(attr
->name
, DEFAULT_LOG4J_CHANNEL_NAME
,
1367 LTTNG_SYMBOL_NAME_LEN
)) {
1368 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1371 } else if (domain
->type
== LTTNG_DOMAIN_PYTHON
) {
1372 if (strncmp(attr
->name
, DEFAULT_PYTHON_CHANNEL_NAME
,
1373 LTTNG_SYMBOL_NAME_LEN
)) {
1374 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1379 chan_ht
= usess
->domain_global
.channels
;
1381 uchan
= trace_ust_find_channel_by_name(chan_ht
, attr
->name
);
1382 if (uchan
== NULL
) {
1383 ret
= channel_ust_create(usess
, attr
, domain
->buf_type
);
1384 if (attr
->name
[0] != '\0') {
1385 usess
->has_non_default_channel
= 1;
1388 ret
= channel_ust_enable(usess
, uchan
);
1393 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1404 * Command LTTNG_DISABLE_EVENT processed by the client thread.
1406 int cmd_disable_event(struct ltt_session
*session
,
1407 enum lttng_domain_type domain
, char *channel_name
,
1408 struct lttng_event
*event
)
1413 DBG("Disable event command for event \'%s\'", event
->name
);
1415 event_name
= event
->name
;
1416 if (validate_event_name(event_name
)) {
1417 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
1421 /* Error out on unhandled search criteria */
1422 if (event
->loglevel_type
|| event
->loglevel
!= -1 || event
->enabled
1423 || event
->pid
|| event
->filter
|| event
->exclusion
) {
1424 ret
= LTTNG_ERR_UNK
;
1431 case LTTNG_DOMAIN_KERNEL
:
1433 struct ltt_kernel_channel
*kchan
;
1434 struct ltt_kernel_session
*ksess
;
1436 ksess
= session
->kernel_session
;
1439 * If a non-default channel has been created in the
1440 * session, explicitely require that -c chan_name needs
1443 if (ksess
->has_non_default_channel
&& channel_name
[0] == '\0') {
1444 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
1448 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksess
);
1449 if (kchan
== NULL
) {
1450 ret
= LTTNG_ERR_KERN_CHAN_NOT_FOUND
;
1454 switch (event
->type
) {
1455 case LTTNG_EVENT_ALL
:
1456 case LTTNG_EVENT_TRACEPOINT
:
1457 case LTTNG_EVENT_SYSCALL
:
1458 case LTTNG_EVENT_PROBE
:
1459 case LTTNG_EVENT_FUNCTION
:
1460 case LTTNG_EVENT_FUNCTION_ENTRY
:/* fall-through */
1461 if (event_name
[0] == '\0') {
1462 ret
= event_kernel_disable_event(kchan
,
1465 ret
= event_kernel_disable_event(kchan
,
1466 event_name
, event
->type
);
1468 if (ret
!= LTTNG_OK
) {
1473 ret
= LTTNG_ERR_UNK
;
1477 kernel_wait_quiescent(kernel_tracer_fd
);
1480 case LTTNG_DOMAIN_UST
:
1482 struct ltt_ust_channel
*uchan
;
1483 struct ltt_ust_session
*usess
;
1485 usess
= session
->ust_session
;
1487 if (validate_ust_event_name(event_name
)) {
1488 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
1493 * If a non-default channel has been created in the
1494 * session, explicitly require that -c chan_name needs
1497 if (usess
->has_non_default_channel
&& channel_name
[0] == '\0') {
1498 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
1502 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
1504 if (uchan
== NULL
) {
1505 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1509 switch (event
->type
) {
1510 case LTTNG_EVENT_ALL
:
1512 * An empty event name means that everything
1513 * should be disabled.
1515 if (event
->name
[0] == '\0') {
1516 ret
= event_ust_disable_all_tracepoints(usess
, uchan
);
1518 ret
= event_ust_disable_tracepoint(usess
, uchan
,
1521 if (ret
!= LTTNG_OK
) {
1526 ret
= LTTNG_ERR_UNK
;
1530 DBG3("Disable UST event %s in channel %s completed", event_name
,
1534 case LTTNG_DOMAIN_LOG4J
:
1535 case LTTNG_DOMAIN_JUL
:
1536 case LTTNG_DOMAIN_PYTHON
:
1539 struct ltt_ust_session
*usess
= session
->ust_session
;
1543 switch (event
->type
) {
1544 case LTTNG_EVENT_ALL
:
1547 ret
= LTTNG_ERR_UNK
;
1551 agt
= trace_ust_find_agent(usess
, domain
);
1553 ret
= -LTTNG_ERR_UST_EVENT_NOT_FOUND
;
1557 * An empty event name means that everything
1558 * should be disabled.
1560 if (event
->name
[0] == '\0') {
1561 ret
= event_agent_disable_all(usess
, agt
);
1563 ret
= event_agent_disable(usess
, agt
, event_name
);
1565 if (ret
!= LTTNG_OK
) {
1572 ret
= LTTNG_ERR_UND
;
1585 * Command LTTNG_ADD_CONTEXT processed by the client thread.
1587 int cmd_add_context(struct ltt_session
*session
, enum lttng_domain_type domain
,
1588 char *channel_name
, struct lttng_event_context
*ctx
, int kwpipe
)
1590 int ret
, chan_kern_created
= 0, chan_ust_created
= 0;
1591 char *app_ctx_provider_name
= NULL
, *app_ctx_name
= NULL
;
1593 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
1594 app_ctx_provider_name
= ctx
->u
.app_ctx
.provider_name
;
1595 app_ctx_name
= ctx
->u
.app_ctx
.ctx_name
;
1599 case LTTNG_DOMAIN_KERNEL
:
1600 assert(session
->kernel_session
);
1602 if (session
->kernel_session
->channel_count
== 0) {
1603 /* Create default channel */
1604 ret
= channel_kernel_create(session
->kernel_session
, NULL
, kwpipe
);
1605 if (ret
!= LTTNG_OK
) {
1608 chan_kern_created
= 1;
1610 /* Add kernel context to kernel tracer */
1611 ret
= context_kernel_add(session
->kernel_session
, ctx
, channel_name
);
1612 if (ret
!= LTTNG_OK
) {
1616 case LTTNG_DOMAIN_JUL
:
1617 case LTTNG_DOMAIN_LOG4J
:
1620 * Validate channel name.
1621 * If no channel name is given and the domain is JUL or LOG4J,
1622 * set it to the appropriate domain-specific channel name. If
1623 * a name is provided but does not match the expexted channel
1624 * name, return an error.
1626 if (domain
== LTTNG_DOMAIN_JUL
&& *channel_name
&&
1627 strcmp(channel_name
,
1628 DEFAULT_JUL_CHANNEL_NAME
)) {
1629 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1631 } else if (domain
== LTTNG_DOMAIN_LOG4J
&& *channel_name
&&
1632 strcmp(channel_name
,
1633 DEFAULT_LOG4J_CHANNEL_NAME
)) {
1634 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1637 /* break is _not_ missing here. */
1639 case LTTNG_DOMAIN_UST
:
1641 struct ltt_ust_session
*usess
= session
->ust_session
;
1642 unsigned int chan_count
;
1646 chan_count
= lttng_ht_get_count(usess
->domain_global
.channels
);
1647 if (chan_count
== 0) {
1648 struct lttng_channel
*attr
;
1649 /* Create default channel */
1650 attr
= channel_new_default_attr(domain
, usess
->buffer_type
);
1652 ret
= LTTNG_ERR_FATAL
;
1656 ret
= channel_ust_create(usess
, attr
, usess
->buffer_type
);
1657 if (ret
!= LTTNG_OK
) {
1662 chan_ust_created
= 1;
1665 ret
= context_ust_add(usess
, domain
, ctx
, channel_name
);
1666 free(app_ctx_provider_name
);
1668 app_ctx_name
= NULL
;
1669 app_ctx_provider_name
= NULL
;
1670 if (ret
!= LTTNG_OK
) {
1676 ret
= LTTNG_ERR_UND
;
1684 if (chan_kern_created
) {
1685 struct ltt_kernel_channel
*kchan
=
1686 trace_kernel_get_channel_by_name(DEFAULT_CHANNEL_NAME
,
1687 session
->kernel_session
);
1688 /* Created previously, this should NOT fail. */
1690 kernel_destroy_channel(kchan
);
1693 if (chan_ust_created
) {
1694 struct ltt_ust_channel
*uchan
=
1695 trace_ust_find_channel_by_name(
1696 session
->ust_session
->domain_global
.channels
,
1697 DEFAULT_CHANNEL_NAME
);
1698 /* Created previously, this should NOT fail. */
1700 /* Remove from the channel list of the session. */
1701 trace_ust_delete_channel(session
->ust_session
->domain_global
.channels
,
1703 trace_ust_destroy_channel(uchan
);
1706 free(app_ctx_provider_name
);
1711 static int validate_event_name(const char *name
)
1714 const char *c
= name
;
1715 const char *event_name_end
= c
+ LTTNG_SYMBOL_NAME_LEN
;
1716 bool null_terminated
= false;
1719 * Make sure that unescaped wildcards are only used as the last
1720 * character of the event name.
1722 while (c
< event_name_end
) {
1725 null_terminated
= true;
1731 if ((c
+ 1) < event_name_end
&& *(c
+ 1)) {
1732 /* Wildcard is not the last character */
1733 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
1742 if (!ret
&& !null_terminated
) {
1743 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
1748 static inline bool name_starts_with(const char *name
, const char *prefix
)
1750 const size_t max_cmp_len
= min(strlen(prefix
), LTTNG_SYMBOL_NAME_LEN
);
1752 return !strncmp(name
, prefix
, max_cmp_len
);
1755 /* Perform userspace-specific event name validation */
1756 static int validate_ust_event_name(const char *name
)
1766 * Check name against all internal UST event component namespaces used
1769 if (name_starts_with(name
, DEFAULT_JUL_EVENT_COMPONENT
) ||
1770 name_starts_with(name
, DEFAULT_LOG4J_EVENT_COMPONENT
) ||
1771 name_starts_with(name
, DEFAULT_PYTHON_EVENT_COMPONENT
)) {
1780 * Internal version of cmd_enable_event() with a supplemental
1781 * "internal_event" flag which is used to enable internal events which should
1782 * be hidden from clients. Such events are used in the agent implementation to
1783 * enable the events through which all "agent" events are funeled.
1785 static int _cmd_enable_event(struct ltt_session
*session
,
1786 struct lttng_domain
*domain
,
1787 char *channel_name
, struct lttng_event
*event
,
1788 char *filter_expression
,
1789 struct lttng_filter_bytecode
*filter
,
1790 struct lttng_event_exclusion
*exclusion
,
1791 int wpipe
, bool internal_event
)
1793 int ret
, channel_created
= 0;
1794 struct lttng_channel
*attr
;
1798 assert(channel_name
);
1800 /* If we have a filter, we must have its filter expression */
1801 assert(!(!!filter_expression
^ !!filter
));
1803 DBG("Enable event command for event \'%s\'", event
->name
);
1807 ret
= validate_event_name(event
->name
);
1812 switch (domain
->type
) {
1813 case LTTNG_DOMAIN_KERNEL
:
1815 struct ltt_kernel_channel
*kchan
;
1818 * If a non-default channel has been created in the
1819 * session, explicitely require that -c chan_name needs
1822 if (session
->kernel_session
->has_non_default_channel
1823 && channel_name
[0] == '\0') {
1824 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
1828 kchan
= trace_kernel_get_channel_by_name(channel_name
,
1829 session
->kernel_session
);
1830 if (kchan
== NULL
) {
1831 attr
= channel_new_default_attr(LTTNG_DOMAIN_KERNEL
,
1832 LTTNG_BUFFER_GLOBAL
);
1834 ret
= LTTNG_ERR_FATAL
;
1837 strncpy(attr
->name
, channel_name
, sizeof(attr
->name
));
1839 ret
= cmd_enable_channel(session
, domain
, attr
, wpipe
);
1840 if (ret
!= LTTNG_OK
) {
1846 channel_created
= 1;
1849 /* Get the newly created kernel channel pointer */
1850 kchan
= trace_kernel_get_channel_by_name(channel_name
,
1851 session
->kernel_session
);
1852 if (kchan
== NULL
) {
1853 /* This sould not happen... */
1854 ret
= LTTNG_ERR_FATAL
;
1858 switch (event
->type
) {
1859 case LTTNG_EVENT_ALL
:
1861 char *filter_expression_a
= NULL
;
1862 struct lttng_filter_bytecode
*filter_a
= NULL
;
1865 * We need to duplicate filter_expression and filter,
1866 * because ownership is passed to first enable
1869 if (filter_expression
) {
1870 filter_expression_a
= strdup(filter_expression
);
1871 if (!filter_expression_a
) {
1872 ret
= LTTNG_ERR_FATAL
;
1877 filter_a
= zmalloc(sizeof(*filter_a
) + filter
->len
);
1879 free(filter_expression_a
);
1880 ret
= LTTNG_ERR_FATAL
;
1883 memcpy(filter_a
, filter
, sizeof(*filter_a
) + filter
->len
);
1885 event
->type
= LTTNG_EVENT_TRACEPOINT
; /* Hack */
1886 ret
= event_kernel_enable_event(kchan
, event
,
1887 filter_expression
, filter
);
1888 /* We have passed ownership */
1889 filter_expression
= NULL
;
1891 if (ret
!= LTTNG_OK
) {
1892 if (channel_created
) {
1893 /* Let's not leak a useless channel. */
1894 kernel_destroy_channel(kchan
);
1896 free(filter_expression_a
);
1900 event
->type
= LTTNG_EVENT_SYSCALL
; /* Hack */
1901 ret
= event_kernel_enable_event(kchan
, event
,
1902 filter_expression_a
, filter_a
);
1903 /* We have passed ownership */
1904 filter_expression_a
= NULL
;
1906 if (ret
!= LTTNG_OK
) {
1911 case LTTNG_EVENT_PROBE
:
1912 case LTTNG_EVENT_FUNCTION
:
1913 case LTTNG_EVENT_FUNCTION_ENTRY
:
1914 case LTTNG_EVENT_TRACEPOINT
:
1915 ret
= event_kernel_enable_event(kchan
, event
,
1916 filter_expression
, filter
);
1917 /* We have passed ownership */
1918 filter_expression
= NULL
;
1920 if (ret
!= LTTNG_OK
) {
1921 if (channel_created
) {
1922 /* Let's not leak a useless channel. */
1923 kernel_destroy_channel(kchan
);
1928 case LTTNG_EVENT_SYSCALL
:
1929 ret
= event_kernel_enable_event(kchan
, event
,
1930 filter_expression
, filter
);
1931 /* We have passed ownership */
1932 filter_expression
= NULL
;
1934 if (ret
!= LTTNG_OK
) {
1939 ret
= LTTNG_ERR_UNK
;
1943 kernel_wait_quiescent(kernel_tracer_fd
);
1946 case LTTNG_DOMAIN_UST
:
1948 struct ltt_ust_channel
*uchan
;
1949 struct ltt_ust_session
*usess
= session
->ust_session
;
1954 * If a non-default channel has been created in the
1955 * session, explicitely require that -c chan_name needs
1958 if (usess
->has_non_default_channel
&& channel_name
[0] == '\0') {
1959 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
1963 /* Get channel from global UST domain */
1964 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
1966 if (uchan
== NULL
) {
1967 /* Create default channel */
1968 attr
= channel_new_default_attr(LTTNG_DOMAIN_UST
,
1969 usess
->buffer_type
);
1971 ret
= LTTNG_ERR_FATAL
;
1974 strncpy(attr
->name
, channel_name
, sizeof(attr
->name
));
1976 ret
= cmd_enable_channel(session
, domain
, attr
, wpipe
);
1977 if (ret
!= LTTNG_OK
) {
1983 /* Get the newly created channel reference back */
1984 uchan
= trace_ust_find_channel_by_name(
1985 usess
->domain_global
.channels
, channel_name
);
1989 if (uchan
->domain
!= LTTNG_DOMAIN_UST
&& !internal_event
) {
1991 * Don't allow users to add UST events to channels which
1992 * are assigned to a userspace subdomain (JUL, Log4J,
1995 ret
= LTTNG_ERR_INVALID_CHANNEL_DOMAIN
;
1999 if (!internal_event
) {
2001 * Ensure the event name is not reserved for internal
2004 ret
= validate_ust_event_name(event
->name
);
2006 WARN("Userspace event name %s failed validation.",
2008 event
->name
: "NULL");
2009 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
2014 /* At this point, the session and channel exist on the tracer */
2015 ret
= event_ust_enable_tracepoint(usess
, uchan
, event
,
2016 filter_expression
, filter
, exclusion
,
2018 /* We have passed ownership */
2019 filter_expression
= NULL
;
2022 if (ret
== LTTNG_ERR_UST_EVENT_ENABLED
) {
2023 goto already_enabled
;
2024 } else if (ret
!= LTTNG_OK
) {
2029 case LTTNG_DOMAIN_LOG4J
:
2030 case LTTNG_DOMAIN_JUL
:
2031 case LTTNG_DOMAIN_PYTHON
:
2033 const char *default_event_name
, *default_chan_name
;
2035 struct lttng_event uevent
;
2036 struct lttng_domain tmp_dom
;
2037 struct ltt_ust_session
*usess
= session
->ust_session
;
2041 agt
= trace_ust_find_agent(usess
, domain
->type
);
2043 agt
= agent_create(domain
->type
);
2045 ret
= LTTNG_ERR_NOMEM
;
2048 agent_add(agt
, usess
->agents
);
2051 /* Create the default tracepoint. */
2052 memset(&uevent
, 0, sizeof(uevent
));
2053 uevent
.type
= LTTNG_EVENT_TRACEPOINT
;
2054 uevent
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
2055 default_event_name
= event_get_default_agent_ust_name(
2057 if (!default_event_name
) {
2058 ret
= LTTNG_ERR_FATAL
;
2061 strncpy(uevent
.name
, default_event_name
, sizeof(uevent
.name
));
2062 uevent
.name
[sizeof(uevent
.name
) - 1] = '\0';
2065 * The domain type is changed because we are about to enable the
2066 * default channel and event for the JUL domain that are hardcoded.
2067 * This happens in the UST domain.
2069 memcpy(&tmp_dom
, domain
, sizeof(tmp_dom
));
2070 tmp_dom
.type
= LTTNG_DOMAIN_UST
;
2072 switch (domain
->type
) {
2073 case LTTNG_DOMAIN_LOG4J
:
2074 default_chan_name
= DEFAULT_LOG4J_CHANNEL_NAME
;
2076 case LTTNG_DOMAIN_JUL
:
2077 default_chan_name
= DEFAULT_JUL_CHANNEL_NAME
;
2079 case LTTNG_DOMAIN_PYTHON
:
2080 default_chan_name
= DEFAULT_PYTHON_CHANNEL_NAME
;
2083 /* The switch/case we are in makes this impossible */
2088 char *filter_expression_copy
= NULL
;
2089 struct lttng_filter_bytecode
*filter_copy
= NULL
;
2092 const size_t filter_size
= sizeof(
2093 struct lttng_filter_bytecode
)
2096 filter_copy
= zmalloc(filter_size
);
2098 ret
= LTTNG_ERR_NOMEM
;
2101 memcpy(filter_copy
, filter
, filter_size
);
2103 filter_expression_copy
=
2104 strdup(filter_expression
);
2105 if (!filter_expression
) {
2106 ret
= LTTNG_ERR_NOMEM
;
2109 if (!filter_expression_copy
|| !filter_copy
) {
2110 free(filter_expression_copy
);
2116 ret
= cmd_enable_event_internal(session
, &tmp_dom
,
2117 (char *) default_chan_name
,
2118 &uevent
, filter_expression_copy
,
2119 filter_copy
, NULL
, wpipe
);
2122 if (ret
== LTTNG_ERR_UST_EVENT_ENABLED
) {
2123 goto already_enabled
;
2124 } else if (ret
!= LTTNG_OK
) {
2128 /* The wild card * means that everything should be enabled. */
2129 if (strncmp(event
->name
, "*", 1) == 0 && strlen(event
->name
) == 1) {
2130 ret
= event_agent_enable_all(usess
, agt
, event
, filter
,
2133 ret
= event_agent_enable(usess
, agt
, event
, filter
,
2137 filter_expression
= NULL
;
2138 if (ret
!= LTTNG_OK
) {
2145 ret
= LTTNG_ERR_UND
;
2153 free(filter_expression
);
2161 * Command LTTNG_ENABLE_EVENT processed by the client thread.
2162 * We own filter, exclusion, and filter_expression.
2164 int cmd_enable_event(struct ltt_session
*session
, struct lttng_domain
*domain
,
2165 char *channel_name
, struct lttng_event
*event
,
2166 char *filter_expression
,
2167 struct lttng_filter_bytecode
*filter
,
2168 struct lttng_event_exclusion
*exclusion
,
2171 return _cmd_enable_event(session
, domain
, channel_name
, event
,
2172 filter_expression
, filter
, exclusion
, wpipe
, false);
2176 * Enable an event which is internal to LTTng. An internal should
2177 * never be made visible to clients and are immune to checks such as
2180 static int cmd_enable_event_internal(struct ltt_session
*session
,
2181 struct lttng_domain
*domain
,
2182 char *channel_name
, struct lttng_event
*event
,
2183 char *filter_expression
,
2184 struct lttng_filter_bytecode
*filter
,
2185 struct lttng_event_exclusion
*exclusion
,
2188 return _cmd_enable_event(session
, domain
, channel_name
, event
,
2189 filter_expression
, filter
, exclusion
, wpipe
, true);
2193 * Command LTTNG_LIST_TRACEPOINTS processed by the client thread.
2195 ssize_t
cmd_list_tracepoints(enum lttng_domain_type domain
,
2196 struct lttng_event
**events
)
2199 ssize_t nb_events
= 0;
2202 case LTTNG_DOMAIN_KERNEL
:
2203 nb_events
= kernel_list_events(kernel_tracer_fd
, events
);
2204 if (nb_events
< 0) {
2205 ret
= LTTNG_ERR_KERN_LIST_FAIL
;
2209 case LTTNG_DOMAIN_UST
:
2210 nb_events
= ust_app_list_events(events
);
2211 if (nb_events
< 0) {
2212 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2216 case LTTNG_DOMAIN_LOG4J
:
2217 case LTTNG_DOMAIN_JUL
:
2218 case LTTNG_DOMAIN_PYTHON
:
2219 nb_events
= agent_list_events(events
, domain
);
2220 if (nb_events
< 0) {
2221 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2226 ret
= LTTNG_ERR_UND
;
2233 /* Return negative value to differentiate return code */
2238 * Command LTTNG_LIST_TRACEPOINT_FIELDS processed by the client thread.
2240 ssize_t
cmd_list_tracepoint_fields(enum lttng_domain_type domain
,
2241 struct lttng_event_field
**fields
)
2244 ssize_t nb_fields
= 0;
2247 case LTTNG_DOMAIN_UST
:
2248 nb_fields
= ust_app_list_event_fields(fields
);
2249 if (nb_fields
< 0) {
2250 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2254 case LTTNG_DOMAIN_KERNEL
:
2255 default: /* fall-through */
2256 ret
= LTTNG_ERR_UND
;
2263 /* Return negative value to differentiate return code */
2267 ssize_t
cmd_list_syscalls(struct lttng_event
**events
)
2269 return syscall_table_list(events
);
2273 * Command LTTNG_LIST_TRACKER_PIDS processed by the client thread.
2275 * Called with session lock held.
2277 ssize_t
cmd_list_tracker_pids(struct ltt_session
*session
,
2278 enum lttng_domain_type domain
, int32_t **pids
)
2281 ssize_t nr_pids
= 0;
2284 case LTTNG_DOMAIN_KERNEL
:
2286 struct ltt_kernel_session
*ksess
;
2288 ksess
= session
->kernel_session
;
2289 nr_pids
= kernel_list_tracker_pids(ksess
, pids
);
2291 ret
= LTTNG_ERR_KERN_LIST_FAIL
;
2296 case LTTNG_DOMAIN_UST
:
2298 struct ltt_ust_session
*usess
;
2300 usess
= session
->ust_session
;
2301 nr_pids
= trace_ust_list_tracker_pids(usess
, pids
);
2303 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2308 case LTTNG_DOMAIN_LOG4J
:
2309 case LTTNG_DOMAIN_JUL
:
2310 case LTTNG_DOMAIN_PYTHON
:
2312 ret
= LTTNG_ERR_UND
;
2319 /* Return negative value to differentiate return code */
2324 * Command LTTNG_START_TRACE processed by the client thread.
2326 * Called with session mutex held.
2328 int cmd_start_trace(struct ltt_session
*session
)
2331 unsigned long nb_chan
= 0;
2332 struct ltt_kernel_session
*ksession
;
2333 struct ltt_ust_session
*usess
;
2337 /* Ease our life a bit ;) */
2338 ksession
= session
->kernel_session
;
2339 usess
= session
->ust_session
;
2341 /* Is the session already started? */
2342 if (session
->active
) {
2343 ret
= LTTNG_ERR_TRACE_ALREADY_STARTED
;
2348 * Starting a session without channel is useless since after that it's not
2349 * possible to enable channel thus inform the client.
2351 if (usess
&& usess
->domain_global
.channels
) {
2352 nb_chan
+= lttng_ht_get_count(usess
->domain_global
.channels
);
2355 nb_chan
+= ksession
->channel_count
;
2358 ret
= LTTNG_ERR_NO_CHANNEL
;
2362 /* Kernel tracing */
2363 if (ksession
!= NULL
) {
2364 ret
= start_kernel_session(ksession
, kernel_tracer_fd
);
2365 if (ret
!= LTTNG_OK
) {
2370 /* Flag session that trace should start automatically */
2373 * Even though the start trace might fail, flag this session active so
2374 * other application coming in are started by default.
2378 ret
= ust_app_start_trace_all(usess
);
2380 ret
= LTTNG_ERR_UST_START_FAIL
;
2385 /* Flag this after a successful start. */
2386 session
->has_been_started
= 1;
2387 session
->active
= 1;
2396 * Command LTTNG_STOP_TRACE processed by the client thread.
2398 int cmd_stop_trace(struct ltt_session
*session
)
2401 struct ltt_kernel_channel
*kchan
;
2402 struct ltt_kernel_session
*ksession
;
2403 struct ltt_ust_session
*usess
;
2408 ksession
= session
->kernel_session
;
2409 usess
= session
->ust_session
;
2411 /* Session is not active. Skip everythong and inform the client. */
2412 if (!session
->active
) {
2413 ret
= LTTNG_ERR_TRACE_ALREADY_STOPPED
;
2418 if (ksession
&& ksession
->active
) {
2419 DBG("Stop kernel tracing");
2421 /* Flush metadata if exist */
2422 if (ksession
->metadata_stream_fd
>= 0) {
2423 ret
= kernel_metadata_flush_buffer(ksession
->metadata_stream_fd
);
2425 ERR("Kernel metadata flush failed");
2429 /* Flush all buffers before stopping */
2430 cds_list_for_each_entry(kchan
, &ksession
->channel_list
.head
, list
) {
2431 ret
= kernel_flush_buffer(kchan
);
2433 ERR("Kernel flush buffer error");
2437 ret
= kernel_stop_session(ksession
);
2439 ret
= LTTNG_ERR_KERN_STOP_FAIL
;
2443 kernel_wait_quiescent(kernel_tracer_fd
);
2445 ksession
->active
= 0;
2448 if (usess
&& usess
->active
) {
2450 * Even though the stop trace might fail, flag this session inactive so
2451 * other application coming in are not started by default.
2455 ret
= ust_app_stop_trace_all(usess
);
2457 ret
= LTTNG_ERR_UST_STOP_FAIL
;
2462 /* Flag inactive after a successful stop. */
2463 session
->active
= 0;
2471 * Command LTTNG_SET_CONSUMER_URI processed by the client thread.
2473 int cmd_set_consumer_uri(struct ltt_session
*session
, size_t nb_uri
,
2474 struct lttng_uri
*uris
)
2477 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
2478 struct ltt_ust_session
*usess
= session
->ust_session
;
2484 /* Can't set consumer URI if the session is active. */
2485 if (session
->active
) {
2486 ret
= LTTNG_ERR_TRACE_ALREADY_STARTED
;
2490 /* Set the "global" consumer URIs */
2491 for (i
= 0; i
< nb_uri
; i
++) {
2492 ret
= add_uri_to_consumer(session
->consumer
,
2493 &uris
[i
], 0, session
->name
);
2494 if (ret
!= LTTNG_OK
) {
2499 /* Set UST session URIs */
2500 if (session
->ust_session
) {
2501 for (i
= 0; i
< nb_uri
; i
++) {
2502 ret
= add_uri_to_consumer(
2503 session
->ust_session
->consumer
,
2504 &uris
[i
], LTTNG_DOMAIN_UST
,
2506 if (ret
!= LTTNG_OK
) {
2512 /* Set kernel session URIs */
2513 if (session
->kernel_session
) {
2514 for (i
= 0; i
< nb_uri
; i
++) {
2515 ret
= add_uri_to_consumer(
2516 session
->kernel_session
->consumer
,
2517 &uris
[i
], LTTNG_DOMAIN_KERNEL
,
2519 if (ret
!= LTTNG_OK
) {
2526 * Make sure to set the session in output mode after we set URI since a
2527 * session can be created without URL (thus flagged in no output mode).
2529 session
->output_traces
= 1;
2531 ksess
->output_traces
= 1;
2535 usess
->output_traces
= 1;
2546 * Command LTTNG_CREATE_SESSION processed by the client thread.
2548 int cmd_create_session_uri(char *name
, struct lttng_uri
*uris
,
2549 size_t nb_uri
, lttng_sock_cred
*creds
, unsigned int live_timer
)
2552 struct ltt_session
*session
;
2558 * Verify if the session already exist
2560 * XXX: There is no need for the session lock list here since the caller
2561 * (process_client_msg) is holding it. We might want to change that so a
2562 * single command does not lock the entire session list.
2564 session
= session_find_by_name(name
);
2565 if (session
!= NULL
) {
2566 ret
= LTTNG_ERR_EXIST_SESS
;
2570 /* Create tracing session in the registry */
2571 ret
= session_create(name
, LTTNG_SOCK_GET_UID_CRED(creds
),
2572 LTTNG_SOCK_GET_GID_CRED(creds
));
2573 if (ret
!= LTTNG_OK
) {
2578 * Get the newly created session pointer back
2580 * XXX: There is no need for the session lock list here since the caller
2581 * (process_client_msg) is holding it. We might want to change that so a
2582 * single command does not lock the entire session list.
2584 session
= session_find_by_name(name
);
2587 session
->live_timer
= live_timer
;
2588 /* Create default consumer output for the session not yet created. */
2589 session
->consumer
= consumer_create_output(CONSUMER_DST_LOCAL
);
2590 if (session
->consumer
== NULL
) {
2591 ret
= LTTNG_ERR_FATAL
;
2592 goto consumer_error
;
2596 ret
= cmd_set_consumer_uri(session
, nb_uri
, uris
);
2597 if (ret
!= LTTNG_OK
) {
2598 goto consumer_error
;
2600 session
->output_traces
= 1;
2602 session
->output_traces
= 0;
2603 DBG2("Session %s created with no output", session
->name
);
2606 session
->consumer
->enabled
= 1;
2611 session_destroy(session
);
2618 * Command LTTNG_CREATE_SESSION_SNAPSHOT processed by the client thread.
2620 int cmd_create_session_snapshot(char *name
, struct lttng_uri
*uris
,
2621 size_t nb_uri
, lttng_sock_cred
*creds
)
2624 struct ltt_session
*session
;
2625 struct snapshot_output
*new_output
= NULL
;
2631 * Create session in no output mode with URIs set to NULL. The uris we've
2632 * received are for a default snapshot output if one.
2634 ret
= cmd_create_session_uri(name
, NULL
, 0, creds
, 0);
2635 if (ret
!= LTTNG_OK
) {
2639 /* Get the newly created session pointer back. This should NEVER fail. */
2640 session
= session_find_by_name(name
);
2643 /* Flag session for snapshot mode. */
2644 session
->snapshot_mode
= 1;
2646 /* Skip snapshot output creation if no URI is given. */
2651 new_output
= snapshot_output_alloc();
2653 ret
= LTTNG_ERR_NOMEM
;
2654 goto error_snapshot_alloc
;
2657 ret
= snapshot_output_init_with_uri(DEFAULT_SNAPSHOT_MAX_SIZE
, NULL
,
2658 uris
, nb_uri
, session
->consumer
, new_output
, &session
->snapshot
);
2660 if (ret
== -ENOMEM
) {
2661 ret
= LTTNG_ERR_NOMEM
;
2663 ret
= LTTNG_ERR_INVALID
;
2665 goto error_snapshot
;
2669 snapshot_add_output(&session
->snapshot
, new_output
);
2676 snapshot_output_destroy(new_output
);
2677 error_snapshot_alloc
:
2678 session_destroy(session
);
2684 * Command LTTNG_DESTROY_SESSION processed by the client thread.
2686 * Called with session lock held.
2688 int cmd_destroy_session(struct ltt_session
*session
, int wpipe
)
2691 struct ltt_ust_session
*usess
;
2692 struct ltt_kernel_session
*ksess
;
2697 usess
= session
->ust_session
;
2698 ksess
= session
->kernel_session
;
2700 /* Clean kernel session teardown */
2701 kernel_destroy_session(ksess
);
2703 /* UST session teardown */
2705 /* Close any relayd session */
2706 consumer_output_send_destroy_relayd(usess
->consumer
);
2708 /* Destroy every UST application related to this session. */
2709 ret
= ust_app_destroy_trace_all(usess
);
2711 ERR("Error in ust_app_destroy_trace_all");
2714 /* Clean up the rest. */
2715 trace_ust_destroy_session(usess
);
2719 * Must notify the kernel thread here to update it's poll set in order to
2720 * remove the channel(s)' fd just destroyed.
2722 ret
= notify_thread_pipe(wpipe
);
2724 PERROR("write kernel poll pipe");
2727 ret
= session_destroy(session
);
2733 * Command LTTNG_CALIBRATE processed by the client thread.
2735 int cmd_calibrate(enum lttng_domain_type domain
,
2736 struct lttng_calibrate
*calibrate
)
2741 case LTTNG_DOMAIN_KERNEL
:
2743 struct lttng_kernel_calibrate kcalibrate
;
2745 switch (calibrate
->type
) {
2746 case LTTNG_CALIBRATE_FUNCTION
:
2748 /* Default and only possible calibrate option. */
2749 kcalibrate
.type
= LTTNG_KERNEL_CALIBRATE_KRETPROBE
;
2753 ret
= kernel_calibrate(kernel_tracer_fd
, &kcalibrate
);
2755 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2760 case LTTNG_DOMAIN_UST
:
2762 struct lttng_ust_calibrate ucalibrate
;
2764 switch (calibrate
->type
) {
2765 case LTTNG_CALIBRATE_FUNCTION
:
2767 /* Default and only possible calibrate option. */
2768 ucalibrate
.type
= LTTNG_UST_CALIBRATE_TRACEPOINT
;
2772 ret
= ust_app_calibrate_glb(&ucalibrate
);
2774 ret
= LTTNG_ERR_UST_CALIBRATE_FAIL
;
2780 ret
= LTTNG_ERR_UND
;
2791 * Command LTTNG_REGISTER_CONSUMER processed by the client thread.
2793 int cmd_register_consumer(struct ltt_session
*session
,
2794 enum lttng_domain_type domain
, const char *sock_path
,
2795 struct consumer_data
*cdata
)
2798 struct consumer_socket
*socket
= NULL
;
2805 case LTTNG_DOMAIN_KERNEL
:
2807 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
2811 /* Can't register a consumer if there is already one */
2812 if (ksess
->consumer_fds_sent
!= 0) {
2813 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
2817 sock
= lttcomm_connect_unix_sock(sock_path
);
2819 ret
= LTTNG_ERR_CONNECT_FAIL
;
2822 cdata
->cmd_sock
= sock
;
2824 socket
= consumer_allocate_socket(&cdata
->cmd_sock
);
2825 if (socket
== NULL
) {
2828 PERROR("close register consumer");
2830 cdata
->cmd_sock
= -1;
2831 ret
= LTTNG_ERR_FATAL
;
2835 socket
->lock
= zmalloc(sizeof(pthread_mutex_t
));
2836 if (socket
->lock
== NULL
) {
2837 PERROR("zmalloc pthread mutex");
2838 ret
= LTTNG_ERR_FATAL
;
2841 pthread_mutex_init(socket
->lock
, NULL
);
2842 socket
->registered
= 1;
2845 consumer_add_socket(socket
, ksess
->consumer
);
2848 pthread_mutex_lock(&cdata
->pid_mutex
);
2850 pthread_mutex_unlock(&cdata
->pid_mutex
);
2855 /* TODO: Userspace tracing */
2856 ret
= LTTNG_ERR_UND
;
2864 consumer_destroy_socket(socket
);
2870 * Command LTTNG_LIST_DOMAINS processed by the client thread.
2872 ssize_t
cmd_list_domains(struct ltt_session
*session
,
2873 struct lttng_domain
**domains
)
2878 struct lttng_ht_iter iter
;
2880 if (session
->kernel_session
!= NULL
) {
2881 DBG3("Listing domains found kernel domain");
2885 if (session
->ust_session
!= NULL
) {
2886 DBG3("Listing domains found UST global domain");
2890 cds_lfht_for_each_entry(session
->ust_session
->agents
->ht
, &iter
.iter
,
2892 if (agt
->being_used
) {
2903 *domains
= zmalloc(nb_dom
* sizeof(struct lttng_domain
));
2904 if (*domains
== NULL
) {
2905 ret
= LTTNG_ERR_FATAL
;
2909 if (session
->kernel_session
!= NULL
) {
2910 (*domains
)[index
].type
= LTTNG_DOMAIN_KERNEL
;
2912 /* Kernel session buffer type is always GLOBAL */
2913 (*domains
)[index
].buf_type
= LTTNG_BUFFER_GLOBAL
;
2918 if (session
->ust_session
!= NULL
) {
2919 (*domains
)[index
].type
= LTTNG_DOMAIN_UST
;
2920 (*domains
)[index
].buf_type
= session
->ust_session
->buffer_type
;
2924 cds_lfht_for_each_entry(session
->ust_session
->agents
->ht
, &iter
.iter
,
2926 if (agt
->being_used
) {
2927 (*domains
)[index
].type
= agt
->domain
;
2928 (*domains
)[index
].buf_type
= session
->ust_session
->buffer_type
;
2938 /* Return negative value to differentiate return code */
2944 * Command LTTNG_LIST_CHANNELS processed by the client thread.
2946 ssize_t
cmd_list_channels(enum lttng_domain_type domain
,
2947 struct ltt_session
*session
, struct lttng_channel
**channels
)
2949 ssize_t nb_chan
= 0, payload_size
= 0, ret
;
2952 case LTTNG_DOMAIN_KERNEL
:
2953 if (session
->kernel_session
!= NULL
) {
2954 nb_chan
= session
->kernel_session
->channel_count
;
2956 DBG3("Number of kernel channels %zd", nb_chan
);
2958 ret
= -LTTNG_ERR_KERN_CHAN_NOT_FOUND
;
2962 case LTTNG_DOMAIN_UST
:
2963 if (session
->ust_session
!= NULL
) {
2965 nb_chan
= lttng_ht_get_count(
2966 session
->ust_session
->domain_global
.channels
);
2969 DBG3("Number of UST global channels %zd", nb_chan
);
2971 ret
= -LTTNG_ERR_UST_CHAN_NOT_FOUND
;
2976 ret
= -LTTNG_ERR_UND
;
2981 const size_t channel_size
= sizeof(struct lttng_channel
) +
2982 sizeof(struct lttcomm_channel_extended
);
2983 struct lttcomm_channel_extended
*channel_exts
;
2985 payload_size
= nb_chan
* channel_size
;
2986 *channels
= zmalloc(payload_size
);
2987 if (*channels
== NULL
) {
2988 ret
= -LTTNG_ERR_FATAL
;
2992 channel_exts
= ((void *) *channels
) +
2993 (nb_chan
* sizeof(struct lttng_channel
));
2994 list_lttng_channels(domain
, session
, *channels
, channel_exts
);
3005 * Command LTTNG_LIST_EVENTS processed by the client thread.
3007 ssize_t
cmd_list_events(enum lttng_domain_type domain
,
3008 struct ltt_session
*session
, char *channel_name
,
3009 struct lttng_event
**events
, size_t *total_size
)
3012 ssize_t nb_event
= 0;
3015 case LTTNG_DOMAIN_KERNEL
:
3016 if (session
->kernel_session
!= NULL
) {
3017 nb_event
= list_lttng_kernel_events(channel_name
,
3018 session
->kernel_session
, events
,
3022 case LTTNG_DOMAIN_UST
:
3024 if (session
->ust_session
!= NULL
) {
3025 nb_event
= list_lttng_ust_global_events(channel_name
,
3026 &session
->ust_session
->domain_global
, events
,
3031 case LTTNG_DOMAIN_LOG4J
:
3032 case LTTNG_DOMAIN_JUL
:
3033 case LTTNG_DOMAIN_PYTHON
:
3034 if (session
->ust_session
) {
3035 struct lttng_ht_iter iter
;
3039 cds_lfht_for_each_entry(session
->ust_session
->agents
->ht
,
3040 &iter
.iter
, agt
, node
.node
) {
3041 if (agt
->domain
== domain
) {
3042 nb_event
= list_lttng_agent_events(
3052 ret
= LTTNG_ERR_UND
;
3059 /* Return negative value to differentiate return code */
3064 * Using the session list, filled a lttng_session array to send back to the
3065 * client for session listing.
3067 * The session list lock MUST be acquired before calling this function. Use
3068 * session_lock_list() and session_unlock_list().
3070 void cmd_list_lttng_sessions(struct lttng_session
*sessions
, uid_t uid
,
3075 struct ltt_session
*session
;
3076 struct ltt_session_list
*list
= session_get_list();
3078 DBG("Getting all available session for UID %d GID %d",
3081 * Iterate over session list and append data after the control struct in
3084 cds_list_for_each_entry(session
, &list
->head
, list
) {
3086 * Only list the sessions the user can control.
3088 if (!session_access_ok(session
, uid
, gid
)) {
3092 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3093 struct ltt_ust_session
*usess
= session
->ust_session
;
3095 if (session
->consumer
->type
== CONSUMER_DST_NET
||
3096 (ksess
&& ksess
->consumer
->type
== CONSUMER_DST_NET
) ||
3097 (usess
&& usess
->consumer
->type
== CONSUMER_DST_NET
)) {
3098 ret
= build_network_session_path(sessions
[i
].path
,
3099 sizeof(sessions
[i
].path
), session
);
3101 ret
= snprintf(sessions
[i
].path
, sizeof(sessions
[i
].path
), "%s",
3102 session
->consumer
->dst
.trace_path
);
3105 PERROR("snprintf session path");
3109 strncpy(sessions
[i
].name
, session
->name
, NAME_MAX
);
3110 sessions
[i
].name
[NAME_MAX
- 1] = '\0';
3111 sessions
[i
].enabled
= session
->active
;
3112 sessions
[i
].snapshot_mode
= session
->snapshot_mode
;
3113 sessions
[i
].live_timer_interval
= session
->live_timer
;
3119 * Command LTTNG_DATA_PENDING returning 0 if the data is NOT pending meaning
3120 * ready for trace analysis (or any kind of reader) or else 1 for pending data.
3122 int cmd_data_pending(struct ltt_session
*session
)
3125 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3126 struct ltt_ust_session
*usess
= session
->ust_session
;
3130 /* Session MUST be stopped to ask for data availability. */
3131 if (session
->active
) {
3132 ret
= LTTNG_ERR_SESSION_STARTED
;
3136 * If stopped, just make sure we've started before else the above call
3137 * will always send that there is data pending.
3139 * The consumer assumes that when the data pending command is received,
3140 * the trace has been started before or else no output data is written
3141 * by the streams which is a condition for data pending. So, this is
3142 * *VERY* important that we don't ask the consumer before a start
3145 if (!session
->has_been_started
) {
3151 if (ksess
&& ksess
->consumer
) {
3152 ret
= consumer_is_data_pending(ksess
->id
, ksess
->consumer
);
3154 /* Data is still being extracted for the kernel. */
3159 if (usess
&& usess
->consumer
) {
3160 ret
= consumer_is_data_pending(usess
->id
, usess
->consumer
);
3162 /* Data is still being extracted for the kernel. */
3167 /* Data is ready to be read by a viewer */
3175 * Command LTTNG_SNAPSHOT_ADD_OUTPUT from the lttng ctl library.
3177 * Return LTTNG_OK on success or else a LTTNG_ERR code.
3179 int cmd_snapshot_add_output(struct ltt_session
*session
,
3180 struct lttng_snapshot_output
*output
, uint32_t *id
)
3183 struct snapshot_output
*new_output
;
3188 DBG("Cmd snapshot add output for session %s", session
->name
);
3191 * Permission denied to create an output if the session is not
3192 * set in no output mode.
3194 if (session
->output_traces
) {
3195 ret
= LTTNG_ERR_EPERM
;
3199 /* Only one output is allowed until we have the "tee" feature. */
3200 if (session
->snapshot
.nb_output
== 1) {
3201 ret
= LTTNG_ERR_SNAPSHOT_OUTPUT_EXIST
;
3205 new_output
= snapshot_output_alloc();
3207 ret
= LTTNG_ERR_NOMEM
;
3211 ret
= snapshot_output_init(output
->max_size
, output
->name
,
3212 output
->ctrl_url
, output
->data_url
, session
->consumer
, new_output
,
3213 &session
->snapshot
);
3215 if (ret
== -ENOMEM
) {
3216 ret
= LTTNG_ERR_NOMEM
;
3218 ret
= LTTNG_ERR_INVALID
;
3224 snapshot_add_output(&session
->snapshot
, new_output
);
3226 *id
= new_output
->id
;
3233 snapshot_output_destroy(new_output
);
3239 * Command LTTNG_SNAPSHOT_DEL_OUTPUT from lib lttng ctl.
3241 * Return LTTNG_OK on success or else a LTTNG_ERR code.
3243 int cmd_snapshot_del_output(struct ltt_session
*session
,
3244 struct lttng_snapshot_output
*output
)
3247 struct snapshot_output
*sout
= NULL
;
3255 * Permission denied to create an output if the session is not
3256 * set in no output mode.
3258 if (session
->output_traces
) {
3259 ret
= LTTNG_ERR_EPERM
;
3264 DBG("Cmd snapshot del output id %" PRIu32
" for session %s", output
->id
,
3266 sout
= snapshot_find_output_by_id(output
->id
, &session
->snapshot
);
3267 } else if (*output
->name
!= '\0') {
3268 DBG("Cmd snapshot del output name %s for session %s", output
->name
,
3270 sout
= snapshot_find_output_by_name(output
->name
, &session
->snapshot
);
3273 ret
= LTTNG_ERR_INVALID
;
3277 snapshot_delete_output(&session
->snapshot
, sout
);
3278 snapshot_output_destroy(sout
);
3287 * Command LTTNG_SNAPSHOT_LIST_OUTPUT from lib lttng ctl.
3289 * If no output is available, outputs is untouched and 0 is returned.
3291 * Return the size of the newly allocated outputs or a negative LTTNG_ERR code.
3293 ssize_t
cmd_snapshot_list_outputs(struct ltt_session
*session
,
3294 struct lttng_snapshot_output
**outputs
)
3297 struct lttng_snapshot_output
*list
= NULL
;
3298 struct lttng_ht_iter iter
;
3299 struct snapshot_output
*output
;
3304 DBG("Cmd snapshot list outputs for session %s", session
->name
);
3307 * Permission denied to create an output if the session is not
3308 * set in no output mode.
3310 if (session
->output_traces
) {
3311 ret
= -LTTNG_ERR_EPERM
;
3315 if (session
->snapshot
.nb_output
== 0) {
3320 list
= zmalloc(session
->snapshot
.nb_output
* sizeof(*list
));
3322 ret
= -LTTNG_ERR_NOMEM
;
3326 /* Copy list from session to the new list object. */
3328 cds_lfht_for_each_entry(session
->snapshot
.output_ht
->ht
, &iter
.iter
,
3329 output
, node
.node
) {
3330 assert(output
->consumer
);
3331 list
[idx
].id
= output
->id
;
3332 list
[idx
].max_size
= output
->max_size
;
3333 strncpy(list
[idx
].name
, output
->name
, sizeof(list
[idx
].name
));
3334 if (output
->consumer
->type
== CONSUMER_DST_LOCAL
) {
3335 strncpy(list
[idx
].ctrl_url
, output
->consumer
->dst
.trace_path
,
3336 sizeof(list
[idx
].ctrl_url
));
3339 ret
= uri_to_str_url(&output
->consumer
->dst
.net
.control
,
3340 list
[idx
].ctrl_url
, sizeof(list
[idx
].ctrl_url
));
3342 ret
= -LTTNG_ERR_NOMEM
;
3347 ret
= uri_to_str_url(&output
->consumer
->dst
.net
.data
,
3348 list
[idx
].data_url
, sizeof(list
[idx
].data_url
));
3350 ret
= -LTTNG_ERR_NOMEM
;
3359 ret
= session
->snapshot
.nb_output
;
3367 * Send relayd sockets from snapshot output to consumer. Ignore request if the
3368 * snapshot output is *not* set with a remote destination.
3370 * Return 0 on success or a LTTNG_ERR code.
3372 static int set_relayd_for_snapshot(struct consumer_output
*consumer
,
3373 struct snapshot_output
*snap_output
, struct ltt_session
*session
)
3376 struct lttng_ht_iter iter
;
3377 struct consumer_socket
*socket
;
3380 assert(snap_output
);
3383 DBG2("Set relayd object from snapshot output");
3385 /* Ignore if snapshot consumer output is not network. */
3386 if (snap_output
->consumer
->type
!= CONSUMER_DST_NET
) {
3391 * For each consumer socket, create and send the relayd object of the
3395 cds_lfht_for_each_entry(snap_output
->consumer
->socks
->ht
, &iter
.iter
,
3396 socket
, node
.node
) {
3397 ret
= send_consumer_relayd_sockets(0, session
->id
,
3398 snap_output
->consumer
, socket
,
3399 session
->name
, session
->hostname
,
3400 session
->live_timer
);
3401 if (ret
!= LTTNG_OK
) {
3413 * Record a kernel snapshot.
3415 * Return LTTNG_OK on success or a LTTNG_ERR code.
3417 static int record_kernel_snapshot(struct ltt_kernel_session
*ksess
,
3418 struct snapshot_output
*output
, struct ltt_session
*session
,
3419 int wait
, uint64_t nb_packets_per_stream
)
3427 /* Get the datetime for the snapshot output directory. */
3428 ret
= utils_get_current_time_str("%Y%m%d-%H%M%S", output
->datetime
,
3429 sizeof(output
->datetime
));
3431 ret
= LTTNG_ERR_INVALID
;
3436 * Copy kernel session sockets so we can communicate with the right
3437 * consumer for the snapshot record command.
3439 ret
= consumer_copy_sockets(output
->consumer
, ksess
->consumer
);
3441 ret
= LTTNG_ERR_NOMEM
;
3445 ret
= set_relayd_for_snapshot(ksess
->consumer
, output
, session
);
3446 if (ret
!= LTTNG_OK
) {
3447 goto error_snapshot
;
3450 ret
= kernel_snapshot_record(ksess
, output
, wait
, nb_packets_per_stream
);
3451 if (ret
!= LTTNG_OK
) {
3452 goto error_snapshot
;
3459 /* Clean up copied sockets so this output can use some other later on. */
3460 consumer_destroy_output_sockets(output
->consumer
);
3467 * Record a UST snapshot.
3469 * Return 0 on success or a LTTNG_ERR error code.
3471 static int record_ust_snapshot(struct ltt_ust_session
*usess
,
3472 struct snapshot_output
*output
, struct ltt_session
*session
,
3473 int wait
, uint64_t nb_packets_per_stream
)
3481 /* Get the datetime for the snapshot output directory. */
3482 ret
= utils_get_current_time_str("%Y%m%d-%H%M%S", output
->datetime
,
3483 sizeof(output
->datetime
));
3485 ret
= LTTNG_ERR_INVALID
;
3490 * Copy UST session sockets so we can communicate with the right
3491 * consumer for the snapshot record command.
3493 ret
= consumer_copy_sockets(output
->consumer
, usess
->consumer
);
3495 ret
= LTTNG_ERR_NOMEM
;
3499 ret
= set_relayd_for_snapshot(usess
->consumer
, output
, session
);
3500 if (ret
!= LTTNG_OK
) {
3501 goto error_snapshot
;
3504 ret
= ust_app_snapshot_record(usess
, output
, wait
, nb_packets_per_stream
);
3508 ret
= LTTNG_ERR_INVALID
;
3511 ret
= LTTNG_ERR_SNAPSHOT_NODATA
;
3514 ret
= LTTNG_ERR_SNAPSHOT_FAIL
;
3517 goto error_snapshot
;
3523 /* Clean up copied sockets so this output can use some other later on. */
3524 consumer_destroy_output_sockets(output
->consumer
);
3530 uint64_t get_session_size_one_more_packet_per_stream(struct ltt_session
*session
,
3531 uint64_t cur_nr_packets
)
3533 uint64_t tot_size
= 0;
3535 if (session
->kernel_session
) {
3536 struct ltt_kernel_channel
*chan
;
3537 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3539 cds_list_for_each_entry(chan
, &ksess
->channel_list
.head
, list
) {
3540 if (cur_nr_packets
>= chan
->channel
->attr
.num_subbuf
) {
3542 * Don't take channel into account if we
3543 * already grab all its packets.
3547 tot_size
+= chan
->channel
->attr
.subbuf_size
3548 * chan
->stream_count
;
3552 if (session
->ust_session
) {
3553 struct ltt_ust_session
*usess
= session
->ust_session
;
3555 tot_size
+= ust_app_get_size_one_more_packet_per_stream(usess
,
3563 * Calculate the number of packets we can grab from each stream that
3564 * fits within the overall snapshot max size.
3566 * Returns -1 on error, 0 means infinite number of packets, else > 0 is
3567 * the number of packets per stream.
3569 * TODO: this approach is not perfect: we consider the worse case
3570 * (packet filling the sub-buffers) as an upper bound, but we could do
3571 * better if we do this calculation while we actually grab the packet
3572 * content: we would know how much padding we don't actually store into
3575 * This algorithm is currently bounded by the number of packets per
3578 * Since we call this algorithm before actually grabbing the data, it's
3579 * an approximation: for instance, applications could appear/disappear
3580 * in between this call and actually grabbing data.
3583 int64_t get_session_nb_packets_per_stream(struct ltt_session
*session
, uint64_t max_size
)
3586 uint64_t cur_nb_packets
= 0;
3589 return 0; /* Infinite */
3592 size_left
= max_size
;
3594 uint64_t one_more_packet_tot_size
;
3596 one_more_packet_tot_size
= get_session_size_one_more_packet_per_stream(session
,
3598 if (!one_more_packet_tot_size
) {
3599 /* We are already grabbing all packets. */
3602 size_left
-= one_more_packet_tot_size
;
3603 if (size_left
< 0) {
3608 if (!cur_nb_packets
) {
3609 /* Not enough room to grab one packet of each stream, error. */
3612 return cur_nb_packets
;
3616 * Command LTTNG_SNAPSHOT_RECORD from lib lttng ctl.
3618 * The wait parameter is ignored so this call always wait for the snapshot to
3619 * complete before returning.
3621 * Return LTTNG_OK on success or else a LTTNG_ERR code.
3623 int cmd_snapshot_record(struct ltt_session
*session
,
3624 struct lttng_snapshot_output
*output
, int wait
)
3627 unsigned int use_tmp_output
= 0;
3628 struct snapshot_output tmp_output
;
3629 unsigned int snapshot_success
= 0;
3634 DBG("Cmd snapshot record for session %s", session
->name
);
3637 * Permission denied to create an output if the session is not
3638 * set in no output mode.
3640 if (session
->output_traces
) {
3641 ret
= LTTNG_ERR_EPERM
;
3645 /* The session needs to be started at least once. */
3646 if (!session
->has_been_started
) {
3647 ret
= LTTNG_ERR_START_SESSION_ONCE
;
3651 /* Use temporary output for the session. */
3652 if (*output
->ctrl_url
!= '\0') {
3653 ret
= snapshot_output_init(output
->max_size
, output
->name
,
3654 output
->ctrl_url
, output
->data_url
, session
->consumer
,
3657 if (ret
== -ENOMEM
) {
3658 ret
= LTTNG_ERR_NOMEM
;
3660 ret
= LTTNG_ERR_INVALID
;
3664 /* Use the global session count for the temporary snapshot. */
3665 tmp_output
.nb_snapshot
= session
->snapshot
.nb_snapshot
;
3669 if (session
->kernel_session
) {
3670 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3672 if (use_tmp_output
) {
3673 int64_t nb_packets_per_stream
;
3675 nb_packets_per_stream
= get_session_nb_packets_per_stream(session
,
3676 tmp_output
.max_size
);
3677 if (nb_packets_per_stream
< 0) {
3678 ret
= LTTNG_ERR_MAX_SIZE_INVALID
;
3681 ret
= record_kernel_snapshot(ksess
, &tmp_output
, session
,
3682 wait
, nb_packets_per_stream
);
3683 if (ret
!= LTTNG_OK
) {
3686 snapshot_success
= 1;
3688 struct snapshot_output
*sout
;
3689 struct lttng_ht_iter iter
;
3692 cds_lfht_for_each_entry(session
->snapshot
.output_ht
->ht
,
3693 &iter
.iter
, sout
, node
.node
) {
3694 int64_t nb_packets_per_stream
;
3697 * Make a local copy of the output and assign the possible
3698 * temporary value given by the caller.
3700 memset(&tmp_output
, 0, sizeof(tmp_output
));
3701 memcpy(&tmp_output
, sout
, sizeof(tmp_output
));
3703 if (output
->max_size
!= (uint64_t) -1ULL) {
3704 tmp_output
.max_size
= output
->max_size
;
3707 nb_packets_per_stream
= get_session_nb_packets_per_stream(session
,
3708 tmp_output
.max_size
);
3709 if (nb_packets_per_stream
< 0) {
3710 ret
= LTTNG_ERR_MAX_SIZE_INVALID
;
3714 /* Use temporary name. */
3715 if (*output
->name
!= '\0') {
3716 strncpy(tmp_output
.name
, output
->name
,
3717 sizeof(tmp_output
.name
));
3720 tmp_output
.nb_snapshot
= session
->snapshot
.nb_snapshot
;
3722 ret
= record_kernel_snapshot(ksess
, &tmp_output
,
3723 session
, wait
, nb_packets_per_stream
);
3724 if (ret
!= LTTNG_OK
) {
3728 snapshot_success
= 1;
3734 if (session
->ust_session
) {
3735 struct ltt_ust_session
*usess
= session
->ust_session
;
3737 if (use_tmp_output
) {
3738 int64_t nb_packets_per_stream
;
3740 nb_packets_per_stream
= get_session_nb_packets_per_stream(session
,
3741 tmp_output
.max_size
);
3742 if (nb_packets_per_stream
< 0) {
3743 ret
= LTTNG_ERR_MAX_SIZE_INVALID
;
3746 ret
= record_ust_snapshot(usess
, &tmp_output
, session
,
3747 wait
, nb_packets_per_stream
);
3748 if (ret
!= LTTNG_OK
) {
3751 snapshot_success
= 1;
3753 struct snapshot_output
*sout
;
3754 struct lttng_ht_iter iter
;
3757 cds_lfht_for_each_entry(session
->snapshot
.output_ht
->ht
,
3758 &iter
.iter
, sout
, node
.node
) {
3759 int64_t nb_packets_per_stream
;
3762 * Make a local copy of the output and assign the possible
3763 * temporary value given by the caller.
3765 memset(&tmp_output
, 0, sizeof(tmp_output
));
3766 memcpy(&tmp_output
, sout
, sizeof(tmp_output
));
3768 if (output
->max_size
!= (uint64_t) -1ULL) {
3769 tmp_output
.max_size
= output
->max_size
;
3772 nb_packets_per_stream
= get_session_nb_packets_per_stream(session
,
3773 tmp_output
.max_size
);
3774 if (nb_packets_per_stream
< 0) {
3775 ret
= LTTNG_ERR_MAX_SIZE_INVALID
;
3780 /* Use temporary name. */
3781 if (*output
->name
!= '\0') {
3782 strncpy(tmp_output
.name
, output
->name
,
3783 sizeof(tmp_output
.name
));
3786 tmp_output
.nb_snapshot
= session
->snapshot
.nb_snapshot
;
3788 ret
= record_ust_snapshot(usess
, &tmp_output
, session
,
3789 wait
, nb_packets_per_stream
);
3790 if (ret
!= LTTNG_OK
) {
3794 snapshot_success
= 1;
3800 if (snapshot_success
) {
3801 session
->snapshot
.nb_snapshot
++;
3803 ret
= LTTNG_ERR_SNAPSHOT_FAIL
;
3811 * Command LTTNG_SET_SESSION_SHM_PATH processed by the client thread.
3813 int cmd_set_session_shm_path(struct ltt_session
*session
,
3814 const char *shm_path
)
3820 * Can only set shm path before session is started.
3822 if (session
->has_been_started
) {
3823 return LTTNG_ERR_SESSION_STARTED
;
3826 strncpy(session
->shm_path
, shm_path
,
3827 sizeof(session
->shm_path
));
3828 session
->shm_path
[sizeof(session
->shm_path
) - 1] = '\0';
3834 * Init command subsystem.
3839 * Set network sequence index to 1 for streams to match a relayd
3840 * socket on the consumer side.
3842 pthread_mutex_lock(&relayd_net_seq_idx_lock
);
3843 relayd_net_seq_idx
= 1;
3844 pthread_mutex_unlock(&relayd_net_seq_idx_lock
);
3846 DBG("Command subsystem initialized");