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 * Fill lttng_channel array of all channels.
145 static void list_lttng_channels(enum lttng_domain_type domain
,
146 struct ltt_session
*session
, struct lttng_channel
*channels
)
149 struct ltt_kernel_channel
*kchan
;
151 DBG("Listing channels for session %s", session
->name
);
154 case LTTNG_DOMAIN_KERNEL
:
155 /* Kernel channels */
156 if (session
->kernel_session
!= NULL
) {
157 cds_list_for_each_entry(kchan
,
158 &session
->kernel_session
->channel_list
.head
, list
) {
159 /* Copy lttng_channel struct to array */
160 memcpy(&channels
[i
], kchan
->channel
, sizeof(struct lttng_channel
));
161 channels
[i
].enabled
= kchan
->enabled
;
166 case LTTNG_DOMAIN_UST
:
168 struct lttng_ht_iter iter
;
169 struct ltt_ust_channel
*uchan
;
172 cds_lfht_for_each_entry(session
->ust_session
->domain_global
.channels
->ht
,
173 &iter
.iter
, uchan
, node
.node
) {
174 strncpy(channels
[i
].name
, uchan
->name
, LTTNG_SYMBOL_NAME_LEN
);
175 channels
[i
].attr
.overwrite
= uchan
->attr
.overwrite
;
176 channels
[i
].attr
.subbuf_size
= uchan
->attr
.subbuf_size
;
177 channels
[i
].attr
.num_subbuf
= uchan
->attr
.num_subbuf
;
178 channels
[i
].attr
.switch_timer_interval
=
179 uchan
->attr
.switch_timer_interval
;
180 channels
[i
].attr
.read_timer_interval
=
181 uchan
->attr
.read_timer_interval
;
182 channels
[i
].enabled
= uchan
->enabled
;
183 channels
[i
].attr
.tracefile_size
= uchan
->tracefile_size
;
184 channels
[i
].attr
.tracefile_count
= uchan
->tracefile_count
;
185 switch (uchan
->attr
.output
) {
188 channels
[i
].attr
.output
= LTTNG_EVENT_MMAP
;
201 static void increment_extended_len(const char *filter_expression
,
202 struct lttng_event_exclusion
*exclusion
, size_t *extended_len
)
204 *extended_len
+= sizeof(struct lttcomm_event_extended_header
);
206 if (filter_expression
) {
207 *extended_len
+= strlen(filter_expression
) + 1;
211 *extended_len
+= exclusion
->count
* LTTNG_SYMBOL_NAME_LEN
;
215 static void append_extended_info(const char *filter_expression
,
216 struct lttng_event_exclusion
*exclusion
, void **extended_at
)
218 struct lttcomm_event_extended_header extended_header
;
219 size_t filter_len
= 0;
220 size_t nb_exclusions
= 0;
222 if (filter_expression
) {
223 filter_len
= strlen(filter_expression
) + 1;
227 nb_exclusions
= exclusion
->count
;
230 /* Set header fields */
231 extended_header
.filter_len
= filter_len
;
232 extended_header
.nb_exclusions
= nb_exclusions
;
235 memcpy(*extended_at
, &extended_header
, sizeof(extended_header
));
236 *extended_at
+= sizeof(extended_header
);
238 /* Copy filter string */
239 if (filter_expression
) {
240 memcpy(*extended_at
, filter_expression
, filter_len
);
241 *extended_at
+= filter_len
;
244 /* Copy exclusion names */
246 size_t len
= nb_exclusions
* LTTNG_SYMBOL_NAME_LEN
;
248 memcpy(*extended_at
, &exclusion
->names
, len
);
254 * Create a list of agent domain events.
256 * Return number of events in list on success or else a negative value.
258 static int list_lttng_agent_events(struct agent
*agt
,
259 struct lttng_event
**events
, size_t *total_size
)
262 unsigned int nb_event
= 0;
263 struct agent_event
*event
;
264 struct lttng_event
*tmp_events
;
265 struct lttng_ht_iter iter
;
266 size_t extended_len
= 0;
272 DBG3("Listing agent events");
275 nb_event
= lttng_ht_get_count(agt
->events
);
283 /* Compute required extended infos size */
284 extended_len
= nb_event
* sizeof(struct lttcomm_event_extended_header
);
287 * This is only valid because the commands which add events are
288 * processed in the same thread as the listing.
291 cds_lfht_for_each_entry(agt
->events
->ht
, &iter
.iter
, event
, node
.node
) {
292 increment_extended_len(event
->filter_expression
, NULL
,
297 *total_size
= nb_event
* sizeof(*tmp_events
) + extended_len
;
298 tmp_events
= zmalloc(*total_size
);
300 PERROR("zmalloc agent events session");
301 ret
= -LTTNG_ERR_FATAL
;
305 extended_at
= ((uint8_t *) tmp_events
) +
306 nb_event
* sizeof(struct lttng_event
);
309 cds_lfht_for_each_entry(agt
->events
->ht
, &iter
.iter
, event
, node
.node
) {
310 strncpy(tmp_events
[i
].name
, event
->name
, sizeof(tmp_events
[i
].name
));
311 tmp_events
[i
].name
[sizeof(tmp_events
[i
].name
) - 1] = '\0';
312 tmp_events
[i
].enabled
= event
->enabled
;
313 tmp_events
[i
].loglevel
= event
->loglevel_value
;
314 tmp_events
[i
].loglevel_type
= event
->loglevel_type
;
317 /* Append extended info */
318 append_extended_info(event
->filter_expression
, NULL
,
323 *events
= tmp_events
;
327 assert(nb_event
== i
);
332 * Create a list of ust global domain events.
334 static int list_lttng_ust_global_events(char *channel_name
,
335 struct ltt_ust_domain_global
*ust_global
,
336 struct lttng_event
**events
, size_t *total_size
)
339 unsigned int nb_event
= 0;
340 struct lttng_ht_iter iter
;
341 struct lttng_ht_node_str
*node
;
342 struct ltt_ust_channel
*uchan
;
343 struct ltt_ust_event
*uevent
;
344 struct lttng_event
*tmp
;
345 size_t extended_len
= 0;
348 DBG("Listing UST global events for channel %s", channel_name
);
352 lttng_ht_lookup(ust_global
->channels
, (void *)channel_name
, &iter
);
353 node
= lttng_ht_iter_get_node_str(&iter
);
355 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
359 uchan
= caa_container_of(&node
->node
, struct ltt_ust_channel
, node
.node
);
361 nb_event
= lttng_ht_get_count(uchan
->events
);
368 DBG3("Listing UST global %d events", nb_event
);
370 /* Compute required extended infos size */
371 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
372 if (uevent
->internal
) {
377 increment_extended_len(uevent
->filter_expression
,
378 uevent
->exclusion
, &extended_len
);
381 /* All events are internal, skip. */
387 *total_size
= nb_event
* sizeof(struct lttng_event
) + extended_len
;
388 tmp
= zmalloc(*total_size
);
390 ret
= -LTTNG_ERR_FATAL
;
394 extended_at
= ((uint8_t *) tmp
) + nb_event
* sizeof(struct lttng_event
);
396 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
397 if (uevent
->internal
) {
398 /* This event should remain hidden from clients */
401 strncpy(tmp
[i
].name
, uevent
->attr
.name
, LTTNG_SYMBOL_NAME_LEN
);
402 tmp
[i
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
403 tmp
[i
].enabled
= uevent
->enabled
;
405 switch (uevent
->attr
.instrumentation
) {
406 case LTTNG_UST_TRACEPOINT
:
407 tmp
[i
].type
= LTTNG_EVENT_TRACEPOINT
;
409 case LTTNG_UST_PROBE
:
410 tmp
[i
].type
= LTTNG_EVENT_PROBE
;
412 case LTTNG_UST_FUNCTION
:
413 tmp
[i
].type
= LTTNG_EVENT_FUNCTION
;
417 tmp
[i
].loglevel
= uevent
->attr
.loglevel
;
418 switch (uevent
->attr
.loglevel_type
) {
419 case LTTNG_UST_LOGLEVEL_ALL
:
420 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
422 case LTTNG_UST_LOGLEVEL_RANGE
:
423 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
425 case LTTNG_UST_LOGLEVEL_SINGLE
:
426 tmp
[i
].loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
429 if (uevent
->filter
) {
432 if (uevent
->exclusion
) {
433 tmp
[i
].exclusion
= 1;
437 /* Append extended info */
438 append_extended_info(uevent
->filter_expression
,
439 uevent
->exclusion
, &extended_at
);
450 * Fill lttng_event array of all kernel events in the channel.
452 static int list_lttng_kernel_events(char *channel_name
,
453 struct ltt_kernel_session
*kernel_session
,
454 struct lttng_event
**events
, size_t *total_size
)
457 unsigned int nb_event
;
458 struct ltt_kernel_event
*event
;
459 struct ltt_kernel_channel
*kchan
;
460 size_t extended_len
= 0;
463 kchan
= trace_kernel_get_channel_by_name(channel_name
, kernel_session
);
465 ret
= LTTNG_ERR_KERN_CHAN_NOT_FOUND
;
469 nb_event
= kchan
->event_count
;
471 DBG("Listing events for channel %s", kchan
->channel
->name
);
479 /* Compute required extended infos size */
480 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
481 increment_extended_len(event
->filter_expression
, NULL
,
485 *total_size
= nb_event
* sizeof(struct lttng_event
) + extended_len
;
486 *events
= zmalloc(*total_size
);
487 if (*events
== NULL
) {
488 ret
= LTTNG_ERR_FATAL
;
492 extended_at
= ((uint8_t *) events
) +
493 nb_event
* sizeof(struct lttng_event
);
495 /* Kernel channels */
496 cds_list_for_each_entry(event
, &kchan
->events_list
.head
, list
) {
497 strncpy((*events
)[i
].name
, event
->event
->name
, LTTNG_SYMBOL_NAME_LEN
);
498 (*events
)[i
].name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
499 (*events
)[i
].enabled
= event
->enabled
;
500 (*events
)[i
].filter
=
501 (unsigned char) !!event
->filter_expression
;
503 switch (event
->event
->instrumentation
) {
504 case LTTNG_KERNEL_TRACEPOINT
:
505 (*events
)[i
].type
= LTTNG_EVENT_TRACEPOINT
;
507 case LTTNG_KERNEL_KRETPROBE
:
508 (*events
)[i
].type
= LTTNG_EVENT_FUNCTION
;
509 memcpy(&(*events
)[i
].attr
.probe
, &event
->event
->u
.kprobe
,
510 sizeof(struct lttng_kernel_kprobe
));
512 case LTTNG_KERNEL_KPROBE
:
513 (*events
)[i
].type
= LTTNG_EVENT_PROBE
;
514 memcpy(&(*events
)[i
].attr
.probe
, &event
->event
->u
.kprobe
,
515 sizeof(struct lttng_kernel_kprobe
));
517 case LTTNG_KERNEL_FUNCTION
:
518 (*events
)[i
].type
= LTTNG_EVENT_FUNCTION
;
519 memcpy(&((*events
)[i
].attr
.ftrace
), &event
->event
->u
.ftrace
,
520 sizeof(struct lttng_kernel_function
));
522 case LTTNG_KERNEL_NOOP
:
523 (*events
)[i
].type
= LTTNG_EVENT_NOOP
;
525 case LTTNG_KERNEL_SYSCALL
:
526 (*events
)[i
].type
= LTTNG_EVENT_SYSCALL
;
528 case LTTNG_KERNEL_ALL
:
534 /* Append extended info */
535 append_extended_info(event
->filter_expression
, NULL
,
543 new_size
= syscall_list_channel(kchan
, events
, nb_event
);
555 /* Negate the error code to differentiate the size from an error */
560 * Add URI so the consumer output object. Set the correct path depending on the
561 * domain adding the default trace directory.
563 static int add_uri_to_consumer(struct consumer_output
*consumer
,
564 struct lttng_uri
*uri
, enum lttng_domain_type domain
,
565 const char *session_name
)
568 const char *default_trace_dir
;
572 if (consumer
== NULL
) {
573 DBG("No consumer detected. Don't add URI. Stopping.");
574 ret
= LTTNG_ERR_NO_CONSUMER
;
579 case LTTNG_DOMAIN_KERNEL
:
580 default_trace_dir
= DEFAULT_KERNEL_TRACE_DIR
;
582 case LTTNG_DOMAIN_UST
:
583 default_trace_dir
= DEFAULT_UST_TRACE_DIR
;
587 * This case is possible is we try to add the URI to the global tracing
588 * session consumer object which in this case there is no subdir.
590 default_trace_dir
= "";
593 switch (uri
->dtype
) {
596 DBG2("Setting network URI to consumer");
598 if (consumer
->type
== CONSUMER_DST_NET
) {
599 if ((uri
->stype
== LTTNG_STREAM_CONTROL
&&
600 consumer
->dst
.net
.control_isset
) ||
601 (uri
->stype
== LTTNG_STREAM_DATA
&&
602 consumer
->dst
.net
.data_isset
)) {
603 ret
= LTTNG_ERR_URL_EXIST
;
607 memset(&consumer
->dst
.net
, 0, sizeof(consumer
->dst
.net
));
610 consumer
->type
= CONSUMER_DST_NET
;
612 /* Set URI into consumer output object */
613 ret
= consumer_set_network_uri(consumer
, uri
);
617 } else if (ret
== 1) {
619 * URI was the same in the consumer so we do not append the subdir
620 * again so to not duplicate output dir.
626 if (uri
->stype
== LTTNG_STREAM_CONTROL
&& strlen(uri
->subdir
) == 0) {
627 ret
= consumer_set_subdir(consumer
, session_name
);
629 ret
= LTTNG_ERR_FATAL
;
634 if (uri
->stype
== LTTNG_STREAM_CONTROL
) {
635 /* On a new subdir, reappend the default trace dir. */
636 strncat(consumer
->subdir
, default_trace_dir
,
637 sizeof(consumer
->subdir
) - strlen(consumer
->subdir
) - 1);
638 DBG3("Append domain trace name to subdir %s", consumer
->subdir
);
643 DBG2("Setting trace directory path from URI to %s", uri
->dst
.path
);
644 memset(consumer
->dst
.trace_path
, 0,
645 sizeof(consumer
->dst
.trace_path
));
646 strncpy(consumer
->dst
.trace_path
, uri
->dst
.path
,
647 sizeof(consumer
->dst
.trace_path
));
648 /* Append default trace dir */
649 strncat(consumer
->dst
.trace_path
, default_trace_dir
,
650 sizeof(consumer
->dst
.trace_path
) -
651 strlen(consumer
->dst
.trace_path
) - 1);
652 /* Flag consumer as local. */
653 consumer
->type
= CONSUMER_DST_LOCAL
;
664 * Init tracing by creating trace directory and sending fds kernel consumer.
666 static int init_kernel_tracing(struct ltt_kernel_session
*session
)
669 struct lttng_ht_iter iter
;
670 struct consumer_socket
*socket
;
676 if (session
->consumer_fds_sent
== 0 && session
->consumer
!= NULL
) {
677 cds_lfht_for_each_entry(session
->consumer
->socks
->ht
, &iter
.iter
,
679 pthread_mutex_lock(socket
->lock
);
680 ret
= kernel_consumer_send_session(socket
, session
);
681 pthread_mutex_unlock(socket
->lock
);
683 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
695 * Create a socket to the relayd using the URI.
697 * On success, the relayd_sock pointer is set to the created socket.
698 * Else, it's stays untouched and a lttcomm error code is returned.
700 static int create_connect_relayd(struct lttng_uri
*uri
,
701 struct lttcomm_relayd_sock
**relayd_sock
)
704 struct lttcomm_relayd_sock
*rsock
;
706 rsock
= lttcomm_alloc_relayd_sock(uri
, RELAYD_VERSION_COMM_MAJOR
,
707 RELAYD_VERSION_COMM_MINOR
);
709 ret
= LTTNG_ERR_FATAL
;
714 * Connect to relayd so we can proceed with a session creation. This call
715 * can possibly block for an arbitrary amount of time to set the health
716 * state to be in poll execution.
719 ret
= relayd_connect(rsock
);
722 ERR("Unable to reach lttng-relayd");
723 ret
= LTTNG_ERR_RELAYD_CONNECT_FAIL
;
727 /* Create socket for control stream. */
728 if (uri
->stype
== LTTNG_STREAM_CONTROL
) {
729 DBG3("Creating relayd stream socket from URI");
731 /* Check relayd version */
732 ret
= relayd_version_check(rsock
);
734 ret
= LTTNG_ERR_RELAYD_VERSION_FAIL
;
737 } else if (uri
->stype
== LTTNG_STREAM_DATA
) {
738 DBG3("Creating relayd data socket from URI");
740 /* Command is not valid */
741 ERR("Relayd invalid stream type: %d", uri
->stype
);
742 ret
= LTTNG_ERR_INVALID
;
746 *relayd_sock
= rsock
;
751 /* The returned value is not useful since we are on an error path. */
752 (void) relayd_close(rsock
);
760 * Connect to the relayd using URI and send the socket to the right consumer.
762 static int send_consumer_relayd_socket(enum lttng_domain_type domain
,
763 unsigned int session_id
, struct lttng_uri
*relayd_uri
,
764 struct consumer_output
*consumer
,
765 struct consumer_socket
*consumer_sock
,
766 char *session_name
, char *hostname
, int session_live_timer
)
769 struct lttcomm_relayd_sock
*rsock
= NULL
;
771 /* Connect to relayd and make version check if uri is the control. */
772 ret
= create_connect_relayd(relayd_uri
, &rsock
);
773 if (ret
!= LTTNG_OK
) {
778 /* Set the network sequence index if not set. */
779 if (consumer
->net_seq_index
== (uint64_t) -1ULL) {
780 pthread_mutex_lock(&relayd_net_seq_idx_lock
);
782 * Increment net_seq_idx because we are about to transfer the
783 * new relayd socket to the consumer.
784 * Assign unique key so the consumer can match streams.
786 consumer
->net_seq_index
= ++relayd_net_seq_idx
;
787 pthread_mutex_unlock(&relayd_net_seq_idx_lock
);
790 /* Send relayd socket to consumer. */
791 ret
= consumer_send_relayd_socket(consumer_sock
, rsock
, consumer
,
792 relayd_uri
->stype
, session_id
,
793 session_name
, hostname
, session_live_timer
);
795 ret
= LTTNG_ERR_ENABLE_CONSUMER_FAIL
;
799 /* Flag that the corresponding socket was sent. */
800 if (relayd_uri
->stype
== LTTNG_STREAM_CONTROL
) {
801 consumer_sock
->control_sock_sent
= 1;
802 } else if (relayd_uri
->stype
== LTTNG_STREAM_DATA
) {
803 consumer_sock
->data_sock_sent
= 1;
809 * Close socket which was dup on the consumer side. The session daemon does
810 * NOT keep track of the relayd socket(s) once transfer to the consumer.
814 (void) relayd_close(rsock
);
818 if (ret
!= LTTNG_OK
) {
820 * The consumer output for this session should not be used anymore
821 * since the relayd connection failed thus making any tracing or/and
822 * streaming not usable.
824 consumer
->enabled
= 0;
830 * Send both relayd sockets to a specific consumer and domain. This is a
831 * helper function to facilitate sending the information to the consumer for a
834 static int send_consumer_relayd_sockets(enum lttng_domain_type domain
,
835 unsigned int session_id
, struct consumer_output
*consumer
,
836 struct consumer_socket
*sock
, char *session_name
,
837 char *hostname
, int session_live_timer
)
844 /* Sending control relayd socket. */
845 if (!sock
->control_sock_sent
) {
846 ret
= send_consumer_relayd_socket(domain
, session_id
,
847 &consumer
->dst
.net
.control
, consumer
, sock
,
848 session_name
, hostname
, session_live_timer
);
849 if (ret
!= LTTNG_OK
) {
854 /* Sending data relayd socket. */
855 if (!sock
->data_sock_sent
) {
856 ret
= send_consumer_relayd_socket(domain
, session_id
,
857 &consumer
->dst
.net
.data
, consumer
, sock
,
858 session_name
, hostname
, session_live_timer
);
859 if (ret
!= LTTNG_OK
) {
869 * Setup relayd connections for a tracing session. First creates the socket to
870 * the relayd and send them to the right domain consumer. Consumer type MUST be
873 int cmd_setup_relayd(struct ltt_session
*session
)
876 struct ltt_ust_session
*usess
;
877 struct ltt_kernel_session
*ksess
;
878 struct consumer_socket
*socket
;
879 struct lttng_ht_iter iter
;
883 usess
= session
->ust_session
;
884 ksess
= session
->kernel_session
;
886 DBG("Setting relayd for session %s", session
->name
);
890 if (usess
&& usess
->consumer
&& usess
->consumer
->type
== CONSUMER_DST_NET
891 && usess
->consumer
->enabled
) {
892 /* For each consumer socket, send relayd sockets */
893 cds_lfht_for_each_entry(usess
->consumer
->socks
->ht
, &iter
.iter
,
895 pthread_mutex_lock(socket
->lock
);
896 ret
= send_consumer_relayd_sockets(LTTNG_DOMAIN_UST
, session
->id
,
897 usess
->consumer
, socket
,
898 session
->name
, session
->hostname
,
899 session
->live_timer
);
900 pthread_mutex_unlock(socket
->lock
);
901 if (ret
!= LTTNG_OK
) {
904 /* Session is now ready for network streaming. */
905 session
->net_handle
= 1;
909 if (ksess
&& ksess
->consumer
&& ksess
->consumer
->type
== CONSUMER_DST_NET
910 && ksess
->consumer
->enabled
) {
911 cds_lfht_for_each_entry(ksess
->consumer
->socks
->ht
, &iter
.iter
,
913 pthread_mutex_lock(socket
->lock
);
914 ret
= send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL
, session
->id
,
915 ksess
->consumer
, socket
,
916 session
->name
, session
->hostname
,
917 session
->live_timer
);
918 pthread_mutex_unlock(socket
->lock
);
919 if (ret
!= LTTNG_OK
) {
922 /* Session is now ready for network streaming. */
923 session
->net_handle
= 1;
933 * Start a kernel session by opening all necessary streams.
935 static int start_kernel_session(struct ltt_kernel_session
*ksess
, int wpipe
)
938 struct ltt_kernel_channel
*kchan
;
940 /* Open kernel metadata */
941 if (ksess
->metadata
== NULL
&& ksess
->output_traces
) {
942 ret
= kernel_open_metadata(ksess
);
944 ret
= LTTNG_ERR_KERN_META_FAIL
;
949 /* Open kernel metadata stream */
950 if (ksess
->metadata
&& ksess
->metadata_stream_fd
< 0) {
951 ret
= kernel_open_metadata_stream(ksess
);
953 ERR("Kernel create metadata stream failed");
954 ret
= LTTNG_ERR_KERN_STREAM_FAIL
;
959 /* For each channel */
960 cds_list_for_each_entry(kchan
, &ksess
->channel_list
.head
, list
) {
961 if (kchan
->stream_count
== 0) {
962 ret
= kernel_open_channel_stream(kchan
);
964 ret
= LTTNG_ERR_KERN_STREAM_FAIL
;
967 /* Update the stream global counter */
968 ksess
->stream_count_global
+= ret
;
972 /* Setup kernel consumer socket and send fds to it */
973 ret
= init_kernel_tracing(ksess
);
975 ret
= LTTNG_ERR_KERN_START_FAIL
;
979 /* This start the kernel tracing */
980 ret
= kernel_start_session(ksess
);
982 ret
= LTTNG_ERR_KERN_START_FAIL
;
986 /* Quiescent wait after starting trace */
987 kernel_wait_quiescent(kernel_tracer_fd
);
998 * Command LTTNG_DISABLE_CHANNEL processed by the client thread.
1000 int cmd_disable_channel(struct ltt_session
*session
,
1001 enum lttng_domain_type domain
, char *channel_name
)
1004 struct ltt_ust_session
*usess
;
1006 usess
= session
->ust_session
;
1011 case LTTNG_DOMAIN_KERNEL
:
1013 ret
= channel_kernel_disable(session
->kernel_session
,
1015 if (ret
!= LTTNG_OK
) {
1019 kernel_wait_quiescent(kernel_tracer_fd
);
1022 case LTTNG_DOMAIN_UST
:
1024 struct ltt_ust_channel
*uchan
;
1025 struct lttng_ht
*chan_ht
;
1027 chan_ht
= usess
->domain_global
.channels
;
1029 uchan
= trace_ust_find_channel_by_name(chan_ht
, channel_name
);
1030 if (uchan
== NULL
) {
1031 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1035 ret
= channel_ust_disable(usess
, uchan
);
1036 if (ret
!= LTTNG_OK
) {
1042 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1054 * Command LTTNG_TRACK_PID processed by the client thread.
1056 * Called with session lock held.
1058 int cmd_track_pid(struct ltt_session
*session
, enum lttng_domain_type domain
,
1066 case LTTNG_DOMAIN_KERNEL
:
1068 struct ltt_kernel_session
*ksess
;
1070 ksess
= session
->kernel_session
;
1072 ret
= kernel_track_pid(ksess
, pid
);
1073 if (ret
!= LTTNG_OK
) {
1077 kernel_wait_quiescent(kernel_tracer_fd
);
1080 case LTTNG_DOMAIN_UST
:
1082 struct ltt_ust_session
*usess
;
1084 usess
= session
->ust_session
;
1086 ret
= trace_ust_track_pid(usess
, pid
);
1087 if (ret
!= LTTNG_OK
) {
1093 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1105 * Command LTTNG_UNTRACK_PID processed by the client thread.
1107 * Called with session lock held.
1109 int cmd_untrack_pid(struct ltt_session
*session
, enum lttng_domain_type domain
,
1117 case LTTNG_DOMAIN_KERNEL
:
1119 struct ltt_kernel_session
*ksess
;
1121 ksess
= session
->kernel_session
;
1123 ret
= kernel_untrack_pid(ksess
, pid
);
1124 if (ret
!= LTTNG_OK
) {
1128 kernel_wait_quiescent(kernel_tracer_fd
);
1131 case LTTNG_DOMAIN_UST
:
1133 struct ltt_ust_session
*usess
;
1135 usess
= session
->ust_session
;
1137 ret
= trace_ust_untrack_pid(usess
, pid
);
1138 if (ret
!= LTTNG_OK
) {
1144 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1156 * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
1158 * The wpipe arguments is used as a notifier for the kernel thread.
1160 int cmd_enable_channel(struct ltt_session
*session
,
1161 struct lttng_domain
*domain
, struct lttng_channel
*attr
, int wpipe
)
1164 struct ltt_ust_session
*usess
= session
->ust_session
;
1165 struct lttng_ht
*chan_ht
;
1172 len
= lttng_strnlen(attr
->name
, sizeof(attr
->name
));
1174 /* Validate channel name */
1175 if (attr
->name
[0] == '.' ||
1176 memchr(attr
->name
, '/', len
) != NULL
) {
1177 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1181 DBG("Enabling channel %s for session %s", attr
->name
, session
->name
);
1186 * Don't try to enable a channel if the session has been started at
1187 * some point in time before. The tracer does not allow it.
1189 if (session
->has_been_started
) {
1190 ret
= LTTNG_ERR_TRACE_ALREADY_STARTED
;
1195 * If the session is a live session, remove the switch timer, the
1196 * live timer does the same thing but sends also synchronisation
1197 * beacons for inactive streams.
1199 if (session
->live_timer
> 0) {
1200 attr
->attr
.live_timer_interval
= session
->live_timer
;
1201 attr
->attr
.switch_timer_interval
= 0;
1205 * The ringbuffer (both in user space and kernel) behave badly in overwrite
1206 * mode and with less than 2 subbuf so block it right away and send back an
1207 * invalid attribute error.
1209 if (attr
->attr
.overwrite
&& attr
->attr
.num_subbuf
< 2) {
1210 ret
= LTTNG_ERR_INVALID
;
1214 switch (domain
->type
) {
1215 case LTTNG_DOMAIN_KERNEL
:
1217 struct ltt_kernel_channel
*kchan
;
1219 kchan
= trace_kernel_get_channel_by_name(attr
->name
,
1220 session
->kernel_session
);
1221 if (kchan
== NULL
) {
1222 ret
= channel_kernel_create(session
->kernel_session
, attr
, wpipe
);
1223 if (attr
->name
[0] != '\0') {
1224 session
->kernel_session
->has_non_default_channel
= 1;
1227 ret
= channel_kernel_enable(session
->kernel_session
, kchan
);
1230 if (ret
!= LTTNG_OK
) {
1234 kernel_wait_quiescent(kernel_tracer_fd
);
1237 case LTTNG_DOMAIN_UST
:
1238 case LTTNG_DOMAIN_JUL
:
1239 case LTTNG_DOMAIN_LOG4J
:
1240 case LTTNG_DOMAIN_PYTHON
:
1242 struct ltt_ust_channel
*uchan
;
1247 * Current agent implementation limitations force us to allow
1248 * only one channel at once in "agent" subdomains. Each
1249 * subdomain has a default channel name which must be strictly
1252 if (domain
->type
== LTTNG_DOMAIN_JUL
) {
1253 if (strncmp(attr
->name
, DEFAULT_JUL_CHANNEL_NAME
,
1254 LTTNG_SYMBOL_NAME_LEN
)) {
1255 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1258 } else if (domain
->type
== LTTNG_DOMAIN_LOG4J
) {
1259 if (strncmp(attr
->name
, DEFAULT_LOG4J_CHANNEL_NAME
,
1260 LTTNG_SYMBOL_NAME_LEN
)) {
1261 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1264 } else if (domain
->type
== LTTNG_DOMAIN_PYTHON
) {
1265 if (strncmp(attr
->name
, DEFAULT_PYTHON_CHANNEL_NAME
,
1266 LTTNG_SYMBOL_NAME_LEN
)) {
1267 ret
= LTTNG_ERR_INVALID_CHANNEL_NAME
;
1272 chan_ht
= usess
->domain_global
.channels
;
1274 uchan
= trace_ust_find_channel_by_name(chan_ht
, attr
->name
);
1275 if (uchan
== NULL
) {
1276 ret
= channel_ust_create(usess
, attr
, domain
->buf_type
);
1277 if (attr
->name
[0] != '\0') {
1278 usess
->has_non_default_channel
= 1;
1281 ret
= channel_ust_enable(usess
, uchan
);
1286 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;
1297 * Command LTTNG_DISABLE_EVENT processed by the client thread.
1299 int cmd_disable_event(struct ltt_session
*session
,
1300 enum lttng_domain_type domain
, char *channel_name
,
1301 struct lttng_event
*event
)
1306 DBG("Disable event command for event \'%s\'", event
->name
);
1308 event_name
= event
->name
;
1309 if (validate_event_name(event_name
)) {
1310 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
1314 /* Error out on unhandled search criteria */
1315 if (event
->loglevel_type
|| event
->loglevel
!= -1 || event
->enabled
1316 || event
->pid
|| event
->filter
|| event
->exclusion
) {
1317 ret
= LTTNG_ERR_UNK
;
1324 case LTTNG_DOMAIN_KERNEL
:
1326 struct ltt_kernel_channel
*kchan
;
1327 struct ltt_kernel_session
*ksess
;
1329 ksess
= session
->kernel_session
;
1332 * If a non-default channel has been created in the
1333 * session, explicitely require that -c chan_name needs
1336 if (ksess
->has_non_default_channel
&& channel_name
[0] == '\0') {
1337 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
1341 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksess
);
1342 if (kchan
== NULL
) {
1343 ret
= LTTNG_ERR_KERN_CHAN_NOT_FOUND
;
1347 switch (event
->type
) {
1348 case LTTNG_EVENT_ALL
:
1349 case LTTNG_EVENT_TRACEPOINT
:
1350 case LTTNG_EVENT_SYSCALL
:
1351 case LTTNG_EVENT_PROBE
:
1352 case LTTNG_EVENT_FUNCTION
:
1353 case LTTNG_EVENT_FUNCTION_ENTRY
:/* fall-through */
1354 if (event_name
[0] == '\0') {
1355 ret
= event_kernel_disable_event(kchan
,
1358 ret
= event_kernel_disable_event(kchan
,
1359 event_name
, event
->type
);
1361 if (ret
!= LTTNG_OK
) {
1366 ret
= LTTNG_ERR_UNK
;
1370 kernel_wait_quiescent(kernel_tracer_fd
);
1373 case LTTNG_DOMAIN_UST
:
1375 struct ltt_ust_channel
*uchan
;
1376 struct ltt_ust_session
*usess
;
1378 usess
= session
->ust_session
;
1380 if (validate_ust_event_name(event_name
)) {
1381 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
1386 * If a non-default channel has been created in the
1387 * session, explicitly require that -c chan_name needs
1390 if (usess
->has_non_default_channel
&& channel_name
[0] == '\0') {
1391 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
1395 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
1397 if (uchan
== NULL
) {
1398 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1402 switch (event
->type
) {
1403 case LTTNG_EVENT_ALL
:
1405 * An empty event name means that everything
1406 * should be disabled.
1408 if (event
->name
[0] == '\0') {
1409 ret
= event_ust_disable_all_tracepoints(usess
, uchan
);
1411 ret
= event_ust_disable_tracepoint(usess
, uchan
,
1414 if (ret
!= LTTNG_OK
) {
1419 ret
= LTTNG_ERR_UNK
;
1423 DBG3("Disable UST event %s in channel %s completed", event_name
,
1427 case LTTNG_DOMAIN_LOG4J
:
1428 case LTTNG_DOMAIN_JUL
:
1429 case LTTNG_DOMAIN_PYTHON
:
1432 struct ltt_ust_session
*usess
= session
->ust_session
;
1436 switch (event
->type
) {
1437 case LTTNG_EVENT_ALL
:
1440 ret
= LTTNG_ERR_UNK
;
1444 agt
= trace_ust_find_agent(usess
, domain
);
1446 ret
= -LTTNG_ERR_UST_EVENT_NOT_FOUND
;
1450 * An empty event name means that everything
1451 * should be disabled.
1453 if (event
->name
[0] == '\0') {
1454 ret
= event_agent_disable_all(usess
, agt
);
1456 ret
= event_agent_disable(usess
, agt
, event_name
);
1458 if (ret
!= LTTNG_OK
) {
1465 ret
= LTTNG_ERR_UND
;
1478 * Command LTTNG_ADD_CONTEXT processed by the client thread.
1480 int cmd_add_context(struct ltt_session
*session
, enum lttng_domain_type domain
,
1481 char *channel_name
, struct lttng_event_context
*ctx
, int kwpipe
)
1483 int ret
, chan_kern_created
= 0, chan_ust_created
= 0;
1484 char *app_ctx_provider_name
= NULL
, *app_ctx_name
= NULL
;
1486 if (ctx
->ctx
== LTTNG_EVENT_CONTEXT_APP_CONTEXT
) {
1487 app_ctx_provider_name
= ctx
->u
.app_ctx
.provider_name
;
1488 app_ctx_name
= ctx
->u
.app_ctx
.ctx_name
;
1492 case LTTNG_DOMAIN_KERNEL
:
1493 assert(session
->kernel_session
);
1495 if (session
->kernel_session
->channel_count
== 0) {
1496 /* Create default channel */
1497 ret
= channel_kernel_create(session
->kernel_session
, NULL
, kwpipe
);
1498 if (ret
!= LTTNG_OK
) {
1501 chan_kern_created
= 1;
1503 /* Add kernel context to kernel tracer */
1504 ret
= context_kernel_add(session
->kernel_session
, ctx
, channel_name
);
1505 if (ret
!= LTTNG_OK
) {
1509 case LTTNG_DOMAIN_JUL
:
1510 case LTTNG_DOMAIN_LOG4J
:
1513 * Validate channel name.
1514 * If no channel name is given and the domain is JUL or LOG4J,
1515 * set it to the appropriate domain-specific channel name. If
1516 * a name is provided but does not match the expexted channel
1517 * name, return an error.
1519 if (domain
== LTTNG_DOMAIN_JUL
&& *channel_name
&&
1520 strcmp(channel_name
,
1521 DEFAULT_JUL_CHANNEL_NAME
)) {
1522 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1524 } else if (domain
== LTTNG_DOMAIN_LOG4J
&& *channel_name
&&
1525 strcmp(channel_name
,
1526 DEFAULT_LOG4J_CHANNEL_NAME
)) {
1527 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
1530 /* break is _not_ missing here. */
1532 case LTTNG_DOMAIN_UST
:
1534 struct ltt_ust_session
*usess
= session
->ust_session
;
1535 unsigned int chan_count
;
1539 chan_count
= lttng_ht_get_count(usess
->domain_global
.channels
);
1540 if (chan_count
== 0) {
1541 struct lttng_channel
*attr
;
1542 /* Create default channel */
1543 attr
= channel_new_default_attr(domain
, usess
->buffer_type
);
1545 ret
= LTTNG_ERR_FATAL
;
1549 ret
= channel_ust_create(usess
, attr
, usess
->buffer_type
);
1550 if (ret
!= LTTNG_OK
) {
1555 chan_ust_created
= 1;
1558 ret
= context_ust_add(usess
, domain
, ctx
, channel_name
);
1559 free(app_ctx_provider_name
);
1561 app_ctx_name
= NULL
;
1562 app_ctx_provider_name
= NULL
;
1563 if (ret
!= LTTNG_OK
) {
1569 ret
= LTTNG_ERR_UND
;
1577 if (chan_kern_created
) {
1578 struct ltt_kernel_channel
*kchan
=
1579 trace_kernel_get_channel_by_name(DEFAULT_CHANNEL_NAME
,
1580 session
->kernel_session
);
1581 /* Created previously, this should NOT fail. */
1583 kernel_destroy_channel(kchan
);
1586 if (chan_ust_created
) {
1587 struct ltt_ust_channel
*uchan
=
1588 trace_ust_find_channel_by_name(
1589 session
->ust_session
->domain_global
.channels
,
1590 DEFAULT_CHANNEL_NAME
);
1591 /* Created previously, this should NOT fail. */
1593 /* Remove from the channel list of the session. */
1594 trace_ust_delete_channel(session
->ust_session
->domain_global
.channels
,
1596 trace_ust_destroy_channel(uchan
);
1599 free(app_ctx_provider_name
);
1604 static int validate_event_name(const char *name
)
1607 const char *c
= name
;
1608 const char *event_name_end
= c
+ LTTNG_SYMBOL_NAME_LEN
;
1609 bool null_terminated
= false;
1612 * Make sure that unescaped wildcards are only used as the last
1613 * character of the event name.
1615 while (c
< event_name_end
) {
1618 null_terminated
= true;
1624 if ((c
+ 1) < event_name_end
&& *(c
+ 1)) {
1625 /* Wildcard is not the last character */
1626 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
1635 if (!ret
&& !null_terminated
) {
1636 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
1641 static inline bool name_starts_with(const char *name
, const char *prefix
)
1643 const size_t max_cmp_len
= min(strlen(prefix
), LTTNG_SYMBOL_NAME_LEN
);
1645 return !strncmp(name
, prefix
, max_cmp_len
);
1648 /* Perform userspace-specific event name validation */
1649 static int validate_ust_event_name(const char *name
)
1659 * Check name against all internal UST event component namespaces used
1662 if (name_starts_with(name
, DEFAULT_JUL_EVENT_COMPONENT
) ||
1663 name_starts_with(name
, DEFAULT_LOG4J_EVENT_COMPONENT
) ||
1664 name_starts_with(name
, DEFAULT_PYTHON_EVENT_COMPONENT
)) {
1673 * Internal version of cmd_enable_event() with a supplemental
1674 * "internal_event" flag which is used to enable internal events which should
1675 * be hidden from clients. Such events are used in the agent implementation to
1676 * enable the events through which all "agent" events are funeled.
1678 static int _cmd_enable_event(struct ltt_session
*session
,
1679 struct lttng_domain
*domain
,
1680 char *channel_name
, struct lttng_event
*event
,
1681 char *filter_expression
,
1682 struct lttng_filter_bytecode
*filter
,
1683 struct lttng_event_exclusion
*exclusion
,
1684 int wpipe
, bool internal_event
)
1686 int ret
, channel_created
= 0;
1687 struct lttng_channel
*attr
;
1691 assert(channel_name
);
1693 /* If we have a filter, we must have its filter expression */
1694 assert(!(!!filter_expression
^ !!filter
));
1696 DBG("Enable event command for event \'%s\'", event
->name
);
1700 ret
= validate_event_name(event
->name
);
1705 switch (domain
->type
) {
1706 case LTTNG_DOMAIN_KERNEL
:
1708 struct ltt_kernel_channel
*kchan
;
1711 * If a non-default channel has been created in the
1712 * session, explicitely require that -c chan_name needs
1715 if (session
->kernel_session
->has_non_default_channel
1716 && channel_name
[0] == '\0') {
1717 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
1721 kchan
= trace_kernel_get_channel_by_name(channel_name
,
1722 session
->kernel_session
);
1723 if (kchan
== NULL
) {
1724 attr
= channel_new_default_attr(LTTNG_DOMAIN_KERNEL
,
1725 LTTNG_BUFFER_GLOBAL
);
1727 ret
= LTTNG_ERR_FATAL
;
1730 strncpy(attr
->name
, channel_name
, sizeof(attr
->name
));
1732 ret
= cmd_enable_channel(session
, domain
, attr
, wpipe
);
1733 if (ret
!= LTTNG_OK
) {
1739 channel_created
= 1;
1742 /* Get the newly created kernel channel pointer */
1743 kchan
= trace_kernel_get_channel_by_name(channel_name
,
1744 session
->kernel_session
);
1745 if (kchan
== NULL
) {
1746 /* This sould not happen... */
1747 ret
= LTTNG_ERR_FATAL
;
1751 switch (event
->type
) {
1752 case LTTNG_EVENT_ALL
:
1754 char *filter_expression_a
= NULL
;
1755 struct lttng_filter_bytecode
*filter_a
= NULL
;
1758 * We need to duplicate filter_expression and filter,
1759 * because ownership is passed to first enable
1762 if (filter_expression
) {
1763 filter_expression_a
= strdup(filter_expression
);
1764 if (!filter_expression_a
) {
1765 ret
= LTTNG_ERR_FATAL
;
1770 filter_a
= zmalloc(sizeof(*filter_a
) + filter
->len
);
1772 free(filter_expression_a
);
1773 ret
= LTTNG_ERR_FATAL
;
1776 memcpy(filter_a
, filter
, sizeof(*filter_a
) + filter
->len
);
1778 event
->type
= LTTNG_EVENT_TRACEPOINT
; /* Hack */
1779 ret
= event_kernel_enable_event(kchan
, event
,
1780 filter_expression
, filter
);
1781 /* We have passed ownership */
1782 filter_expression
= NULL
;
1784 if (ret
!= LTTNG_OK
) {
1785 if (channel_created
) {
1786 /* Let's not leak a useless channel. */
1787 kernel_destroy_channel(kchan
);
1789 free(filter_expression_a
);
1793 event
->type
= LTTNG_EVENT_SYSCALL
; /* Hack */
1794 ret
= event_kernel_enable_event(kchan
, event
,
1795 filter_expression_a
, filter_a
);
1796 /* We have passed ownership */
1797 filter_expression_a
= NULL
;
1799 if (ret
!= LTTNG_OK
) {
1804 case LTTNG_EVENT_PROBE
:
1805 case LTTNG_EVENT_FUNCTION
:
1806 case LTTNG_EVENT_FUNCTION_ENTRY
:
1807 case LTTNG_EVENT_TRACEPOINT
:
1808 ret
= event_kernel_enable_event(kchan
, event
,
1809 filter_expression
, filter
);
1810 /* We have passed ownership */
1811 filter_expression
= NULL
;
1813 if (ret
!= LTTNG_OK
) {
1814 if (channel_created
) {
1815 /* Let's not leak a useless channel. */
1816 kernel_destroy_channel(kchan
);
1821 case LTTNG_EVENT_SYSCALL
:
1822 ret
= event_kernel_enable_event(kchan
, event
,
1823 filter_expression
, filter
);
1824 /* We have passed ownership */
1825 filter_expression
= NULL
;
1827 if (ret
!= LTTNG_OK
) {
1832 ret
= LTTNG_ERR_UNK
;
1836 kernel_wait_quiescent(kernel_tracer_fd
);
1839 case LTTNG_DOMAIN_UST
:
1841 struct ltt_ust_channel
*uchan
;
1842 struct ltt_ust_session
*usess
= session
->ust_session
;
1847 * If a non-default channel has been created in the
1848 * session, explicitely require that -c chan_name needs
1851 if (usess
->has_non_default_channel
&& channel_name
[0] == '\0') {
1852 ret
= LTTNG_ERR_NEED_CHANNEL_NAME
;
1856 /* Get channel from global UST domain */
1857 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
1859 if (uchan
== NULL
) {
1860 /* Create default channel */
1861 attr
= channel_new_default_attr(LTTNG_DOMAIN_UST
,
1862 usess
->buffer_type
);
1864 ret
= LTTNG_ERR_FATAL
;
1867 strncpy(attr
->name
, channel_name
, sizeof(attr
->name
));
1869 ret
= cmd_enable_channel(session
, domain
, attr
, wpipe
);
1870 if (ret
!= LTTNG_OK
) {
1876 /* Get the newly created channel reference back */
1877 uchan
= trace_ust_find_channel_by_name(
1878 usess
->domain_global
.channels
, channel_name
);
1882 if (uchan
->domain
!= LTTNG_DOMAIN_UST
&& !internal_event
) {
1884 * Don't allow users to add UST events to channels which
1885 * are assigned to a userspace subdomain (JUL, Log4J,
1888 ret
= LTTNG_ERR_INVALID_CHANNEL_DOMAIN
;
1892 if (!internal_event
) {
1894 * Ensure the event name is not reserved for internal
1897 ret
= validate_ust_event_name(event
->name
);
1899 WARN("Userspace event name %s failed validation.",
1901 event
->name
: "NULL");
1902 ret
= LTTNG_ERR_INVALID_EVENT_NAME
;
1907 /* At this point, the session and channel exist on the tracer */
1908 ret
= event_ust_enable_tracepoint(usess
, uchan
, event
,
1909 filter_expression
, filter
, exclusion
,
1911 /* We have passed ownership */
1912 filter_expression
= NULL
;
1915 if (ret
== LTTNG_ERR_UST_EVENT_ENABLED
) {
1916 goto already_enabled
;
1917 } else if (ret
!= LTTNG_OK
) {
1922 case LTTNG_DOMAIN_LOG4J
:
1923 case LTTNG_DOMAIN_JUL
:
1924 case LTTNG_DOMAIN_PYTHON
:
1926 const char *default_event_name
, *default_chan_name
;
1928 struct lttng_event uevent
;
1929 struct lttng_domain tmp_dom
;
1930 struct ltt_ust_session
*usess
= session
->ust_session
;
1934 agt
= trace_ust_find_agent(usess
, domain
->type
);
1936 agt
= agent_create(domain
->type
);
1938 ret
= LTTNG_ERR_NOMEM
;
1941 agent_add(agt
, usess
->agents
);
1944 /* Create the default tracepoint. */
1945 memset(&uevent
, 0, sizeof(uevent
));
1946 uevent
.type
= LTTNG_EVENT_TRACEPOINT
;
1947 uevent
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
1948 default_event_name
= event_get_default_agent_ust_name(
1950 if (!default_event_name
) {
1951 ret
= LTTNG_ERR_FATAL
;
1954 strncpy(uevent
.name
, default_event_name
, sizeof(uevent
.name
));
1955 uevent
.name
[sizeof(uevent
.name
) - 1] = '\0';
1958 * The domain type is changed because we are about to enable the
1959 * default channel and event for the JUL domain that are hardcoded.
1960 * This happens in the UST domain.
1962 memcpy(&tmp_dom
, domain
, sizeof(tmp_dom
));
1963 tmp_dom
.type
= LTTNG_DOMAIN_UST
;
1965 switch (domain
->type
) {
1966 case LTTNG_DOMAIN_LOG4J
:
1967 default_chan_name
= DEFAULT_LOG4J_CHANNEL_NAME
;
1969 case LTTNG_DOMAIN_JUL
:
1970 default_chan_name
= DEFAULT_JUL_CHANNEL_NAME
;
1972 case LTTNG_DOMAIN_PYTHON
:
1973 default_chan_name
= DEFAULT_PYTHON_CHANNEL_NAME
;
1976 /* The switch/case we are in makes this impossible */
1981 char *filter_expression_copy
= NULL
;
1982 struct lttng_filter_bytecode
*filter_copy
= NULL
;
1985 const size_t filter_size
= sizeof(
1986 struct lttng_filter_bytecode
)
1989 filter_copy
= zmalloc(filter_size
);
1991 ret
= LTTNG_ERR_NOMEM
;
1994 memcpy(filter_copy
, filter
, filter_size
);
1996 filter_expression_copy
=
1997 strdup(filter_expression
);
1998 if (!filter_expression
) {
1999 ret
= LTTNG_ERR_NOMEM
;
2002 if (!filter_expression_copy
|| !filter_copy
) {
2003 free(filter_expression_copy
);
2009 ret
= cmd_enable_event_internal(session
, &tmp_dom
,
2010 (char *) default_chan_name
,
2011 &uevent
, filter_expression_copy
,
2012 filter_copy
, NULL
, wpipe
);
2015 if (ret
== LTTNG_ERR_UST_EVENT_ENABLED
) {
2016 goto already_enabled
;
2017 } else if (ret
!= LTTNG_OK
) {
2021 /* The wild card * means that everything should be enabled. */
2022 if (strncmp(event
->name
, "*", 1) == 0 && strlen(event
->name
) == 1) {
2023 ret
= event_agent_enable_all(usess
, agt
, event
, filter
,
2026 ret
= event_agent_enable(usess
, agt
, event
, filter
,
2030 filter_expression
= NULL
;
2031 if (ret
!= LTTNG_OK
) {
2038 ret
= LTTNG_ERR_UND
;
2046 free(filter_expression
);
2054 * Command LTTNG_ENABLE_EVENT processed by the client thread.
2055 * We own filter, exclusion, and filter_expression.
2057 int cmd_enable_event(struct ltt_session
*session
, struct lttng_domain
*domain
,
2058 char *channel_name
, struct lttng_event
*event
,
2059 char *filter_expression
,
2060 struct lttng_filter_bytecode
*filter
,
2061 struct lttng_event_exclusion
*exclusion
,
2064 return _cmd_enable_event(session
, domain
, channel_name
, event
,
2065 filter_expression
, filter
, exclusion
, wpipe
, false);
2069 * Enable an event which is internal to LTTng. An internal should
2070 * never be made visible to clients and are immune to checks such as
2073 static int cmd_enable_event_internal(struct ltt_session
*session
,
2074 struct lttng_domain
*domain
,
2075 char *channel_name
, struct lttng_event
*event
,
2076 char *filter_expression
,
2077 struct lttng_filter_bytecode
*filter
,
2078 struct lttng_event_exclusion
*exclusion
,
2081 return _cmd_enable_event(session
, domain
, channel_name
, event
,
2082 filter_expression
, filter
, exclusion
, wpipe
, true);
2086 * Command LTTNG_LIST_TRACEPOINTS processed by the client thread.
2088 ssize_t
cmd_list_tracepoints(enum lttng_domain_type domain
,
2089 struct lttng_event
**events
)
2092 ssize_t nb_events
= 0;
2095 case LTTNG_DOMAIN_KERNEL
:
2096 nb_events
= kernel_list_events(kernel_tracer_fd
, events
);
2097 if (nb_events
< 0) {
2098 ret
= LTTNG_ERR_KERN_LIST_FAIL
;
2102 case LTTNG_DOMAIN_UST
:
2103 nb_events
= ust_app_list_events(events
);
2104 if (nb_events
< 0) {
2105 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2109 case LTTNG_DOMAIN_LOG4J
:
2110 case LTTNG_DOMAIN_JUL
:
2111 case LTTNG_DOMAIN_PYTHON
:
2112 nb_events
= agent_list_events(events
, domain
);
2113 if (nb_events
< 0) {
2114 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2119 ret
= LTTNG_ERR_UND
;
2126 /* Return negative value to differentiate return code */
2131 * Command LTTNG_LIST_TRACEPOINT_FIELDS processed by the client thread.
2133 ssize_t
cmd_list_tracepoint_fields(enum lttng_domain_type domain
,
2134 struct lttng_event_field
**fields
)
2137 ssize_t nb_fields
= 0;
2140 case LTTNG_DOMAIN_UST
:
2141 nb_fields
= ust_app_list_event_fields(fields
);
2142 if (nb_fields
< 0) {
2143 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2147 case LTTNG_DOMAIN_KERNEL
:
2148 default: /* fall-through */
2149 ret
= LTTNG_ERR_UND
;
2156 /* Return negative value to differentiate return code */
2160 ssize_t
cmd_list_syscalls(struct lttng_event
**events
)
2162 return syscall_table_list(events
);
2166 * Command LTTNG_LIST_TRACKER_PIDS processed by the client thread.
2168 * Called with session lock held.
2170 ssize_t
cmd_list_tracker_pids(struct ltt_session
*session
,
2171 enum lttng_domain_type domain
, int32_t **pids
)
2174 ssize_t nr_pids
= 0;
2177 case LTTNG_DOMAIN_KERNEL
:
2179 struct ltt_kernel_session
*ksess
;
2181 ksess
= session
->kernel_session
;
2182 nr_pids
= kernel_list_tracker_pids(ksess
, pids
);
2184 ret
= LTTNG_ERR_KERN_LIST_FAIL
;
2189 case LTTNG_DOMAIN_UST
:
2191 struct ltt_ust_session
*usess
;
2193 usess
= session
->ust_session
;
2194 nr_pids
= trace_ust_list_tracker_pids(usess
, pids
);
2196 ret
= LTTNG_ERR_UST_LIST_FAIL
;
2201 case LTTNG_DOMAIN_LOG4J
:
2202 case LTTNG_DOMAIN_JUL
:
2203 case LTTNG_DOMAIN_PYTHON
:
2205 ret
= LTTNG_ERR_UND
;
2212 /* Return negative value to differentiate return code */
2217 * Command LTTNG_START_TRACE processed by the client thread.
2219 * Called with session mutex held.
2221 int cmd_start_trace(struct ltt_session
*session
)
2224 unsigned long nb_chan
= 0;
2225 struct ltt_kernel_session
*ksession
;
2226 struct ltt_ust_session
*usess
;
2230 /* Ease our life a bit ;) */
2231 ksession
= session
->kernel_session
;
2232 usess
= session
->ust_session
;
2234 /* Is the session already started? */
2235 if (session
->active
) {
2236 ret
= LTTNG_ERR_TRACE_ALREADY_STARTED
;
2241 * Starting a session without channel is useless since after that it's not
2242 * possible to enable channel thus inform the client.
2244 if (usess
&& usess
->domain_global
.channels
) {
2245 nb_chan
+= lttng_ht_get_count(usess
->domain_global
.channels
);
2248 nb_chan
+= ksession
->channel_count
;
2251 ret
= LTTNG_ERR_NO_CHANNEL
;
2255 /* Kernel tracing */
2256 if (ksession
!= NULL
) {
2257 ret
= start_kernel_session(ksession
, kernel_tracer_fd
);
2258 if (ret
!= LTTNG_OK
) {
2263 /* Flag session that trace should start automatically */
2266 * Even though the start trace might fail, flag this session active so
2267 * other application coming in are started by default.
2271 ret
= ust_app_start_trace_all(usess
);
2273 ret
= LTTNG_ERR_UST_START_FAIL
;
2278 /* Flag this after a successful start. */
2279 session
->has_been_started
= 1;
2280 session
->active
= 1;
2289 * Command LTTNG_STOP_TRACE processed by the client thread.
2291 int cmd_stop_trace(struct ltt_session
*session
)
2294 struct ltt_kernel_channel
*kchan
;
2295 struct ltt_kernel_session
*ksession
;
2296 struct ltt_ust_session
*usess
;
2301 ksession
= session
->kernel_session
;
2302 usess
= session
->ust_session
;
2304 /* Session is not active. Skip everythong and inform the client. */
2305 if (!session
->active
) {
2306 ret
= LTTNG_ERR_TRACE_ALREADY_STOPPED
;
2311 if (ksession
&& ksession
->active
) {
2312 DBG("Stop kernel tracing");
2314 /* Flush metadata if exist */
2315 if (ksession
->metadata_stream_fd
>= 0) {
2316 ret
= kernel_metadata_flush_buffer(ksession
->metadata_stream_fd
);
2318 ERR("Kernel metadata flush failed");
2322 /* Flush all buffers before stopping */
2323 cds_list_for_each_entry(kchan
, &ksession
->channel_list
.head
, list
) {
2324 ret
= kernel_flush_buffer(kchan
);
2326 ERR("Kernel flush buffer error");
2330 ret
= kernel_stop_session(ksession
);
2332 ret
= LTTNG_ERR_KERN_STOP_FAIL
;
2336 kernel_wait_quiescent(kernel_tracer_fd
);
2338 ksession
->active
= 0;
2341 if (usess
&& usess
->active
) {
2343 * Even though the stop trace might fail, flag this session inactive so
2344 * other application coming in are not started by default.
2348 ret
= ust_app_stop_trace_all(usess
);
2350 ret
= LTTNG_ERR_UST_STOP_FAIL
;
2355 /* Flag inactive after a successful stop. */
2356 session
->active
= 0;
2364 * Command LTTNG_SET_CONSUMER_URI processed by the client thread.
2366 int cmd_set_consumer_uri(struct ltt_session
*session
, size_t nb_uri
,
2367 struct lttng_uri
*uris
)
2370 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
2371 struct ltt_ust_session
*usess
= session
->ust_session
;
2377 /* Can't set consumer URI if the session is active. */
2378 if (session
->active
) {
2379 ret
= LTTNG_ERR_TRACE_ALREADY_STARTED
;
2383 /* Set the "global" consumer URIs */
2384 for (i
= 0; i
< nb_uri
; i
++) {
2385 ret
= add_uri_to_consumer(session
->consumer
,
2386 &uris
[i
], 0, session
->name
);
2387 if (ret
!= LTTNG_OK
) {
2392 /* Set UST session URIs */
2393 if (session
->ust_session
) {
2394 for (i
= 0; i
< nb_uri
; i
++) {
2395 ret
= add_uri_to_consumer(
2396 session
->ust_session
->consumer
,
2397 &uris
[i
], LTTNG_DOMAIN_UST
,
2399 if (ret
!= LTTNG_OK
) {
2405 /* Set kernel session URIs */
2406 if (session
->kernel_session
) {
2407 for (i
= 0; i
< nb_uri
; i
++) {
2408 ret
= add_uri_to_consumer(
2409 session
->kernel_session
->consumer
,
2410 &uris
[i
], LTTNG_DOMAIN_KERNEL
,
2412 if (ret
!= LTTNG_OK
) {
2419 * Make sure to set the session in output mode after we set URI since a
2420 * session can be created without URL (thus flagged in no output mode).
2422 session
->output_traces
= 1;
2424 ksess
->output_traces
= 1;
2428 usess
->output_traces
= 1;
2439 * Command LTTNG_CREATE_SESSION processed by the client thread.
2441 int cmd_create_session_uri(char *name
, struct lttng_uri
*uris
,
2442 size_t nb_uri
, lttng_sock_cred
*creds
, unsigned int live_timer
)
2445 struct ltt_session
*session
;
2451 * Verify if the session already exist
2453 * XXX: There is no need for the session lock list here since the caller
2454 * (process_client_msg) is holding it. We might want to change that so a
2455 * single command does not lock the entire session list.
2457 session
= session_find_by_name(name
);
2458 if (session
!= NULL
) {
2459 ret
= LTTNG_ERR_EXIST_SESS
;
2463 /* Create tracing session in the registry */
2464 ret
= session_create(name
, LTTNG_SOCK_GET_UID_CRED(creds
),
2465 LTTNG_SOCK_GET_GID_CRED(creds
));
2466 if (ret
!= LTTNG_OK
) {
2471 * Get the newly created session pointer back
2473 * XXX: There is no need for the session lock list here since the caller
2474 * (process_client_msg) is holding it. We might want to change that so a
2475 * single command does not lock the entire session list.
2477 session
= session_find_by_name(name
);
2480 session
->live_timer
= live_timer
;
2481 /* Create default consumer output for the session not yet created. */
2482 session
->consumer
= consumer_create_output(CONSUMER_DST_LOCAL
);
2483 if (session
->consumer
== NULL
) {
2484 ret
= LTTNG_ERR_FATAL
;
2485 goto consumer_error
;
2489 ret
= cmd_set_consumer_uri(session
, nb_uri
, uris
);
2490 if (ret
!= LTTNG_OK
) {
2491 goto consumer_error
;
2493 session
->output_traces
= 1;
2495 session
->output_traces
= 0;
2496 DBG2("Session %s created with no output", session
->name
);
2499 session
->consumer
->enabled
= 1;
2504 session_destroy(session
);
2511 * Command LTTNG_CREATE_SESSION_SNAPSHOT processed by the client thread.
2513 int cmd_create_session_snapshot(char *name
, struct lttng_uri
*uris
,
2514 size_t nb_uri
, lttng_sock_cred
*creds
)
2517 struct ltt_session
*session
;
2518 struct snapshot_output
*new_output
= NULL
;
2524 * Create session in no output mode with URIs set to NULL. The uris we've
2525 * received are for a default snapshot output if one.
2527 ret
= cmd_create_session_uri(name
, NULL
, 0, creds
, 0);
2528 if (ret
!= LTTNG_OK
) {
2532 /* Get the newly created session pointer back. This should NEVER fail. */
2533 session
= session_find_by_name(name
);
2536 /* Flag session for snapshot mode. */
2537 session
->snapshot_mode
= 1;
2539 /* Skip snapshot output creation if no URI is given. */
2544 new_output
= snapshot_output_alloc();
2546 ret
= LTTNG_ERR_NOMEM
;
2547 goto error_snapshot_alloc
;
2550 ret
= snapshot_output_init_with_uri(DEFAULT_SNAPSHOT_MAX_SIZE
, NULL
,
2551 uris
, nb_uri
, session
->consumer
, new_output
, &session
->snapshot
);
2553 if (ret
== -ENOMEM
) {
2554 ret
= LTTNG_ERR_NOMEM
;
2556 ret
= LTTNG_ERR_INVALID
;
2558 goto error_snapshot
;
2562 snapshot_add_output(&session
->snapshot
, new_output
);
2569 snapshot_output_destroy(new_output
);
2570 error_snapshot_alloc
:
2571 session_destroy(session
);
2577 * Command LTTNG_DESTROY_SESSION processed by the client thread.
2579 * Called with session lock held.
2581 int cmd_destroy_session(struct ltt_session
*session
, int wpipe
)
2584 struct ltt_ust_session
*usess
;
2585 struct ltt_kernel_session
*ksess
;
2590 usess
= session
->ust_session
;
2591 ksess
= session
->kernel_session
;
2593 /* Clean kernel session teardown */
2594 kernel_destroy_session(ksess
);
2596 /* UST session teardown */
2598 /* Close any relayd session */
2599 consumer_output_send_destroy_relayd(usess
->consumer
);
2601 /* Destroy every UST application related to this session. */
2602 ret
= ust_app_destroy_trace_all(usess
);
2604 ERR("Error in ust_app_destroy_trace_all");
2607 /* Clean up the rest. */
2608 trace_ust_destroy_session(usess
);
2612 * Must notify the kernel thread here to update it's poll set in order to
2613 * remove the channel(s)' fd just destroyed.
2615 ret
= notify_thread_pipe(wpipe
);
2617 PERROR("write kernel poll pipe");
2620 ret
= session_destroy(session
);
2626 * Command LTTNG_CALIBRATE processed by the client thread.
2628 int cmd_calibrate(enum lttng_domain_type domain
,
2629 struct lttng_calibrate
*calibrate
)
2634 case LTTNG_DOMAIN_KERNEL
:
2636 struct lttng_kernel_calibrate kcalibrate
;
2638 switch (calibrate
->type
) {
2639 case LTTNG_CALIBRATE_FUNCTION
:
2641 /* Default and only possible calibrate option. */
2642 kcalibrate
.type
= LTTNG_KERNEL_CALIBRATE_KRETPROBE
;
2646 ret
= kernel_calibrate(kernel_tracer_fd
, &kcalibrate
);
2648 ret
= LTTNG_ERR_KERN_ENABLE_FAIL
;
2653 case LTTNG_DOMAIN_UST
:
2655 struct lttng_ust_calibrate ucalibrate
;
2657 switch (calibrate
->type
) {
2658 case LTTNG_CALIBRATE_FUNCTION
:
2660 /* Default and only possible calibrate option. */
2661 ucalibrate
.type
= LTTNG_UST_CALIBRATE_TRACEPOINT
;
2665 ret
= ust_app_calibrate_glb(&ucalibrate
);
2667 ret
= LTTNG_ERR_UST_CALIBRATE_FAIL
;
2673 ret
= LTTNG_ERR_UND
;
2684 * Command LTTNG_REGISTER_CONSUMER processed by the client thread.
2686 int cmd_register_consumer(struct ltt_session
*session
,
2687 enum lttng_domain_type domain
, const char *sock_path
,
2688 struct consumer_data
*cdata
)
2691 struct consumer_socket
*socket
= NULL
;
2698 case LTTNG_DOMAIN_KERNEL
:
2700 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
2704 /* Can't register a consumer if there is already one */
2705 if (ksess
->consumer_fds_sent
!= 0) {
2706 ret
= LTTNG_ERR_KERN_CONSUMER_FAIL
;
2710 sock
= lttcomm_connect_unix_sock(sock_path
);
2712 ret
= LTTNG_ERR_CONNECT_FAIL
;
2715 cdata
->cmd_sock
= sock
;
2717 socket
= consumer_allocate_socket(&cdata
->cmd_sock
);
2718 if (socket
== NULL
) {
2721 PERROR("close register consumer");
2723 cdata
->cmd_sock
= -1;
2724 ret
= LTTNG_ERR_FATAL
;
2728 socket
->lock
= zmalloc(sizeof(pthread_mutex_t
));
2729 if (socket
->lock
== NULL
) {
2730 PERROR("zmalloc pthread mutex");
2731 ret
= LTTNG_ERR_FATAL
;
2734 pthread_mutex_init(socket
->lock
, NULL
);
2735 socket
->registered
= 1;
2738 consumer_add_socket(socket
, ksess
->consumer
);
2741 pthread_mutex_lock(&cdata
->pid_mutex
);
2743 pthread_mutex_unlock(&cdata
->pid_mutex
);
2748 /* TODO: Userspace tracing */
2749 ret
= LTTNG_ERR_UND
;
2757 consumer_destroy_socket(socket
);
2763 * Command LTTNG_LIST_DOMAINS processed by the client thread.
2765 ssize_t
cmd_list_domains(struct ltt_session
*session
,
2766 struct lttng_domain
**domains
)
2771 struct lttng_ht_iter iter
;
2773 if (session
->kernel_session
!= NULL
) {
2774 DBG3("Listing domains found kernel domain");
2778 if (session
->ust_session
!= NULL
) {
2779 DBG3("Listing domains found UST global domain");
2783 cds_lfht_for_each_entry(session
->ust_session
->agents
->ht
, &iter
.iter
,
2785 if (agt
->being_used
) {
2796 *domains
= zmalloc(nb_dom
* sizeof(struct lttng_domain
));
2797 if (*domains
== NULL
) {
2798 ret
= LTTNG_ERR_FATAL
;
2802 if (session
->kernel_session
!= NULL
) {
2803 (*domains
)[index
].type
= LTTNG_DOMAIN_KERNEL
;
2805 /* Kernel session buffer type is always GLOBAL */
2806 (*domains
)[index
].buf_type
= LTTNG_BUFFER_GLOBAL
;
2811 if (session
->ust_session
!= NULL
) {
2812 (*domains
)[index
].type
= LTTNG_DOMAIN_UST
;
2813 (*domains
)[index
].buf_type
= session
->ust_session
->buffer_type
;
2817 cds_lfht_for_each_entry(session
->ust_session
->agents
->ht
, &iter
.iter
,
2819 if (agt
->being_used
) {
2820 (*domains
)[index
].type
= agt
->domain
;
2821 (*domains
)[index
].buf_type
= session
->ust_session
->buffer_type
;
2831 /* Return negative value to differentiate return code */
2837 * Command LTTNG_LIST_CHANNELS processed by the client thread.
2839 ssize_t
cmd_list_channels(enum lttng_domain_type domain
,
2840 struct ltt_session
*session
, struct lttng_channel
**channels
)
2842 ssize_t nb_chan
= 0, payload_size
= 0, ret
;
2845 case LTTNG_DOMAIN_KERNEL
:
2846 if (session
->kernel_session
!= NULL
) {
2847 nb_chan
= session
->kernel_session
->channel_count
;
2849 DBG3("Number of kernel channels %zd", nb_chan
);
2851 ret
= -LTTNG_ERR_KERN_CHAN_NOT_FOUND
;
2855 case LTTNG_DOMAIN_UST
:
2856 if (session
->ust_session
!= NULL
) {
2858 nb_chan
= lttng_ht_get_count(
2859 session
->ust_session
->domain_global
.channels
);
2862 DBG3("Number of UST global channels %zd", nb_chan
);
2864 ret
= -LTTNG_ERR_UST_CHAN_NOT_FOUND
;
2869 ret
= -LTTNG_ERR_UND
;
2874 const size_t channel_size
= sizeof(struct lttng_channel
) +
2875 sizeof(struct lttcomm_channel_extended
);
2876 struct lttcomm_channel_extended
*channel_exts
;
2878 payload_size
= nb_chan
* channel_size
;
2879 *channels
= zmalloc(payload_size
);
2880 if (*channels
== NULL
) {
2881 ret
= -LTTNG_ERR_FATAL
;
2885 channel_exts
= ((void *) *channels
) +
2886 (nb_chan
* sizeof(struct lttng_channel
));
2887 list_lttng_channels(domain
, session
, *channels
, channel_exts
);
2898 * Command LTTNG_LIST_EVENTS processed by the client thread.
2900 ssize_t
cmd_list_events(enum lttng_domain_type domain
,
2901 struct ltt_session
*session
, char *channel_name
,
2902 struct lttng_event
**events
, size_t *total_size
)
2905 ssize_t nb_event
= 0;
2908 case LTTNG_DOMAIN_KERNEL
:
2909 if (session
->kernel_session
!= NULL
) {
2910 nb_event
= list_lttng_kernel_events(channel_name
,
2911 session
->kernel_session
, events
,
2915 case LTTNG_DOMAIN_UST
:
2917 if (session
->ust_session
!= NULL
) {
2918 nb_event
= list_lttng_ust_global_events(channel_name
,
2919 &session
->ust_session
->domain_global
, events
,
2924 case LTTNG_DOMAIN_LOG4J
:
2925 case LTTNG_DOMAIN_JUL
:
2926 case LTTNG_DOMAIN_PYTHON
:
2927 if (session
->ust_session
) {
2928 struct lttng_ht_iter iter
;
2932 cds_lfht_for_each_entry(session
->ust_session
->agents
->ht
,
2933 &iter
.iter
, agt
, node
.node
) {
2934 if (agt
->domain
== domain
) {
2935 nb_event
= list_lttng_agent_events(
2945 ret
= LTTNG_ERR_UND
;
2952 /* Return negative value to differentiate return code */
2957 * Using the session list, filled a lttng_session array to send back to the
2958 * client for session listing.
2960 * The session list lock MUST be acquired before calling this function. Use
2961 * session_lock_list() and session_unlock_list().
2963 void cmd_list_lttng_sessions(struct lttng_session
*sessions
, uid_t uid
,
2968 struct ltt_session
*session
;
2969 struct ltt_session_list
*list
= session_get_list();
2971 DBG("Getting all available session for UID %d GID %d",
2974 * Iterate over session list and append data after the control struct in
2977 cds_list_for_each_entry(session
, &list
->head
, list
) {
2979 * Only list the sessions the user can control.
2981 if (!session_access_ok(session
, uid
, gid
)) {
2985 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
2986 struct ltt_ust_session
*usess
= session
->ust_session
;
2988 if (session
->consumer
->type
== CONSUMER_DST_NET
||
2989 (ksess
&& ksess
->consumer
->type
== CONSUMER_DST_NET
) ||
2990 (usess
&& usess
->consumer
->type
== CONSUMER_DST_NET
)) {
2991 ret
= build_network_session_path(sessions
[i
].path
,
2992 sizeof(sessions
[i
].path
), session
);
2994 ret
= snprintf(sessions
[i
].path
, sizeof(sessions
[i
].path
), "%s",
2995 session
->consumer
->dst
.trace_path
);
2998 PERROR("snprintf session path");
3002 strncpy(sessions
[i
].name
, session
->name
, NAME_MAX
);
3003 sessions
[i
].name
[NAME_MAX
- 1] = '\0';
3004 sessions
[i
].enabled
= session
->active
;
3005 sessions
[i
].snapshot_mode
= session
->snapshot_mode
;
3006 sessions
[i
].live_timer_interval
= session
->live_timer
;
3012 * Command LTTNG_DATA_PENDING returning 0 if the data is NOT pending meaning
3013 * ready for trace analysis (or any kind of reader) or else 1 for pending data.
3015 int cmd_data_pending(struct ltt_session
*session
)
3018 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3019 struct ltt_ust_session
*usess
= session
->ust_session
;
3023 /* Session MUST be stopped to ask for data availability. */
3024 if (session
->active
) {
3025 ret
= LTTNG_ERR_SESSION_STARTED
;
3029 * If stopped, just make sure we've started before else the above call
3030 * will always send that there is data pending.
3032 * The consumer assumes that when the data pending command is received,
3033 * the trace has been started before or else no output data is written
3034 * by the streams which is a condition for data pending. So, this is
3035 * *VERY* important that we don't ask the consumer before a start
3038 if (!session
->has_been_started
) {
3044 if (ksess
&& ksess
->consumer
) {
3045 ret
= consumer_is_data_pending(ksess
->id
, ksess
->consumer
);
3047 /* Data is still being extracted for the kernel. */
3052 if (usess
&& usess
->consumer
) {
3053 ret
= consumer_is_data_pending(usess
->id
, usess
->consumer
);
3055 /* Data is still being extracted for the kernel. */
3060 /* Data is ready to be read by a viewer */
3068 * Command LTTNG_SNAPSHOT_ADD_OUTPUT from the lttng ctl library.
3070 * Return LTTNG_OK on success or else a LTTNG_ERR code.
3072 int cmd_snapshot_add_output(struct ltt_session
*session
,
3073 struct lttng_snapshot_output
*output
, uint32_t *id
)
3076 struct snapshot_output
*new_output
;
3081 DBG("Cmd snapshot add output for session %s", session
->name
);
3084 * Permission denied to create an output if the session is not
3085 * set in no output mode.
3087 if (session
->output_traces
) {
3088 ret
= LTTNG_ERR_EPERM
;
3092 /* Only one output is allowed until we have the "tee" feature. */
3093 if (session
->snapshot
.nb_output
== 1) {
3094 ret
= LTTNG_ERR_SNAPSHOT_OUTPUT_EXIST
;
3098 new_output
= snapshot_output_alloc();
3100 ret
= LTTNG_ERR_NOMEM
;
3104 ret
= snapshot_output_init(output
->max_size
, output
->name
,
3105 output
->ctrl_url
, output
->data_url
, session
->consumer
, new_output
,
3106 &session
->snapshot
);
3108 if (ret
== -ENOMEM
) {
3109 ret
= LTTNG_ERR_NOMEM
;
3111 ret
= LTTNG_ERR_INVALID
;
3117 snapshot_add_output(&session
->snapshot
, new_output
);
3119 *id
= new_output
->id
;
3126 snapshot_output_destroy(new_output
);
3132 * Command LTTNG_SNAPSHOT_DEL_OUTPUT from lib lttng ctl.
3134 * Return LTTNG_OK on success or else a LTTNG_ERR code.
3136 int cmd_snapshot_del_output(struct ltt_session
*session
,
3137 struct lttng_snapshot_output
*output
)
3140 struct snapshot_output
*sout
= NULL
;
3148 * Permission denied to create an output if the session is not
3149 * set in no output mode.
3151 if (session
->output_traces
) {
3152 ret
= LTTNG_ERR_EPERM
;
3157 DBG("Cmd snapshot del output id %" PRIu32
" for session %s", output
->id
,
3159 sout
= snapshot_find_output_by_id(output
->id
, &session
->snapshot
);
3160 } else if (*output
->name
!= '\0') {
3161 DBG("Cmd snapshot del output name %s for session %s", output
->name
,
3163 sout
= snapshot_find_output_by_name(output
->name
, &session
->snapshot
);
3166 ret
= LTTNG_ERR_INVALID
;
3170 snapshot_delete_output(&session
->snapshot
, sout
);
3171 snapshot_output_destroy(sout
);
3180 * Command LTTNG_SNAPSHOT_LIST_OUTPUT from lib lttng ctl.
3182 * If no output is available, outputs is untouched and 0 is returned.
3184 * Return the size of the newly allocated outputs or a negative LTTNG_ERR code.
3186 ssize_t
cmd_snapshot_list_outputs(struct ltt_session
*session
,
3187 struct lttng_snapshot_output
**outputs
)
3190 struct lttng_snapshot_output
*list
= NULL
;
3191 struct lttng_ht_iter iter
;
3192 struct snapshot_output
*output
;
3197 DBG("Cmd snapshot list outputs for session %s", session
->name
);
3200 * Permission denied to create an output if the session is not
3201 * set in no output mode.
3203 if (session
->output_traces
) {
3204 ret
= -LTTNG_ERR_EPERM
;
3208 if (session
->snapshot
.nb_output
== 0) {
3213 list
= zmalloc(session
->snapshot
.nb_output
* sizeof(*list
));
3215 ret
= -LTTNG_ERR_NOMEM
;
3219 /* Copy list from session to the new list object. */
3221 cds_lfht_for_each_entry(session
->snapshot
.output_ht
->ht
, &iter
.iter
,
3222 output
, node
.node
) {
3223 assert(output
->consumer
);
3224 list
[idx
].id
= output
->id
;
3225 list
[idx
].max_size
= output
->max_size
;
3226 strncpy(list
[idx
].name
, output
->name
, sizeof(list
[idx
].name
));
3227 if (output
->consumer
->type
== CONSUMER_DST_LOCAL
) {
3228 strncpy(list
[idx
].ctrl_url
, output
->consumer
->dst
.trace_path
,
3229 sizeof(list
[idx
].ctrl_url
));
3232 ret
= uri_to_str_url(&output
->consumer
->dst
.net
.control
,
3233 list
[idx
].ctrl_url
, sizeof(list
[idx
].ctrl_url
));
3235 ret
= -LTTNG_ERR_NOMEM
;
3240 ret
= uri_to_str_url(&output
->consumer
->dst
.net
.data
,
3241 list
[idx
].data_url
, sizeof(list
[idx
].data_url
));
3243 ret
= -LTTNG_ERR_NOMEM
;
3252 ret
= session
->snapshot
.nb_output
;
3260 * Send relayd sockets from snapshot output to consumer. Ignore request if the
3261 * snapshot output is *not* set with a remote destination.
3263 * Return 0 on success or a LTTNG_ERR code.
3265 static int set_relayd_for_snapshot(struct consumer_output
*consumer
,
3266 struct snapshot_output
*snap_output
, struct ltt_session
*session
)
3269 struct lttng_ht_iter iter
;
3270 struct consumer_socket
*socket
;
3273 assert(snap_output
);
3276 DBG2("Set relayd object from snapshot output");
3278 /* Ignore if snapshot consumer output is not network. */
3279 if (snap_output
->consumer
->type
!= CONSUMER_DST_NET
) {
3284 * For each consumer socket, create and send the relayd object of the
3288 cds_lfht_for_each_entry(snap_output
->consumer
->socks
->ht
, &iter
.iter
,
3289 socket
, node
.node
) {
3290 ret
= send_consumer_relayd_sockets(0, session
->id
,
3291 snap_output
->consumer
, socket
,
3292 session
->name
, session
->hostname
,
3293 session
->live_timer
);
3294 if (ret
!= LTTNG_OK
) {
3306 * Record a kernel snapshot.
3308 * Return LTTNG_OK on success or a LTTNG_ERR code.
3310 static int record_kernel_snapshot(struct ltt_kernel_session
*ksess
,
3311 struct snapshot_output
*output
, struct ltt_session
*session
,
3312 int wait
, uint64_t nb_packets_per_stream
)
3320 /* Get the datetime for the snapshot output directory. */
3321 ret
= utils_get_current_time_str("%Y%m%d-%H%M%S", output
->datetime
,
3322 sizeof(output
->datetime
));
3324 ret
= LTTNG_ERR_INVALID
;
3329 * Copy kernel session sockets so we can communicate with the right
3330 * consumer for the snapshot record command.
3332 ret
= consumer_copy_sockets(output
->consumer
, ksess
->consumer
);
3334 ret
= LTTNG_ERR_NOMEM
;
3338 ret
= set_relayd_for_snapshot(ksess
->consumer
, output
, session
);
3339 if (ret
!= LTTNG_OK
) {
3340 goto error_snapshot
;
3343 ret
= kernel_snapshot_record(ksess
, output
, wait
, nb_packets_per_stream
);
3344 if (ret
!= LTTNG_OK
) {
3345 goto error_snapshot
;
3352 /* Clean up copied sockets so this output can use some other later on. */
3353 consumer_destroy_output_sockets(output
->consumer
);
3360 * Record a UST snapshot.
3362 * Return 0 on success or a LTTNG_ERR error code.
3364 static int record_ust_snapshot(struct ltt_ust_session
*usess
,
3365 struct snapshot_output
*output
, struct ltt_session
*session
,
3366 int wait
, uint64_t nb_packets_per_stream
)
3374 /* Get the datetime for the snapshot output directory. */
3375 ret
= utils_get_current_time_str("%Y%m%d-%H%M%S", output
->datetime
,
3376 sizeof(output
->datetime
));
3378 ret
= LTTNG_ERR_INVALID
;
3383 * Copy UST session sockets so we can communicate with the right
3384 * consumer for the snapshot record command.
3386 ret
= consumer_copy_sockets(output
->consumer
, usess
->consumer
);
3388 ret
= LTTNG_ERR_NOMEM
;
3392 ret
= set_relayd_for_snapshot(usess
->consumer
, output
, session
);
3393 if (ret
!= LTTNG_OK
) {
3394 goto error_snapshot
;
3397 ret
= ust_app_snapshot_record(usess
, output
, wait
, nb_packets_per_stream
);
3401 ret
= LTTNG_ERR_INVALID
;
3404 ret
= LTTNG_ERR_SNAPSHOT_NODATA
;
3407 ret
= LTTNG_ERR_SNAPSHOT_FAIL
;
3410 goto error_snapshot
;
3416 /* Clean up copied sockets so this output can use some other later on. */
3417 consumer_destroy_output_sockets(output
->consumer
);
3423 uint64_t get_session_size_one_more_packet_per_stream(struct ltt_session
*session
,
3424 uint64_t cur_nr_packets
)
3426 uint64_t tot_size
= 0;
3428 if (session
->kernel_session
) {
3429 struct ltt_kernel_channel
*chan
;
3430 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3432 cds_list_for_each_entry(chan
, &ksess
->channel_list
.head
, list
) {
3433 if (cur_nr_packets
>= chan
->channel
->attr
.num_subbuf
) {
3435 * Don't take channel into account if we
3436 * already grab all its packets.
3440 tot_size
+= chan
->channel
->attr
.subbuf_size
3441 * chan
->stream_count
;
3445 if (session
->ust_session
) {
3446 struct ltt_ust_session
*usess
= session
->ust_session
;
3448 tot_size
+= ust_app_get_size_one_more_packet_per_stream(usess
,
3456 * Calculate the number of packets we can grab from each stream that
3457 * fits within the overall snapshot max size.
3459 * Returns -1 on error, 0 means infinite number of packets, else > 0 is
3460 * the number of packets per stream.
3462 * TODO: this approach is not perfect: we consider the worse case
3463 * (packet filling the sub-buffers) as an upper bound, but we could do
3464 * better if we do this calculation while we actually grab the packet
3465 * content: we would know how much padding we don't actually store into
3468 * This algorithm is currently bounded by the number of packets per
3471 * Since we call this algorithm before actually grabbing the data, it's
3472 * an approximation: for instance, applications could appear/disappear
3473 * in between this call and actually grabbing data.
3476 int64_t get_session_nb_packets_per_stream(struct ltt_session
*session
, uint64_t max_size
)
3479 uint64_t cur_nb_packets
= 0;
3482 return 0; /* Infinite */
3485 size_left
= max_size
;
3487 uint64_t one_more_packet_tot_size
;
3489 one_more_packet_tot_size
= get_session_size_one_more_packet_per_stream(session
,
3491 if (!one_more_packet_tot_size
) {
3492 /* We are already grabbing all packets. */
3495 size_left
-= one_more_packet_tot_size
;
3496 if (size_left
< 0) {
3501 if (!cur_nb_packets
) {
3502 /* Not enough room to grab one packet of each stream, error. */
3505 return cur_nb_packets
;
3509 * Command LTTNG_SNAPSHOT_RECORD from lib lttng ctl.
3511 * The wait parameter is ignored so this call always wait for the snapshot to
3512 * complete before returning.
3514 * Return LTTNG_OK on success or else a LTTNG_ERR code.
3516 int cmd_snapshot_record(struct ltt_session
*session
,
3517 struct lttng_snapshot_output
*output
, int wait
)
3520 unsigned int use_tmp_output
= 0;
3521 struct snapshot_output tmp_output
;
3522 unsigned int snapshot_success
= 0;
3527 DBG("Cmd snapshot record for session %s", session
->name
);
3530 * Permission denied to create an output if the session is not
3531 * set in no output mode.
3533 if (session
->output_traces
) {
3534 ret
= LTTNG_ERR_EPERM
;
3538 /* The session needs to be started at least once. */
3539 if (!session
->has_been_started
) {
3540 ret
= LTTNG_ERR_START_SESSION_ONCE
;
3544 /* Use temporary output for the session. */
3545 if (*output
->ctrl_url
!= '\0') {
3546 ret
= snapshot_output_init(output
->max_size
, output
->name
,
3547 output
->ctrl_url
, output
->data_url
, session
->consumer
,
3550 if (ret
== -ENOMEM
) {
3551 ret
= LTTNG_ERR_NOMEM
;
3553 ret
= LTTNG_ERR_INVALID
;
3557 /* Use the global session count for the temporary snapshot. */
3558 tmp_output
.nb_snapshot
= session
->snapshot
.nb_snapshot
;
3562 if (session
->kernel_session
) {
3563 struct ltt_kernel_session
*ksess
= session
->kernel_session
;
3565 if (use_tmp_output
) {
3566 int64_t nb_packets_per_stream
;
3568 nb_packets_per_stream
= get_session_nb_packets_per_stream(session
,
3569 tmp_output
.max_size
);
3570 if (nb_packets_per_stream
< 0) {
3571 ret
= LTTNG_ERR_MAX_SIZE_INVALID
;
3574 ret
= record_kernel_snapshot(ksess
, &tmp_output
, session
,
3575 wait
, nb_packets_per_stream
);
3576 if (ret
!= LTTNG_OK
) {
3579 snapshot_success
= 1;
3581 struct snapshot_output
*sout
;
3582 struct lttng_ht_iter iter
;
3585 cds_lfht_for_each_entry(session
->snapshot
.output_ht
->ht
,
3586 &iter
.iter
, sout
, node
.node
) {
3587 int64_t nb_packets_per_stream
;
3590 * Make a local copy of the output and assign the possible
3591 * temporary value given by the caller.
3593 memset(&tmp_output
, 0, sizeof(tmp_output
));
3594 memcpy(&tmp_output
, sout
, sizeof(tmp_output
));
3596 if (output
->max_size
!= (uint64_t) -1ULL) {
3597 tmp_output
.max_size
= output
->max_size
;
3600 nb_packets_per_stream
= get_session_nb_packets_per_stream(session
,
3601 tmp_output
.max_size
);
3602 if (nb_packets_per_stream
< 0) {
3603 ret
= LTTNG_ERR_MAX_SIZE_INVALID
;
3607 /* Use temporary name. */
3608 if (*output
->name
!= '\0') {
3609 strncpy(tmp_output
.name
, output
->name
,
3610 sizeof(tmp_output
.name
));
3613 tmp_output
.nb_snapshot
= session
->snapshot
.nb_snapshot
;
3615 ret
= record_kernel_snapshot(ksess
, &tmp_output
,
3616 session
, wait
, nb_packets_per_stream
);
3617 if (ret
!= LTTNG_OK
) {
3621 snapshot_success
= 1;
3627 if (session
->ust_session
) {
3628 struct ltt_ust_session
*usess
= session
->ust_session
;
3630 if (use_tmp_output
) {
3631 int64_t nb_packets_per_stream
;
3633 nb_packets_per_stream
= get_session_nb_packets_per_stream(session
,
3634 tmp_output
.max_size
);
3635 if (nb_packets_per_stream
< 0) {
3636 ret
= LTTNG_ERR_MAX_SIZE_INVALID
;
3639 ret
= record_ust_snapshot(usess
, &tmp_output
, session
,
3640 wait
, nb_packets_per_stream
);
3641 if (ret
!= LTTNG_OK
) {
3644 snapshot_success
= 1;
3646 struct snapshot_output
*sout
;
3647 struct lttng_ht_iter iter
;
3650 cds_lfht_for_each_entry(session
->snapshot
.output_ht
->ht
,
3651 &iter
.iter
, sout
, node
.node
) {
3652 int64_t nb_packets_per_stream
;
3655 * Make a local copy of the output and assign the possible
3656 * temporary value given by the caller.
3658 memset(&tmp_output
, 0, sizeof(tmp_output
));
3659 memcpy(&tmp_output
, sout
, sizeof(tmp_output
));
3661 if (output
->max_size
!= (uint64_t) -1ULL) {
3662 tmp_output
.max_size
= output
->max_size
;
3665 nb_packets_per_stream
= get_session_nb_packets_per_stream(session
,
3666 tmp_output
.max_size
);
3667 if (nb_packets_per_stream
< 0) {
3668 ret
= LTTNG_ERR_MAX_SIZE_INVALID
;
3673 /* Use temporary name. */
3674 if (*output
->name
!= '\0') {
3675 strncpy(tmp_output
.name
, output
->name
,
3676 sizeof(tmp_output
.name
));
3679 tmp_output
.nb_snapshot
= session
->snapshot
.nb_snapshot
;
3681 ret
= record_ust_snapshot(usess
, &tmp_output
, session
,
3682 wait
, nb_packets_per_stream
);
3683 if (ret
!= LTTNG_OK
) {
3687 snapshot_success
= 1;
3693 if (snapshot_success
) {
3694 session
->snapshot
.nb_snapshot
++;
3696 ret
= LTTNG_ERR_SNAPSHOT_FAIL
;
3704 * Command LTTNG_SET_SESSION_SHM_PATH processed by the client thread.
3706 int cmd_set_session_shm_path(struct ltt_session
*session
,
3707 const char *shm_path
)
3713 * Can only set shm path before session is started.
3715 if (session
->has_been_started
) {
3716 return LTTNG_ERR_SESSION_STARTED
;
3719 strncpy(session
->shm_path
, shm_path
,
3720 sizeof(session
->shm_path
));
3721 session
->shm_path
[sizeof(session
->shm_path
) - 1] = '\0';
3727 * Init command subsystem.
3732 * Set network sequence index to 1 for streams to match a relayd
3733 * socket on the consumer side.
3735 pthread_mutex_lock(&relayd_net_seq_idx_lock
);
3736 relayd_net_seq_idx
= 1;
3737 pthread_mutex_unlock(&relayd_net_seq_idx_lock
);
3739 DBG("Command subsystem initialized");