Add exclusion data to cmd_enable_event
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
1 /*
2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #define _GNU_SOURCE
19 #include <assert.h>
20 #include <inttypes.h>
21 #include <urcu/list.h>
22 #include <urcu/uatomic.h>
23
24 #include <common/defaults.h>
25 #include <common/common.h>
26 #include <common/sessiond-comm/sessiond-comm.h>
27 #include <common/relayd/relayd.h>
28 #include <common/utils.h>
29
30 #include "channel.h"
31 #include "consumer.h"
32 #include "event.h"
33 #include "health-sessiond.h"
34 #include "kernel.h"
35 #include "kernel-consumer.h"
36 #include "lttng-sessiond.h"
37 #include "utils.h"
38
39 #include "cmd.h"
40
41 /*
42 * Used to keep a unique index for each relayd socket created where this value
43 * is associated with streams on the consumer so it can match the right relayd
44 * to send to. It must be accessed with the relayd_net_seq_idx_lock
45 * held.
46 */
47 static pthread_mutex_t relayd_net_seq_idx_lock = PTHREAD_MUTEX_INITIALIZER;
48 static uint64_t relayd_net_seq_idx;
49
50 /*
51 * Create a session path used by list_lttng_sessions for the case that the
52 * session consumer is on the network.
53 */
54 static int build_network_session_path(char *dst, size_t size,
55 struct ltt_session *session)
56 {
57 int ret, kdata_port, udata_port;
58 struct lttng_uri *kuri = NULL, *uuri = NULL, *uri = NULL;
59 char tmp_uurl[PATH_MAX], tmp_urls[PATH_MAX];
60
61 assert(session);
62 assert(dst);
63
64 memset(tmp_urls, 0, sizeof(tmp_urls));
65 memset(tmp_uurl, 0, sizeof(tmp_uurl));
66
67 kdata_port = udata_port = DEFAULT_NETWORK_DATA_PORT;
68
69 if (session->kernel_session && session->kernel_session->consumer) {
70 kuri = &session->kernel_session->consumer->dst.net.control;
71 kdata_port = session->kernel_session->consumer->dst.net.data.port;
72 }
73
74 if (session->ust_session && session->ust_session->consumer) {
75 uuri = &session->ust_session->consumer->dst.net.control;
76 udata_port = session->ust_session->consumer->dst.net.data.port;
77 }
78
79 if (uuri == NULL && kuri == NULL) {
80 uri = &session->consumer->dst.net.control;
81 kdata_port = session->consumer->dst.net.data.port;
82 } else if (kuri && uuri) {
83 ret = uri_compare(kuri, uuri);
84 if (ret) {
85 /* Not Equal */
86 uri = kuri;
87 /* Build uuri URL string */
88 ret = uri_to_str_url(uuri, tmp_uurl, sizeof(tmp_uurl));
89 if (ret < 0) {
90 goto error;
91 }
92 } else {
93 uri = kuri;
94 }
95 } else if (kuri && uuri == NULL) {
96 uri = kuri;
97 } else if (uuri && kuri == NULL) {
98 uri = uuri;
99 }
100
101 ret = uri_to_str_url(uri, tmp_urls, sizeof(tmp_urls));
102 if (ret < 0) {
103 goto error;
104 }
105
106 /*
107 * Do we have a UST url set. If yes, this means we have both kernel and UST
108 * to print.
109 */
110 if (*tmp_uurl != '\0') {
111 ret = snprintf(dst, size, "[K]: %s [data: %d] -- [U]: %s [data: %d]",
112 tmp_urls, kdata_port, tmp_uurl, udata_port);
113 } else {
114 int dport;
115 if (kuri || (!kuri && !uuri)) {
116 dport = kdata_port;
117 } else {
118 /* No kernel URI, use the UST port. */
119 dport = udata_port;
120 }
121 ret = snprintf(dst, size, "%s [data: %d]", tmp_urls, dport);
122 }
123
124 error:
125 return ret;
126 }
127
128 /*
129 * Fill lttng_channel array of all channels.
130 */
131 static void list_lttng_channels(int domain, struct ltt_session *session,
132 struct lttng_channel *channels)
133 {
134 int i = 0;
135 struct ltt_kernel_channel *kchan;
136
137 DBG("Listing channels for session %s", session->name);
138
139 switch (domain) {
140 case LTTNG_DOMAIN_KERNEL:
141 /* Kernel channels */
142 if (session->kernel_session != NULL) {
143 cds_list_for_each_entry(kchan,
144 &session->kernel_session->channel_list.head, list) {
145 /* Copy lttng_channel struct to array */
146 memcpy(&channels[i], kchan->channel, sizeof(struct lttng_channel));
147 channels[i].enabled = kchan->enabled;
148 i++;
149 }
150 }
151 break;
152 case LTTNG_DOMAIN_UST:
153 {
154 struct lttng_ht_iter iter;
155 struct ltt_ust_channel *uchan;
156
157 rcu_read_lock();
158 cds_lfht_for_each_entry(session->ust_session->domain_global.channels->ht,
159 &iter.iter, uchan, node.node) {
160 strncpy(channels[i].name, uchan->name, LTTNG_SYMBOL_NAME_LEN);
161 channels[i].attr.overwrite = uchan->attr.overwrite;
162 channels[i].attr.subbuf_size = uchan->attr.subbuf_size;
163 channels[i].attr.num_subbuf = uchan->attr.num_subbuf;
164 channels[i].attr.switch_timer_interval =
165 uchan->attr.switch_timer_interval;
166 channels[i].attr.read_timer_interval =
167 uchan->attr.read_timer_interval;
168 channels[i].enabled = uchan->enabled;
169 switch (uchan->attr.output) {
170 case LTTNG_UST_MMAP:
171 default:
172 channels[i].attr.output = LTTNG_EVENT_MMAP;
173 break;
174 }
175 i++;
176 }
177 rcu_read_unlock();
178 break;
179 }
180 default:
181 break;
182 }
183 }
184
185 /*
186 * Create a list of JUL domain events.
187 *
188 * Return number of events in list on success or else a negative value.
189 */
190 static int list_lttng_jul_events(struct jul_domain *dom,
191 struct lttng_event **events)
192 {
193 int i = 0, ret = 0;
194 unsigned int nb_event = 0;
195 struct jul_event *event;
196 struct lttng_event *tmp_events;
197 struct lttng_ht_iter iter;
198
199 assert(dom);
200 assert(events);
201
202 DBG3("Listing JUL events");
203
204 nb_event = lttng_ht_get_count(dom->events);
205 if (nb_event == 0) {
206 ret = nb_event;
207 goto error;
208 }
209
210 tmp_events = zmalloc(nb_event * sizeof(*tmp_events));
211 if (!tmp_events) {
212 PERROR("zmalloc JUL events session");
213 ret = -LTTNG_ERR_FATAL;
214 goto error;
215 }
216
217 rcu_read_lock();
218 cds_lfht_for_each_entry(dom->events->ht, &iter.iter, event, node.node) {
219 strncpy(tmp_events[i].name, event->name, sizeof(tmp_events[i].name));
220 tmp_events[i].name[sizeof(tmp_events[i].name) - 1] = '\0';
221 tmp_events[i].enabled = event->enabled;
222 i++;
223 }
224 rcu_read_unlock();
225
226 *events = tmp_events;
227 ret = nb_event;
228
229 error:
230 assert(nb_event == i);
231 return ret;
232 }
233
234 /*
235 * Create a list of ust global domain events.
236 */
237 static int list_lttng_ust_global_events(char *channel_name,
238 struct ltt_ust_domain_global *ust_global, struct lttng_event **events)
239 {
240 int i = 0, ret = 0;
241 unsigned int nb_event = 0;
242 struct lttng_ht_iter iter;
243 struct lttng_ht_node_str *node;
244 struct ltt_ust_channel *uchan;
245 struct ltt_ust_event *uevent;
246 struct lttng_event *tmp;
247
248 DBG("Listing UST global events for channel %s", channel_name);
249
250 rcu_read_lock();
251
252 lttng_ht_lookup(ust_global->channels, (void *)channel_name, &iter);
253 node = lttng_ht_iter_get_node_str(&iter);
254 if (node == NULL) {
255 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
256 goto error;
257 }
258
259 uchan = caa_container_of(&node->node, struct ltt_ust_channel, node.node);
260
261 nb_event += lttng_ht_get_count(uchan->events);
262
263 if (nb_event == 0) {
264 ret = nb_event;
265 goto error;
266 }
267
268 DBG3("Listing UST global %d events", nb_event);
269
270 tmp = zmalloc(nb_event * sizeof(struct lttng_event));
271 if (tmp == NULL) {
272 ret = LTTNG_ERR_FATAL;
273 goto error;
274 }
275
276 cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, node.node) {
277 strncpy(tmp[i].name, uevent->attr.name, LTTNG_SYMBOL_NAME_LEN);
278 tmp[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
279 tmp[i].enabled = uevent->enabled;
280
281 switch (uevent->attr.instrumentation) {
282 case LTTNG_UST_TRACEPOINT:
283 tmp[i].type = LTTNG_EVENT_TRACEPOINT;
284 break;
285 case LTTNG_UST_PROBE:
286 tmp[i].type = LTTNG_EVENT_PROBE;
287 break;
288 case LTTNG_UST_FUNCTION:
289 tmp[i].type = LTTNG_EVENT_FUNCTION;
290 break;
291 }
292
293 tmp[i].loglevel = uevent->attr.loglevel;
294 switch (uevent->attr.loglevel_type) {
295 case LTTNG_UST_LOGLEVEL_ALL:
296 tmp[i].loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
297 break;
298 case LTTNG_UST_LOGLEVEL_RANGE:
299 tmp[i].loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE;
300 break;
301 case LTTNG_UST_LOGLEVEL_SINGLE:
302 tmp[i].loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE;
303 break;
304 }
305 if (uevent->filter) {
306 tmp[i].filter = 1;
307 }
308 i++;
309 }
310
311 ret = nb_event;
312 *events = tmp;
313
314 error:
315 rcu_read_unlock();
316 return ret;
317 }
318
319 /*
320 * Fill lttng_event array of all kernel events in the channel.
321 */
322 static int list_lttng_kernel_events(char *channel_name,
323 struct ltt_kernel_session *kernel_session, struct lttng_event **events)
324 {
325 int i = 0, ret;
326 unsigned int nb_event;
327 struct ltt_kernel_event *event;
328 struct ltt_kernel_channel *kchan;
329
330 kchan = trace_kernel_get_channel_by_name(channel_name, kernel_session);
331 if (kchan == NULL) {
332 ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND;
333 goto error;
334 }
335
336 nb_event = kchan->event_count;
337
338 DBG("Listing events for channel %s", kchan->channel->name);
339
340 if (nb_event == 0) {
341 goto end;
342 }
343
344 *events = zmalloc(nb_event * sizeof(struct lttng_event));
345 if (*events == NULL) {
346 ret = LTTNG_ERR_FATAL;
347 goto error;
348 }
349
350 /* Kernel channels */
351 cds_list_for_each_entry(event, &kchan->events_list.head , list) {
352 strncpy((*events)[i].name, event->event->name, LTTNG_SYMBOL_NAME_LEN);
353 (*events)[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
354 (*events)[i].enabled = event->enabled;
355
356 switch (event->event->instrumentation) {
357 case LTTNG_KERNEL_TRACEPOINT:
358 (*events)[i].type = LTTNG_EVENT_TRACEPOINT;
359 break;
360 case LTTNG_KERNEL_KRETPROBE:
361 (*events)[i].type = LTTNG_EVENT_FUNCTION;
362 memcpy(&(*events)[i].attr.probe, &event->event->u.kprobe,
363 sizeof(struct lttng_kernel_kprobe));
364 break;
365 case LTTNG_KERNEL_KPROBE:
366 (*events)[i].type = LTTNG_EVENT_PROBE;
367 memcpy(&(*events)[i].attr.probe, &event->event->u.kprobe,
368 sizeof(struct lttng_kernel_kprobe));
369 break;
370 case LTTNG_KERNEL_FUNCTION:
371 (*events)[i].type = LTTNG_EVENT_FUNCTION;
372 memcpy(&((*events)[i].attr.ftrace), &event->event->u.ftrace,
373 sizeof(struct lttng_kernel_function));
374 break;
375 case LTTNG_KERNEL_NOOP:
376 (*events)[i].type = LTTNG_EVENT_NOOP;
377 break;
378 case LTTNG_KERNEL_SYSCALL:
379 (*events)[i].type = LTTNG_EVENT_SYSCALL;
380 break;
381 case LTTNG_KERNEL_ALL:
382 assert(0);
383 break;
384 }
385 i++;
386 }
387
388 end:
389 return nb_event;
390
391 error:
392 /* Negate the error code to differentiate the size from an error */
393 return -ret;
394 }
395
396 /*
397 * Add URI so the consumer output object. Set the correct path depending on the
398 * domain adding the default trace directory.
399 */
400 static int add_uri_to_consumer(struct consumer_output *consumer,
401 struct lttng_uri *uri, int domain, const char *session_name)
402 {
403 int ret = LTTNG_OK;
404 const char *default_trace_dir;
405
406 assert(uri);
407
408 if (consumer == NULL) {
409 DBG("No consumer detected. Don't add URI. Stopping.");
410 ret = LTTNG_ERR_NO_CONSUMER;
411 goto error;
412 }
413
414 switch (domain) {
415 case LTTNG_DOMAIN_KERNEL:
416 default_trace_dir = DEFAULT_KERNEL_TRACE_DIR;
417 break;
418 case LTTNG_DOMAIN_UST:
419 default_trace_dir = DEFAULT_UST_TRACE_DIR;
420 break;
421 default:
422 /*
423 * This case is possible is we try to add the URI to the global tracing
424 * session consumer object which in this case there is no subdir.
425 */
426 default_trace_dir = "";
427 }
428
429 switch (uri->dtype) {
430 case LTTNG_DST_IPV4:
431 case LTTNG_DST_IPV6:
432 DBG2("Setting network URI to consumer");
433
434 if (consumer->type == CONSUMER_DST_NET) {
435 if ((uri->stype == LTTNG_STREAM_CONTROL &&
436 consumer->dst.net.control_isset) ||
437 (uri->stype == LTTNG_STREAM_DATA &&
438 consumer->dst.net.data_isset)) {
439 ret = LTTNG_ERR_URL_EXIST;
440 goto error;
441 }
442 } else {
443 memset(&consumer->dst.net, 0, sizeof(consumer->dst.net));
444 }
445
446 consumer->type = CONSUMER_DST_NET;
447
448 /* Set URI into consumer output object */
449 ret = consumer_set_network_uri(consumer, uri);
450 if (ret < 0) {
451 ret = -ret;
452 goto error;
453 } else if (ret == 1) {
454 /*
455 * URI was the same in the consumer so we do not append the subdir
456 * again so to not duplicate output dir.
457 */
458 goto error;
459 }
460
461 if (uri->stype == LTTNG_STREAM_CONTROL && strlen(uri->subdir) == 0) {
462 ret = consumer_set_subdir(consumer, session_name);
463 if (ret < 0) {
464 ret = LTTNG_ERR_FATAL;
465 goto error;
466 }
467 }
468
469 if (uri->stype == LTTNG_STREAM_CONTROL) {
470 /* On a new subdir, reappend the default trace dir. */
471 strncat(consumer->subdir, default_trace_dir,
472 sizeof(consumer->subdir) - strlen(consumer->subdir) - 1);
473 DBG3("Append domain trace name to subdir %s", consumer->subdir);
474 }
475
476 break;
477 case LTTNG_DST_PATH:
478 DBG2("Setting trace directory path from URI to %s", uri->dst.path);
479 memset(consumer->dst.trace_path, 0,
480 sizeof(consumer->dst.trace_path));
481 strncpy(consumer->dst.trace_path, uri->dst.path,
482 sizeof(consumer->dst.trace_path));
483 /* Append default trace dir */
484 strncat(consumer->dst.trace_path, default_trace_dir,
485 sizeof(consumer->dst.trace_path) -
486 strlen(consumer->dst.trace_path) - 1);
487 /* Flag consumer as local. */
488 consumer->type = CONSUMER_DST_LOCAL;
489 break;
490 }
491
492 ret = LTTNG_OK;
493
494 error:
495 return ret;
496 }
497
498 /*
499 * Init tracing by creating trace directory and sending fds kernel consumer.
500 */
501 static int init_kernel_tracing(struct ltt_kernel_session *session)
502 {
503 int ret = 0;
504 struct lttng_ht_iter iter;
505 struct consumer_socket *socket;
506
507 assert(session);
508
509 rcu_read_lock();
510
511 if (session->consumer_fds_sent == 0 && session->consumer != NULL) {
512 cds_lfht_for_each_entry(session->consumer->socks->ht, &iter.iter,
513 socket, node.node) {
514 pthread_mutex_lock(socket->lock);
515 ret = kernel_consumer_send_session(socket, session);
516 pthread_mutex_unlock(socket->lock);
517 if (ret < 0) {
518 ret = LTTNG_ERR_KERN_CONSUMER_FAIL;
519 goto error;
520 }
521 }
522 }
523
524 error:
525 rcu_read_unlock();
526 return ret;
527 }
528
529 /*
530 * Create a socket to the relayd using the URI.
531 *
532 * On success, the relayd_sock pointer is set to the created socket.
533 * Else, it's stays untouched and a lttcomm error code is returned.
534 */
535 static int create_connect_relayd(struct lttng_uri *uri,
536 struct lttcomm_relayd_sock **relayd_sock)
537 {
538 int ret;
539 struct lttcomm_relayd_sock *rsock;
540
541 rsock = lttcomm_alloc_relayd_sock(uri, RELAYD_VERSION_COMM_MAJOR,
542 RELAYD_VERSION_COMM_MINOR);
543 if (!rsock) {
544 ret = LTTNG_ERR_FATAL;
545 goto error;
546 }
547
548 /*
549 * Connect to relayd so we can proceed with a session creation. This call
550 * can possibly block for an arbitrary amount of time to set the health
551 * state to be in poll execution.
552 */
553 health_poll_entry();
554 ret = relayd_connect(rsock);
555 health_poll_exit();
556 if (ret < 0) {
557 ERR("Unable to reach lttng-relayd");
558 ret = LTTNG_ERR_RELAYD_CONNECT_FAIL;
559 goto free_sock;
560 }
561
562 /* Create socket for control stream. */
563 if (uri->stype == LTTNG_STREAM_CONTROL) {
564 DBG3("Creating relayd stream socket from URI");
565
566 /* Check relayd version */
567 ret = relayd_version_check(rsock);
568 if (ret < 0) {
569 ret = LTTNG_ERR_RELAYD_VERSION_FAIL;
570 goto close_sock;
571 }
572 } else if (uri->stype == LTTNG_STREAM_DATA) {
573 DBG3("Creating relayd data socket from URI");
574 } else {
575 /* Command is not valid */
576 ERR("Relayd invalid stream type: %d", uri->stype);
577 ret = LTTNG_ERR_INVALID;
578 goto close_sock;
579 }
580
581 *relayd_sock = rsock;
582
583 return LTTNG_OK;
584
585 close_sock:
586 /* The returned value is not useful since we are on an error path. */
587 (void) relayd_close(rsock);
588 free_sock:
589 free(rsock);
590 error:
591 return ret;
592 }
593
594 /*
595 * Connect to the relayd using URI and send the socket to the right consumer.
596 */
597 static int send_consumer_relayd_socket(int domain, unsigned int session_id,
598 struct lttng_uri *relayd_uri, struct consumer_output *consumer,
599 struct consumer_socket *consumer_sock,
600 char *session_name, char *hostname, int session_live_timer)
601 {
602 int ret;
603 struct lttcomm_relayd_sock *rsock = NULL;
604
605 /* Connect to relayd and make version check if uri is the control. */
606 ret = create_connect_relayd(relayd_uri, &rsock);
607 if (ret != LTTNG_OK) {
608 goto error;
609 }
610 assert(rsock);
611
612 /* Set the network sequence index if not set. */
613 if (consumer->net_seq_index == (uint64_t) -1ULL) {
614 pthread_mutex_lock(&relayd_net_seq_idx_lock);
615 /*
616 * Increment net_seq_idx because we are about to transfer the
617 * new relayd socket to the consumer.
618 * Assign unique key so the consumer can match streams.
619 */
620 consumer->net_seq_index = ++relayd_net_seq_idx;
621 pthread_mutex_unlock(&relayd_net_seq_idx_lock);
622 }
623
624 /* Send relayd socket to consumer. */
625 ret = consumer_send_relayd_socket(consumer_sock, rsock, consumer,
626 relayd_uri->stype, session_id,
627 session_name, hostname, session_live_timer);
628 if (ret < 0) {
629 ret = LTTNG_ERR_ENABLE_CONSUMER_FAIL;
630 goto close_sock;
631 }
632
633 /* Flag that the corresponding socket was sent. */
634 if (relayd_uri->stype == LTTNG_STREAM_CONTROL) {
635 consumer_sock->control_sock_sent = 1;
636 } else if (relayd_uri->stype == LTTNG_STREAM_DATA) {
637 consumer_sock->data_sock_sent = 1;
638 }
639
640 ret = LTTNG_OK;
641
642 /*
643 * Close socket which was dup on the consumer side. The session daemon does
644 * NOT keep track of the relayd socket(s) once transfer to the consumer.
645 */
646
647 close_sock:
648 (void) relayd_close(rsock);
649 free(rsock);
650
651 error:
652 if (ret != LTTNG_OK) {
653 /*
654 * The consumer output for this session should not be used anymore
655 * since the relayd connection failed thus making any tracing or/and
656 * streaming not usable.
657 */
658 consumer->enabled = 0;
659 }
660 return ret;
661 }
662
663 /*
664 * Send both relayd sockets to a specific consumer and domain. This is a
665 * helper function to facilitate sending the information to the consumer for a
666 * session.
667 */
668 static int send_consumer_relayd_sockets(int domain, unsigned int session_id,
669 struct consumer_output *consumer, struct consumer_socket *sock,
670 char *session_name, char *hostname, int session_live_timer)
671 {
672 int ret = LTTNG_OK;
673
674 assert(consumer);
675 assert(sock);
676
677 /* Sending control relayd socket. */
678 if (!sock->control_sock_sent) {
679 ret = send_consumer_relayd_socket(domain, session_id,
680 &consumer->dst.net.control, consumer, sock,
681 session_name, hostname, session_live_timer);
682 if (ret != LTTNG_OK) {
683 goto error;
684 }
685 }
686
687 /* Sending data relayd socket. */
688 if (!sock->data_sock_sent) {
689 ret = send_consumer_relayd_socket(domain, session_id,
690 &consumer->dst.net.data, consumer, sock,
691 session_name, hostname, session_live_timer);
692 if (ret != LTTNG_OK) {
693 goto error;
694 }
695 }
696
697 error:
698 return ret;
699 }
700
701 /*
702 * Setup relayd connections for a tracing session. First creates the socket to
703 * the relayd and send them to the right domain consumer. Consumer type MUST be
704 * network.
705 */
706 int cmd_setup_relayd(struct ltt_session *session)
707 {
708 int ret = LTTNG_OK;
709 struct ltt_ust_session *usess;
710 struct ltt_kernel_session *ksess;
711 struct consumer_socket *socket;
712 struct lttng_ht_iter iter;
713
714 assert(session);
715
716 usess = session->ust_session;
717 ksess = session->kernel_session;
718
719 DBG("Setting relayd for session %s", session->name);
720
721 rcu_read_lock();
722
723 if (usess && usess->consumer && usess->consumer->type == CONSUMER_DST_NET
724 && usess->consumer->enabled) {
725 /* For each consumer socket, send relayd sockets */
726 cds_lfht_for_each_entry(usess->consumer->socks->ht, &iter.iter,
727 socket, node.node) {
728 pthread_mutex_lock(socket->lock);
729 ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session->id,
730 usess->consumer, socket,
731 session->name, session->hostname,
732 session->live_timer);
733 pthread_mutex_unlock(socket->lock);
734 if (ret != LTTNG_OK) {
735 goto error;
736 }
737 /* Session is now ready for network streaming. */
738 session->net_handle = 1;
739 }
740 }
741
742 if (ksess && ksess->consumer && ksess->consumer->type == CONSUMER_DST_NET
743 && ksess->consumer->enabled) {
744 cds_lfht_for_each_entry(ksess->consumer->socks->ht, &iter.iter,
745 socket, node.node) {
746 pthread_mutex_lock(socket->lock);
747 ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session->id,
748 ksess->consumer, socket,
749 session->name, session->hostname,
750 session->live_timer);
751 pthread_mutex_unlock(socket->lock);
752 if (ret != LTTNG_OK) {
753 goto error;
754 }
755 /* Session is now ready for network streaming. */
756 session->net_handle = 1;
757 }
758 }
759
760 error:
761 rcu_read_unlock();
762 return ret;
763 }
764
765 /*
766 * Start a kernel session by opening all necessary streams.
767 */
768 static int start_kernel_session(struct ltt_kernel_session *ksess, int wpipe)
769 {
770 int ret;
771 struct ltt_kernel_channel *kchan;
772
773 /* Open kernel metadata */
774 if (ksess->metadata == NULL && ksess->output_traces) {
775 ret = kernel_open_metadata(ksess);
776 if (ret < 0) {
777 ret = LTTNG_ERR_KERN_META_FAIL;
778 goto error;
779 }
780 }
781
782 /* Open kernel metadata stream */
783 if (ksess->metadata && ksess->metadata_stream_fd < 0) {
784 ret = kernel_open_metadata_stream(ksess);
785 if (ret < 0) {
786 ERR("Kernel create metadata stream failed");
787 ret = LTTNG_ERR_KERN_STREAM_FAIL;
788 goto error;
789 }
790 }
791
792 /* For each channel */
793 cds_list_for_each_entry(kchan, &ksess->channel_list.head, list) {
794 if (kchan->stream_count == 0) {
795 ret = kernel_open_channel_stream(kchan);
796 if (ret < 0) {
797 ret = LTTNG_ERR_KERN_STREAM_FAIL;
798 goto error;
799 }
800 /* Update the stream global counter */
801 ksess->stream_count_global += ret;
802 }
803 }
804
805 /* Setup kernel consumer socket and send fds to it */
806 ret = init_kernel_tracing(ksess);
807 if (ret != 0) {
808 ret = LTTNG_ERR_KERN_START_FAIL;
809 goto error;
810 }
811
812 /* This start the kernel tracing */
813 ret = kernel_start_session(ksess);
814 if (ret < 0) {
815 ret = LTTNG_ERR_KERN_START_FAIL;
816 goto error;
817 }
818
819 /* Quiescent wait after starting trace */
820 kernel_wait_quiescent(kernel_tracer_fd);
821
822 ksess->started = 1;
823
824 ret = LTTNG_OK;
825
826 error:
827 return ret;
828 }
829
830 /*
831 * Command LTTNG_DISABLE_CHANNEL processed by the client thread.
832 */
833 int cmd_disable_channel(struct ltt_session *session, int domain,
834 char *channel_name)
835 {
836 int ret;
837 struct ltt_ust_session *usess;
838
839 usess = session->ust_session;
840
841 rcu_read_lock();
842
843 switch (domain) {
844 case LTTNG_DOMAIN_KERNEL:
845 {
846 ret = channel_kernel_disable(session->kernel_session,
847 channel_name);
848 if (ret != LTTNG_OK) {
849 goto error;
850 }
851
852 kernel_wait_quiescent(kernel_tracer_fd);
853 break;
854 }
855 case LTTNG_DOMAIN_UST:
856 {
857 struct ltt_ust_channel *uchan;
858 struct lttng_ht *chan_ht;
859
860 chan_ht = usess->domain_global.channels;
861
862 uchan = trace_ust_find_channel_by_name(chan_ht, channel_name);
863 if (uchan == NULL) {
864 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
865 goto error;
866 }
867
868 ret = channel_ust_disable(usess, uchan);
869 if (ret != LTTNG_OK) {
870 goto error;
871 }
872 break;
873 }
874 #if 0
875 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
876 case LTTNG_DOMAIN_UST_EXEC_NAME:
877 case LTTNG_DOMAIN_UST_PID:
878 #endif
879 default:
880 ret = LTTNG_ERR_UNKNOWN_DOMAIN;
881 goto error;
882 }
883
884 ret = LTTNG_OK;
885
886 error:
887 rcu_read_unlock();
888 return ret;
889 }
890
891 /*
892 * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
893 *
894 * The wpipe arguments is used as a notifier for the kernel thread.
895 */
896 int cmd_enable_channel(struct ltt_session *session,
897 struct lttng_domain *domain, struct lttng_channel *attr, int wpipe)
898 {
899 int ret;
900 struct ltt_ust_session *usess = session->ust_session;
901 struct lttng_ht *chan_ht;
902
903 assert(session);
904 assert(attr);
905 assert(domain);
906
907 DBG("Enabling channel %s for session %s", attr->name, session->name);
908
909 rcu_read_lock();
910
911 /*
912 * Don't try to enable a channel if the session has been started at
913 * some point in time before. The tracer does not allow it.
914 */
915 if (session->started) {
916 ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
917 goto error;
918 }
919
920 /*
921 * If the session is a live session, remove the switch timer, the
922 * live timer does the same thing but sends also synchronisation
923 * beacons for inactive streams.
924 */
925 if (session->live_timer > 0) {
926 attr->attr.live_timer_interval = session->live_timer;
927 attr->attr.switch_timer_interval = 0;
928 }
929
930 switch (domain->type) {
931 case LTTNG_DOMAIN_KERNEL:
932 {
933 struct ltt_kernel_channel *kchan;
934
935 kchan = trace_kernel_get_channel_by_name(attr->name,
936 session->kernel_session);
937 if (kchan == NULL) {
938 /*
939 * Don't try to create a channel if the session
940 * has been started at some point in time
941 * before. The tracer does not allow it.
942 */
943 if (session->started) {
944 ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
945 goto error;
946 }
947 ret = channel_kernel_create(session->kernel_session, attr, wpipe);
948 if (attr->name[0] != '\0') {
949 session->kernel_session->has_non_default_channel = 1;
950 }
951 } else {
952 ret = channel_kernel_enable(session->kernel_session, kchan);
953 }
954
955 if (ret != LTTNG_OK) {
956 goto error;
957 }
958
959 kernel_wait_quiescent(kernel_tracer_fd);
960 break;
961 }
962 case LTTNG_DOMAIN_UST:
963 {
964 struct ltt_ust_channel *uchan;
965
966 chan_ht = usess->domain_global.channels;
967
968 uchan = trace_ust_find_channel_by_name(chan_ht, attr->name);
969 if (uchan == NULL) {
970 /*
971 * Don't try to create a channel if the session
972 * has been started at some point in time
973 * before. The tracer does not allow it.
974 */
975 if (session->started) {
976 ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
977 goto error;
978 }
979 ret = channel_ust_create(usess, attr, domain->buf_type);
980 if (attr->name[0] != '\0') {
981 usess->has_non_default_channel = 1;
982 }
983 } else {
984 ret = channel_ust_enable(usess, uchan);
985 }
986 break;
987 }
988 default:
989 ret = LTTNG_ERR_UNKNOWN_DOMAIN;
990 goto error;
991 }
992
993 error:
994 rcu_read_unlock();
995 return ret;
996 }
997
998
999 /*
1000 * Command LTTNG_DISABLE_EVENT processed by the client thread.
1001 */
1002 int cmd_disable_event(struct ltt_session *session, int domain,
1003 char *channel_name, char *event_name)
1004 {
1005 int ret;
1006
1007 rcu_read_lock();
1008
1009 switch (domain) {
1010 case LTTNG_DOMAIN_KERNEL:
1011 {
1012 struct ltt_kernel_channel *kchan;
1013 struct ltt_kernel_session *ksess;
1014
1015 ksess = session->kernel_session;
1016
1017 /*
1018 * If a non-default channel has been created in the
1019 * session, explicitely require that -c chan_name needs
1020 * to be provided.
1021 */
1022 if (ksess->has_non_default_channel && channel_name[0] == '\0') {
1023 ret = LTTNG_ERR_NEED_CHANNEL_NAME;
1024 goto error;
1025 }
1026
1027 kchan = trace_kernel_get_channel_by_name(channel_name, ksess);
1028 if (kchan == NULL) {
1029 ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND;
1030 goto error;
1031 }
1032
1033 ret = event_kernel_disable_tracepoint(kchan, event_name);
1034 if (ret != LTTNG_OK) {
1035 goto error;
1036 }
1037
1038 kernel_wait_quiescent(kernel_tracer_fd);
1039 break;
1040 }
1041 case LTTNG_DOMAIN_UST:
1042 {
1043 struct ltt_ust_channel *uchan;
1044 struct ltt_ust_session *usess;
1045
1046 usess = session->ust_session;
1047
1048 /*
1049 * If a non-default channel has been created in the
1050 * session, explicitely require that -c chan_name needs
1051 * to be provided.
1052 */
1053 if (usess->has_non_default_channel && channel_name[0] == '\0') {
1054 ret = LTTNG_ERR_NEED_CHANNEL_NAME;
1055 goto error;
1056 }
1057
1058 uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
1059 channel_name);
1060 if (uchan == NULL) {
1061 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
1062 goto error;
1063 }
1064
1065 ret = event_ust_disable_tracepoint(usess, uchan, event_name);
1066 if (ret != LTTNG_OK) {
1067 goto error;
1068 }
1069
1070 DBG3("Disable UST event %s in channel %s completed", event_name,
1071 channel_name);
1072 break;
1073 }
1074 case LTTNG_DOMAIN_JUL:
1075 {
1076 struct ltt_ust_session *usess = session->ust_session;
1077
1078 assert(usess);
1079
1080 ret = event_jul_disable(usess, event_name);
1081 if (ret != LTTNG_OK) {
1082 goto error;
1083 }
1084
1085 break;
1086 }
1087 #if 0
1088 case LTTNG_DOMAIN_UST_EXEC_NAME:
1089 case LTTNG_DOMAIN_UST_PID:
1090 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
1091 #endif
1092 default:
1093 ret = LTTNG_ERR_UND;
1094 goto error;
1095 }
1096
1097 ret = LTTNG_OK;
1098
1099 error:
1100 rcu_read_unlock();
1101 return ret;
1102 }
1103
1104 /*
1105 * Command LTTNG_DISABLE_ALL_EVENT processed by the client thread.
1106 */
1107 int cmd_disable_event_all(struct ltt_session *session, int domain,
1108 char *channel_name)
1109 {
1110 int ret;
1111
1112 rcu_read_lock();
1113
1114 switch (domain) {
1115 case LTTNG_DOMAIN_KERNEL:
1116 {
1117 struct ltt_kernel_session *ksess;
1118 struct ltt_kernel_channel *kchan;
1119
1120 ksess = session->kernel_session;
1121
1122 /*
1123 * If a non-default channel has been created in the
1124 * session, explicitely require that -c chan_name needs
1125 * to be provided.
1126 */
1127 if (ksess->has_non_default_channel && channel_name[0] == '\0') {
1128 ret = LTTNG_ERR_NEED_CHANNEL_NAME;
1129 goto error;
1130 }
1131
1132 kchan = trace_kernel_get_channel_by_name(channel_name, ksess);
1133 if (kchan == NULL) {
1134 ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND;
1135 goto error;
1136 }
1137
1138 ret = event_kernel_disable_all(kchan);
1139 if (ret != LTTNG_OK) {
1140 goto error;
1141 }
1142
1143 kernel_wait_quiescent(kernel_tracer_fd);
1144 break;
1145 }
1146 case LTTNG_DOMAIN_UST:
1147 {
1148 struct ltt_ust_session *usess;
1149 struct ltt_ust_channel *uchan;
1150
1151 usess = session->ust_session;
1152
1153 /*
1154 * If a non-default channel has been created in the
1155 * session, explicitely require that -c chan_name needs
1156 * to be provided.
1157 */
1158 if (usess->has_non_default_channel && channel_name[0] == '\0') {
1159 ret = LTTNG_ERR_NEED_CHANNEL_NAME;
1160 goto error;
1161 }
1162
1163 uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
1164 channel_name);
1165 if (uchan == NULL) {
1166 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
1167 goto error;
1168 }
1169
1170 ret = event_ust_disable_all_tracepoints(usess, uchan);
1171 if (ret != 0) {
1172 goto error;
1173 }
1174
1175 DBG3("Disable all UST events in channel %s completed", channel_name);
1176
1177 break;
1178 }
1179 case LTTNG_DOMAIN_JUL:
1180 {
1181 struct ltt_ust_session *usess = session->ust_session;
1182
1183 assert(usess);
1184
1185 ret = event_jul_disable_all(usess);
1186 if (ret != LTTNG_OK) {
1187 goto error;
1188 }
1189
1190 break;
1191 }
1192 #if 0
1193 case LTTNG_DOMAIN_UST_EXEC_NAME:
1194 case LTTNG_DOMAIN_UST_PID:
1195 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
1196 #endif
1197 default:
1198 ret = LTTNG_ERR_UND;
1199 goto error;
1200 }
1201
1202 ret = LTTNG_OK;
1203
1204 error:
1205 rcu_read_unlock();
1206 return ret;
1207 }
1208
1209 /*
1210 * Command LTTNG_ADD_CONTEXT processed by the client thread.
1211 */
1212 int cmd_add_context(struct ltt_session *session, int domain,
1213 char *channel_name, struct lttng_event_context *ctx, int kwpipe)
1214 {
1215 int ret, chan_kern_created = 0, chan_ust_created = 0;
1216
1217 switch (domain) {
1218 case LTTNG_DOMAIN_KERNEL:
1219 assert(session->kernel_session);
1220
1221 if (session->kernel_session->channel_count == 0) {
1222 /* Create default channel */
1223 ret = channel_kernel_create(session->kernel_session, NULL, kwpipe);
1224 if (ret != LTTNG_OK) {
1225 goto error;
1226 }
1227 chan_kern_created = 1;
1228 }
1229 /* Add kernel context to kernel tracer */
1230 ret = context_kernel_add(session->kernel_session, ctx, channel_name);
1231 if (ret != LTTNG_OK) {
1232 goto error;
1233 }
1234 break;
1235 case LTTNG_DOMAIN_UST:
1236 {
1237 struct ltt_ust_session *usess = session->ust_session;
1238 unsigned int chan_count;
1239
1240 assert(usess);
1241
1242 chan_count = lttng_ht_get_count(usess->domain_global.channels);
1243 if (chan_count == 0) {
1244 struct lttng_channel *attr;
1245 /* Create default channel */
1246 attr = channel_new_default_attr(domain, usess->buffer_type);
1247 if (attr == NULL) {
1248 ret = LTTNG_ERR_FATAL;
1249 goto error;
1250 }
1251
1252 ret = channel_ust_create(usess, attr, usess->buffer_type);
1253 if (ret != LTTNG_OK) {
1254 free(attr);
1255 goto error;
1256 }
1257 free(attr);
1258 chan_ust_created = 1;
1259 }
1260
1261 ret = context_ust_add(usess, domain, ctx, channel_name);
1262 if (ret != LTTNG_OK) {
1263 goto error;
1264 }
1265 break;
1266 }
1267 #if 0
1268 case LTTNG_DOMAIN_UST_EXEC_NAME:
1269 case LTTNG_DOMAIN_UST_PID:
1270 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
1271 #endif
1272 default:
1273 ret = LTTNG_ERR_UND;
1274 goto error;
1275 }
1276
1277 return LTTNG_OK;
1278
1279 error:
1280 if (chan_kern_created) {
1281 struct ltt_kernel_channel *kchan =
1282 trace_kernel_get_channel_by_name(DEFAULT_CHANNEL_NAME,
1283 session->kernel_session);
1284 /* Created previously, this should NOT fail. */
1285 assert(kchan);
1286 kernel_destroy_channel(kchan);
1287 }
1288
1289 if (chan_ust_created) {
1290 struct ltt_ust_channel *uchan =
1291 trace_ust_find_channel_by_name(
1292 session->ust_session->domain_global.channels,
1293 DEFAULT_CHANNEL_NAME);
1294 /* Created previously, this should NOT fail. */
1295 assert(uchan);
1296 /* Remove from the channel list of the session. */
1297 trace_ust_delete_channel(session->ust_session->domain_global.channels,
1298 uchan);
1299 trace_ust_destroy_channel(uchan);
1300 }
1301 return ret;
1302 }
1303
1304 /*
1305 * Command LTTNG_ENABLE_EVENT processed by the client thread.
1306 */
1307 int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
1308 char *channel_name, struct lttng_event *event,
1309 struct lttng_filter_bytecode *filter,
1310 struct lttng_event_exclusion *exclusion,
1311 int wpipe)
1312 {
1313 int ret, channel_created = 0;
1314 struct lttng_channel *attr;
1315
1316 assert(session);
1317 assert(event);
1318 assert(channel_name);
1319
1320 rcu_read_lock();
1321
1322 switch (domain->type) {
1323 case LTTNG_DOMAIN_KERNEL:
1324 {
1325 struct ltt_kernel_channel *kchan;
1326
1327 /*
1328 * If a non-default channel has been created in the
1329 * session, explicitely require that -c chan_name needs
1330 * to be provided.
1331 */
1332 if (session->kernel_session->has_non_default_channel
1333 && channel_name[0] == '\0') {
1334 ret = LTTNG_ERR_NEED_CHANNEL_NAME;
1335 goto error;
1336 }
1337
1338 kchan = trace_kernel_get_channel_by_name(channel_name,
1339 session->kernel_session);
1340 if (kchan == NULL) {
1341 attr = channel_new_default_attr(LTTNG_DOMAIN_KERNEL,
1342 LTTNG_BUFFER_GLOBAL);
1343 if (attr == NULL) {
1344 ret = LTTNG_ERR_FATAL;
1345 goto error;
1346 }
1347 strncpy(attr->name, channel_name, sizeof(attr->name));
1348
1349 ret = cmd_enable_channel(session, domain, attr, wpipe);
1350 if (ret != LTTNG_OK) {
1351 free(attr);
1352 goto error;
1353 }
1354 free(attr);
1355
1356 channel_created = 1;
1357 }
1358
1359 /* Get the newly created kernel channel pointer */
1360 kchan = trace_kernel_get_channel_by_name(channel_name,
1361 session->kernel_session);
1362 if (kchan == NULL) {
1363 /* This sould not happen... */
1364 ret = LTTNG_ERR_FATAL;
1365 goto error;
1366 }
1367
1368 ret = event_kernel_enable_tracepoint(kchan, event);
1369 if (ret != LTTNG_OK) {
1370 if (channel_created) {
1371 /* Let's not leak a useless channel. */
1372 kernel_destroy_channel(kchan);
1373 }
1374 goto error;
1375 }
1376
1377 kernel_wait_quiescent(kernel_tracer_fd);
1378 break;
1379 }
1380 case LTTNG_DOMAIN_UST:
1381 {
1382 struct ltt_ust_channel *uchan;
1383 struct ltt_ust_session *usess = session->ust_session;
1384
1385 assert(usess);
1386
1387 /*
1388 * If a non-default channel has been created in the
1389 * session, explicitely require that -c chan_name needs
1390 * to be provided.
1391 */
1392 if (usess->has_non_default_channel && channel_name[0] == '\0') {
1393 ret = LTTNG_ERR_NEED_CHANNEL_NAME;
1394 goto error;
1395 }
1396
1397 /* Get channel from global UST domain */
1398 uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
1399 channel_name);
1400 if (uchan == NULL) {
1401 /* Create default channel */
1402 attr = channel_new_default_attr(LTTNG_DOMAIN_UST,
1403 usess->buffer_type);
1404 if (attr == NULL) {
1405 ret = LTTNG_ERR_FATAL;
1406 goto error;
1407 }
1408 strncpy(attr->name, channel_name, sizeof(attr->name));
1409
1410 ret = cmd_enable_channel(session, domain, attr, wpipe);
1411 if (ret != LTTNG_OK) {
1412 free(attr);
1413 goto error;
1414 }
1415 free(attr);
1416
1417 /* Get the newly created channel reference back */
1418 uchan = trace_ust_find_channel_by_name(
1419 usess->domain_global.channels, channel_name);
1420 assert(uchan);
1421 }
1422
1423 /* At this point, the session and channel exist on the tracer */
1424 ret = event_ust_enable_tracepoint(usess, uchan, event, filter);
1425 if (ret != LTTNG_OK) {
1426 goto error;
1427 }
1428 break;
1429 }
1430 case LTTNG_DOMAIN_JUL:
1431 {
1432 struct lttng_event uevent;
1433 struct lttng_domain tmp_dom;
1434 struct ltt_ust_session *usess = session->ust_session;
1435
1436 assert(usess);
1437
1438 /* Create the default JUL tracepoint. */
1439 uevent.type = LTTNG_EVENT_TRACEPOINT;
1440 uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
1441 strncpy(uevent.name, DEFAULT_JUL_EVENT_NAME, sizeof(uevent.name));
1442 uevent.name[sizeof(uevent.name) - 1] = '\0';
1443
1444 /*
1445 * The domain type is changed because we are about to enable the
1446 * default channel and event for the JUL domain that are hardcoded.
1447 * This happens in the UST domain.
1448 */
1449 memcpy(&tmp_dom, domain, sizeof(tmp_dom));
1450 tmp_dom.type = LTTNG_DOMAIN_UST;
1451
1452 ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME,
1453 &uevent, NULL, NULL, wpipe);
1454 if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
1455 goto error;
1456 }
1457
1458 /* The wild card * means that everything should be enabled. */
1459 if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) {
1460 ret = event_jul_enable_all(usess);
1461 } else {
1462 ret = event_jul_enable(usess, event);
1463 }
1464 if (ret != LTTNG_OK) {
1465 goto error;
1466 }
1467
1468 break;
1469 }
1470 #if 0
1471 case LTTNG_DOMAIN_UST_EXEC_NAME:
1472 case LTTNG_DOMAIN_UST_PID:
1473 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
1474 #endif
1475 default:
1476 ret = LTTNG_ERR_UND;
1477 goto error;
1478 }
1479
1480 ret = LTTNG_OK;
1481
1482 error:
1483 rcu_read_unlock();
1484 return ret;
1485 }
1486
1487 /*
1488 * Command LTTNG_ENABLE_ALL_EVENT processed by the client thread.
1489 */
1490 int cmd_enable_event_all(struct ltt_session *session,
1491 struct lttng_domain *domain, char *channel_name, int event_type,
1492 struct lttng_filter_bytecode *filter, int wpipe)
1493 {
1494 int ret;
1495 struct lttng_channel *attr;
1496
1497 assert(session);
1498 assert(channel_name);
1499
1500 rcu_read_lock();
1501
1502 switch (domain->type) {
1503 case LTTNG_DOMAIN_KERNEL:
1504 {
1505 struct ltt_kernel_channel *kchan;
1506
1507 assert(session->kernel_session);
1508
1509 /*
1510 * If a non-default channel has been created in the
1511 * session, explicitely require that -c chan_name needs
1512 * to be provided.
1513 */
1514 if (session->kernel_session->has_non_default_channel
1515 && channel_name[0] == '\0') {
1516 ret = LTTNG_ERR_NEED_CHANNEL_NAME;
1517 goto error;
1518 }
1519
1520 kchan = trace_kernel_get_channel_by_name(channel_name,
1521 session->kernel_session);
1522 if (kchan == NULL) {
1523 /* Create default channel */
1524 attr = channel_new_default_attr(LTTNG_DOMAIN_KERNEL,
1525 LTTNG_BUFFER_GLOBAL);
1526 if (attr == NULL) {
1527 ret = LTTNG_ERR_FATAL;
1528 goto error;
1529 }
1530 strncpy(attr->name, channel_name, sizeof(attr->name));
1531
1532 ret = cmd_enable_channel(session, domain, attr, wpipe);
1533 if (ret != LTTNG_OK) {
1534 free(attr);
1535 goto error;
1536 }
1537 free(attr);
1538
1539 /* Get the newly created kernel channel pointer */
1540 kchan = trace_kernel_get_channel_by_name(channel_name,
1541 session->kernel_session);
1542 assert(kchan);
1543 }
1544
1545 switch (event_type) {
1546 case LTTNG_EVENT_SYSCALL:
1547 ret = event_kernel_enable_all_syscalls(kchan, kernel_tracer_fd);
1548 break;
1549 case LTTNG_EVENT_TRACEPOINT:
1550 /*
1551 * This call enables all LTTNG_KERNEL_TRACEPOINTS and
1552 * events already registered to the channel.
1553 */
1554 ret = event_kernel_enable_all_tracepoints(kchan, kernel_tracer_fd);
1555 break;
1556 case LTTNG_EVENT_ALL:
1557 /* Enable syscalls and tracepoints */
1558 ret = event_kernel_enable_all(kchan, kernel_tracer_fd);
1559 break;
1560 default:
1561 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
1562 goto error;
1563 }
1564
1565 /* Manage return value */
1566 if (ret != LTTNG_OK) {
1567 /*
1568 * On error, cmd_enable_channel call will take care of destroying
1569 * the created channel if it was needed.
1570 */
1571 goto error;
1572 }
1573
1574 kernel_wait_quiescent(kernel_tracer_fd);
1575 break;
1576 }
1577 case LTTNG_DOMAIN_UST:
1578 {
1579 struct ltt_ust_channel *uchan;
1580 struct ltt_ust_session *usess = session->ust_session;
1581
1582 assert(usess);
1583
1584 /*
1585 * If a non-default channel has been created in the
1586 * session, explicitely require that -c chan_name needs
1587 * to be provided.
1588 */
1589 if (usess->has_non_default_channel && channel_name[0] == '\0') {
1590 ret = LTTNG_ERR_NEED_CHANNEL_NAME;
1591 goto error;
1592 }
1593
1594 /* Get channel from global UST domain */
1595 uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
1596 channel_name);
1597 if (uchan == NULL) {
1598 /* Create default channel */
1599 attr = channel_new_default_attr(LTTNG_DOMAIN_UST,
1600 usess->buffer_type);
1601 if (attr == NULL) {
1602 ret = LTTNG_ERR_FATAL;
1603 goto error;
1604 }
1605 strncpy(attr->name, channel_name, sizeof(attr->name));
1606
1607 ret = cmd_enable_channel(session, domain, attr, wpipe);
1608 if (ret != LTTNG_OK) {
1609 free(attr);
1610 goto error;
1611 }
1612 free(attr);
1613
1614 /* Get the newly created channel reference back */
1615 uchan = trace_ust_find_channel_by_name(
1616 usess->domain_global.channels, channel_name);
1617 assert(uchan);
1618 }
1619
1620 /* At this point, the session and channel exist on the tracer */
1621
1622 switch (event_type) {
1623 case LTTNG_EVENT_ALL:
1624 case LTTNG_EVENT_TRACEPOINT:
1625 ret = event_ust_enable_all_tracepoints(usess, uchan, filter);
1626 if (ret != LTTNG_OK) {
1627 goto error;
1628 }
1629 break;
1630 default:
1631 ret = LTTNG_ERR_UST_ENABLE_FAIL;
1632 goto error;
1633 }
1634
1635 /* Manage return value */
1636 if (ret != LTTNG_OK) {
1637 goto error;
1638 }
1639
1640 break;
1641 }
1642 case LTTNG_DOMAIN_JUL:
1643 {
1644 struct lttng_event uevent;
1645 struct lttng_domain tmp_dom;
1646 struct ltt_ust_session *usess = session->ust_session;
1647
1648 assert(usess);
1649
1650 /* Create the default JUL tracepoint. */
1651 uevent.type = LTTNG_EVENT_TRACEPOINT;
1652 uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
1653 strncpy(uevent.name, DEFAULT_JUL_EVENT_NAME, sizeof(uevent.name));
1654 uevent.name[sizeof(uevent.name) - 1] = '\0';
1655
1656 /*
1657 * The domain type is changed because we are about to enable the
1658 * default channel and event for the JUL domain that are hardcoded.
1659 * This happens in the UST domain.
1660 */
1661 memcpy(&tmp_dom, domain, sizeof(tmp_dom));
1662 tmp_dom.type = LTTNG_DOMAIN_UST;
1663
1664 ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME,
1665 &uevent, NULL, NULL, wpipe);
1666 if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
1667 goto error;
1668 }
1669
1670 ret = event_jul_enable_all(usess);
1671 if (ret != LTTNG_OK) {
1672 goto error;
1673 }
1674
1675 break;
1676 }
1677 #if 0
1678 case LTTNG_DOMAIN_UST_EXEC_NAME:
1679 case LTTNG_DOMAIN_UST_PID:
1680 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
1681 #endif
1682 default:
1683 ret = LTTNG_ERR_UND;
1684 goto error;
1685 }
1686
1687 ret = LTTNG_OK;
1688
1689 error:
1690 rcu_read_unlock();
1691 return ret;
1692 }
1693
1694
1695 /*
1696 * Command LTTNG_LIST_TRACEPOINTS processed by the client thread.
1697 */
1698 ssize_t cmd_list_tracepoints(int domain, struct lttng_event **events)
1699 {
1700 int ret;
1701 ssize_t nb_events = 0;
1702
1703 switch (domain) {
1704 case LTTNG_DOMAIN_KERNEL:
1705 nb_events = kernel_list_events(kernel_tracer_fd, events);
1706 if (nb_events < 0) {
1707 ret = LTTNG_ERR_KERN_LIST_FAIL;
1708 goto error;
1709 }
1710 break;
1711 case LTTNG_DOMAIN_UST:
1712 nb_events = ust_app_list_events(events);
1713 if (nb_events < 0) {
1714 ret = LTTNG_ERR_UST_LIST_FAIL;
1715 goto error;
1716 }
1717 break;
1718 case LTTNG_DOMAIN_JUL:
1719 nb_events = jul_list_events(events);
1720 if (nb_events < 0) {
1721 ret = LTTNG_ERR_UST_LIST_FAIL;
1722 goto error;
1723 }
1724 break;
1725 default:
1726 ret = LTTNG_ERR_UND;
1727 goto error;
1728 }
1729
1730 return nb_events;
1731
1732 error:
1733 /* Return negative value to differentiate return code */
1734 return -ret;
1735 }
1736
1737 /*
1738 * Command LTTNG_LIST_TRACEPOINT_FIELDS processed by the client thread.
1739 */
1740 ssize_t cmd_list_tracepoint_fields(int domain,
1741 struct lttng_event_field **fields)
1742 {
1743 int ret;
1744 ssize_t nb_fields = 0;
1745
1746 switch (domain) {
1747 case LTTNG_DOMAIN_UST:
1748 nb_fields = ust_app_list_event_fields(fields);
1749 if (nb_fields < 0) {
1750 ret = LTTNG_ERR_UST_LIST_FAIL;
1751 goto error;
1752 }
1753 break;
1754 case LTTNG_DOMAIN_KERNEL:
1755 default: /* fall-through */
1756 ret = LTTNG_ERR_UND;
1757 goto error;
1758 }
1759
1760 return nb_fields;
1761
1762 error:
1763 /* Return negative value to differentiate return code */
1764 return -ret;
1765 }
1766
1767 /*
1768 * Command LTTNG_START_TRACE processed by the client thread.
1769 */
1770 int cmd_start_trace(struct ltt_session *session)
1771 {
1772 int ret;
1773 struct ltt_kernel_session *ksession;
1774 struct ltt_ust_session *usess;
1775
1776 assert(session);
1777
1778 /* Ease our life a bit ;) */
1779 ksession = session->kernel_session;
1780 usess = session->ust_session;
1781
1782 if (session->enabled) {
1783 /* Already started. */
1784 ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
1785 goto error;
1786 }
1787
1788 session->enabled = 1;
1789
1790 /* Kernel tracing */
1791 if (ksession != NULL) {
1792 ret = start_kernel_session(ksession, kernel_tracer_fd);
1793 if (ret != LTTNG_OK) {
1794 goto error;
1795 }
1796 }
1797
1798 /* Flag session that trace should start automatically */
1799 if (usess) {
1800 usess->start_trace = 1;
1801
1802 ret = ust_app_start_trace_all(usess);
1803 if (ret < 0) {
1804 ret = LTTNG_ERR_UST_START_FAIL;
1805 goto error;
1806 }
1807 }
1808
1809 session->started = 1;
1810
1811 ret = LTTNG_OK;
1812
1813 error:
1814 return ret;
1815 }
1816
1817 /*
1818 * Command LTTNG_STOP_TRACE processed by the client thread.
1819 */
1820 int cmd_stop_trace(struct ltt_session *session)
1821 {
1822 int ret;
1823 struct ltt_kernel_channel *kchan;
1824 struct ltt_kernel_session *ksession;
1825 struct ltt_ust_session *usess;
1826
1827 assert(session);
1828
1829 /* Short cut */
1830 ksession = session->kernel_session;
1831 usess = session->ust_session;
1832
1833 if (!session->enabled) {
1834 ret = LTTNG_ERR_TRACE_ALREADY_STOPPED;
1835 goto error;
1836 }
1837
1838 session->enabled = 0;
1839
1840 /* Kernel tracer */
1841 if (ksession && ksession->started) {
1842 DBG("Stop kernel tracing");
1843
1844 /* Flush metadata if exist */
1845 if (ksession->metadata_stream_fd >= 0) {
1846 ret = kernel_metadata_flush_buffer(ksession->metadata_stream_fd);
1847 if (ret < 0) {
1848 ERR("Kernel metadata flush failed");
1849 }
1850 }
1851
1852 /* Flush all buffers before stopping */
1853 cds_list_for_each_entry(kchan, &ksession->channel_list.head, list) {
1854 ret = kernel_flush_buffer(kchan);
1855 if (ret < 0) {
1856 ERR("Kernel flush buffer error");
1857 }
1858 }
1859
1860 ret = kernel_stop_session(ksession);
1861 if (ret < 0) {
1862 ret = LTTNG_ERR_KERN_STOP_FAIL;
1863 goto error;
1864 }
1865
1866 kernel_wait_quiescent(kernel_tracer_fd);
1867
1868 ksession->started = 0;
1869 }
1870
1871 if (usess && usess->start_trace) {
1872 usess->start_trace = 0;
1873
1874 ret = ust_app_stop_trace_all(usess);
1875 if (ret < 0) {
1876 ret = LTTNG_ERR_UST_STOP_FAIL;
1877 goto error;
1878 }
1879 }
1880
1881 ret = LTTNG_OK;
1882
1883 error:
1884 return ret;
1885 }
1886
1887 /*
1888 * Command LTTNG_SET_CONSUMER_URI processed by the client thread.
1889 */
1890 int cmd_set_consumer_uri(int domain, struct ltt_session *session,
1891 size_t nb_uri, struct lttng_uri *uris)
1892 {
1893 int ret, i;
1894 struct ltt_kernel_session *ksess = session->kernel_session;
1895 struct ltt_ust_session *usess = session->ust_session;
1896 struct consumer_output *consumer = NULL;
1897
1898 assert(session);
1899 assert(uris);
1900 assert(nb_uri > 0);
1901
1902 /* Can't enable consumer after session started. */
1903 if (session->enabled) {
1904 ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
1905 goto error;
1906 }
1907
1908 /*
1909 * This case switch makes sure the domain session has a temporary consumer
1910 * so the URL can be set.
1911 */
1912 switch (domain) {
1913 case 0:
1914 /* Code flow error. A session MUST always have a consumer object */
1915 assert(session->consumer);
1916 /*
1917 * The URL will be added to the tracing session consumer instead of a
1918 * specific domain consumer.
1919 */
1920 consumer = session->consumer;
1921 break;
1922 case LTTNG_DOMAIN_KERNEL:
1923 /* Code flow error if we don't have a kernel session here. */
1924 assert(ksess);
1925 assert(ksess->consumer);
1926 consumer = ksess->consumer;
1927 break;
1928 case LTTNG_DOMAIN_UST:
1929 /* Code flow error if we don't have a kernel session here. */
1930 assert(usess);
1931 assert(usess->consumer);
1932 consumer = usess->consumer;
1933 break;
1934 }
1935
1936 for (i = 0; i < nb_uri; i++) {
1937 ret = add_uri_to_consumer(consumer, &uris[i], domain, session->name);
1938 if (ret != LTTNG_OK) {
1939 goto error;
1940 }
1941 }
1942
1943 /* All good! */
1944 ret = LTTNG_OK;
1945
1946 error:
1947 return ret;
1948 }
1949
1950 /*
1951 * Command LTTNG_CREATE_SESSION processed by the client thread.
1952 */
1953 int cmd_create_session_uri(char *name, struct lttng_uri *uris,
1954 size_t nb_uri, lttng_sock_cred *creds, unsigned int live_timer)
1955 {
1956 int ret;
1957 struct ltt_session *session;
1958
1959 assert(name);
1960 assert(creds);
1961
1962 /*
1963 * Verify if the session already exist
1964 *
1965 * XXX: There is no need for the session lock list here since the caller
1966 * (process_client_msg) is holding it. We might want to change that so a
1967 * single command does not lock the entire session list.
1968 */
1969 session = session_find_by_name(name);
1970 if (session != NULL) {
1971 ret = LTTNG_ERR_EXIST_SESS;
1972 goto find_error;
1973 }
1974
1975 /* Create tracing session in the registry */
1976 ret = session_create(name, LTTNG_SOCK_GET_UID_CRED(creds),
1977 LTTNG_SOCK_GET_GID_CRED(creds));
1978 if (ret != LTTNG_OK) {
1979 goto session_error;
1980 }
1981
1982 /*
1983 * Get the newly created session pointer back
1984 *
1985 * XXX: There is no need for the session lock list here since the caller
1986 * (process_client_msg) is holding it. We might want to change that so a
1987 * single command does not lock the entire session list.
1988 */
1989 session = session_find_by_name(name);
1990 assert(session);
1991
1992 session->live_timer = live_timer;
1993 /* Create default consumer output for the session not yet created. */
1994 session->consumer = consumer_create_output(CONSUMER_DST_LOCAL);
1995 if (session->consumer == NULL) {
1996 ret = LTTNG_ERR_FATAL;
1997 goto consumer_error;
1998 }
1999
2000 if (uris) {
2001 ret = cmd_set_consumer_uri(0, session, nb_uri, uris);
2002 if (ret != LTTNG_OK) {
2003 goto consumer_error;
2004 }
2005 session->output_traces = 1;
2006 } else {
2007 session->output_traces = 0;
2008 DBG2("Session %s created with no output", session->name);
2009 }
2010
2011 session->consumer->enabled = 1;
2012
2013 return LTTNG_OK;
2014
2015 consumer_error:
2016 session_destroy(session);
2017 session_error:
2018 find_error:
2019 return ret;
2020 }
2021
2022 /*
2023 * Command LTTNG_CREATE_SESSION_SNAPSHOT processed by the client thread.
2024 */
2025 int cmd_create_session_snapshot(char *name, struct lttng_uri *uris,
2026 size_t nb_uri, lttng_sock_cred *creds)
2027 {
2028 int ret;
2029 struct ltt_session *session;
2030 struct snapshot_output *new_output = NULL;
2031
2032 assert(name);
2033 assert(creds);
2034
2035 /*
2036 * Create session in no output mode with URIs set to NULL. The uris we've
2037 * received are for a default snapshot output if one.
2038 */
2039 ret = cmd_create_session_uri(name, NULL, 0, creds, -1);
2040 if (ret != LTTNG_OK) {
2041 goto error;
2042 }
2043
2044 /* Get the newly created session pointer back. This should NEVER fail. */
2045 session = session_find_by_name(name);
2046 assert(session);
2047
2048 /* Flag session for snapshot mode. */
2049 session->snapshot_mode = 1;
2050
2051 /* Skip snapshot output creation if no URI is given. */
2052 if (nb_uri == 0) {
2053 goto end;
2054 }
2055
2056 new_output = snapshot_output_alloc();
2057 if (!new_output) {
2058 ret = LTTNG_ERR_NOMEM;
2059 goto error_snapshot_alloc;
2060 }
2061
2062 ret = snapshot_output_init_with_uri(DEFAULT_SNAPSHOT_MAX_SIZE, NULL,
2063 uris, nb_uri, session->consumer, new_output, &session->snapshot);
2064 if (ret < 0) {
2065 if (ret == -ENOMEM) {
2066 ret = LTTNG_ERR_NOMEM;
2067 } else {
2068 ret = LTTNG_ERR_INVALID;
2069 }
2070 goto error_snapshot;
2071 }
2072
2073 rcu_read_lock();
2074 snapshot_add_output(&session->snapshot, new_output);
2075 rcu_read_unlock();
2076
2077 end:
2078 return LTTNG_OK;
2079
2080 error_snapshot:
2081 snapshot_output_destroy(new_output);
2082 error_snapshot_alloc:
2083 session_destroy(session);
2084 error:
2085 return ret;
2086 }
2087
2088 /*
2089 * Command LTTNG_DESTROY_SESSION processed by the client thread.
2090 */
2091 int cmd_destroy_session(struct ltt_session *session, int wpipe)
2092 {
2093 int ret;
2094 struct ltt_ust_session *usess;
2095 struct ltt_kernel_session *ksess;
2096
2097 /* Safety net */
2098 assert(session);
2099
2100 usess = session->ust_session;
2101 ksess = session->kernel_session;
2102
2103 /* Clean kernel session teardown */
2104 kernel_destroy_session(ksess);
2105
2106 /* UST session teardown */
2107 if (usess) {
2108 /* Close any relayd session */
2109 consumer_output_send_destroy_relayd(usess->consumer);
2110
2111 /* Destroy every UST application related to this session. */
2112 ret = ust_app_destroy_trace_all(usess);
2113 if (ret) {
2114 ERR("Error in ust_app_destroy_trace_all");
2115 }
2116
2117 /* Clean up the rest. */
2118 trace_ust_destroy_session(usess);
2119 }
2120
2121 /*
2122 * Must notify the kernel thread here to update it's poll set in order to
2123 * remove the channel(s)' fd just destroyed.
2124 */
2125 ret = notify_thread_pipe(wpipe);
2126 if (ret < 0) {
2127 PERROR("write kernel poll pipe");
2128 }
2129
2130 ret = session_destroy(session);
2131
2132 return ret;
2133 }
2134
2135 /*
2136 * Command LTTNG_CALIBRATE processed by the client thread.
2137 */
2138 int cmd_calibrate(int domain, struct lttng_calibrate *calibrate)
2139 {
2140 int ret;
2141
2142 switch (domain) {
2143 case LTTNG_DOMAIN_KERNEL:
2144 {
2145 struct lttng_kernel_calibrate kcalibrate;
2146
2147 kcalibrate.type = calibrate->type;
2148 ret = kernel_calibrate(kernel_tracer_fd, &kcalibrate);
2149 if (ret < 0) {
2150 ret = LTTNG_ERR_KERN_ENABLE_FAIL;
2151 goto error;
2152 }
2153 break;
2154 }
2155 case LTTNG_DOMAIN_UST:
2156 {
2157 struct lttng_ust_calibrate ucalibrate;
2158
2159 ucalibrate.type = calibrate->type;
2160 ret = ust_app_calibrate_glb(&ucalibrate);
2161 if (ret < 0) {
2162 ret = LTTNG_ERR_UST_CALIBRATE_FAIL;
2163 goto error;
2164 }
2165 break;
2166 }
2167 default:
2168 ret = LTTNG_ERR_UND;
2169 goto error;
2170 }
2171
2172 ret = LTTNG_OK;
2173
2174 error:
2175 return ret;
2176 }
2177
2178 /*
2179 * Command LTTNG_REGISTER_CONSUMER processed by the client thread.
2180 */
2181 int cmd_register_consumer(struct ltt_session *session, int domain,
2182 const char *sock_path, struct consumer_data *cdata)
2183 {
2184 int ret, sock;
2185 struct consumer_socket *socket = NULL;
2186
2187 assert(session);
2188 assert(cdata);
2189 assert(sock_path);
2190
2191 switch (domain) {
2192 case LTTNG_DOMAIN_KERNEL:
2193 {
2194 struct ltt_kernel_session *ksess = session->kernel_session;
2195
2196 assert(ksess);
2197
2198 /* Can't register a consumer if there is already one */
2199 if (ksess->consumer_fds_sent != 0) {
2200 ret = LTTNG_ERR_KERN_CONSUMER_FAIL;
2201 goto error;
2202 }
2203
2204 sock = lttcomm_connect_unix_sock(sock_path);
2205 if (sock < 0) {
2206 ret = LTTNG_ERR_CONNECT_FAIL;
2207 goto error;
2208 }
2209 cdata->cmd_sock = sock;
2210
2211 socket = consumer_allocate_socket(&cdata->cmd_sock);
2212 if (socket == NULL) {
2213 ret = close(sock);
2214 if (ret < 0) {
2215 PERROR("close register consumer");
2216 }
2217 cdata->cmd_sock = -1;
2218 ret = LTTNG_ERR_FATAL;
2219 goto error;
2220 }
2221
2222 socket->lock = zmalloc(sizeof(pthread_mutex_t));
2223 if (socket->lock == NULL) {
2224 PERROR("zmalloc pthread mutex");
2225 ret = LTTNG_ERR_FATAL;
2226 goto error;
2227 }
2228 pthread_mutex_init(socket->lock, NULL);
2229 socket->registered = 1;
2230
2231 rcu_read_lock();
2232 consumer_add_socket(socket, ksess->consumer);
2233 rcu_read_unlock();
2234
2235 pthread_mutex_lock(&cdata->pid_mutex);
2236 cdata->pid = -1;
2237 pthread_mutex_unlock(&cdata->pid_mutex);
2238
2239 break;
2240 }
2241 default:
2242 /* TODO: Userspace tracing */
2243 ret = LTTNG_ERR_UND;
2244 goto error;
2245 }
2246
2247 return LTTNG_OK;
2248
2249 error:
2250 if (socket) {
2251 consumer_destroy_socket(socket);
2252 }
2253 return ret;
2254 }
2255
2256 /*
2257 * Command LTTNG_LIST_DOMAINS processed by the client thread.
2258 */
2259 ssize_t cmd_list_domains(struct ltt_session *session,
2260 struct lttng_domain **domains)
2261 {
2262 int ret, index = 0;
2263 ssize_t nb_dom = 0;
2264
2265 if (session->kernel_session != NULL) {
2266 DBG3("Listing domains found kernel domain");
2267 nb_dom++;
2268 }
2269
2270 if (session->ust_session != NULL) {
2271 DBG3("Listing domains found UST global domain");
2272 nb_dom++;
2273
2274 if (session->ust_session->domain_jul.being_used) {
2275 nb_dom++;
2276 }
2277 }
2278
2279 *domains = zmalloc(nb_dom * sizeof(struct lttng_domain));
2280 if (*domains == NULL) {
2281 ret = LTTNG_ERR_FATAL;
2282 goto error;
2283 }
2284
2285 if (session->kernel_session != NULL) {
2286 (*domains)[index].type = LTTNG_DOMAIN_KERNEL;
2287 index++;
2288 }
2289
2290 if (session->ust_session != NULL) {
2291 (*domains)[index].type = LTTNG_DOMAIN_UST;
2292 (*domains)[index].buf_type = session->ust_session->buffer_type;
2293 index++;
2294
2295 if (session->ust_session->domain_jul.being_used) {
2296 (*domains)[index].type = LTTNG_DOMAIN_JUL;
2297 (*domains)[index].buf_type = session->ust_session->buffer_type;
2298 index++;
2299 }
2300 }
2301
2302 return nb_dom;
2303
2304 error:
2305 /* Return negative value to differentiate return code */
2306 return -ret;
2307 }
2308
2309
2310 /*
2311 * Command LTTNG_LIST_CHANNELS processed by the client thread.
2312 */
2313 ssize_t cmd_list_channels(int domain, struct ltt_session *session,
2314 struct lttng_channel **channels)
2315 {
2316 int ret;
2317 ssize_t nb_chan = 0;
2318
2319 switch (domain) {
2320 case LTTNG_DOMAIN_KERNEL:
2321 if (session->kernel_session != NULL) {
2322 nb_chan = session->kernel_session->channel_count;
2323 }
2324 DBG3("Number of kernel channels %zd", nb_chan);
2325 if (nb_chan <= 0) {
2326 ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND;
2327 }
2328 break;
2329 case LTTNG_DOMAIN_UST:
2330 if (session->ust_session != NULL) {
2331 nb_chan = lttng_ht_get_count(
2332 session->ust_session->domain_global.channels);
2333 }
2334 DBG3("Number of UST global channels %zd", nb_chan);
2335 if (nb_chan <= 0) {
2336 ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
2337 }
2338 break;
2339 default:
2340 *channels = NULL;
2341 ret = LTTNG_ERR_UND;
2342 goto error;
2343 }
2344
2345 if (nb_chan > 0) {
2346 *channels = zmalloc(nb_chan * sizeof(struct lttng_channel));
2347 if (*channels == NULL) {
2348 ret = LTTNG_ERR_FATAL;
2349 goto error;
2350 }
2351
2352 list_lttng_channels(domain, session, *channels);
2353 } else {
2354 *channels = NULL;
2355 /* Ret value was set in the domain switch case */
2356 goto error;
2357 }
2358
2359 return nb_chan;
2360
2361 error:
2362 /* Return negative value to differentiate return code */
2363 return -ret;
2364 }
2365
2366 /*
2367 * Command LTTNG_LIST_EVENTS processed by the client thread.
2368 */
2369 ssize_t cmd_list_events(int domain, struct ltt_session *session,
2370 char *channel_name, struct lttng_event **events)
2371 {
2372 int ret = 0;
2373 ssize_t nb_event = 0;
2374
2375 switch (domain) {
2376 case LTTNG_DOMAIN_KERNEL:
2377 if (session->kernel_session != NULL) {
2378 nb_event = list_lttng_kernel_events(channel_name,
2379 session->kernel_session, events);
2380 }
2381 break;
2382 case LTTNG_DOMAIN_UST:
2383 {
2384 if (session->ust_session != NULL) {
2385 nb_event = list_lttng_ust_global_events(channel_name,
2386 &session->ust_session->domain_global, events);
2387 }
2388 break;
2389 }
2390 case LTTNG_DOMAIN_JUL:
2391 if (session->ust_session) {
2392 nb_event = list_lttng_jul_events(
2393 &session->ust_session->domain_jul, events);
2394 }
2395 break;
2396 default:
2397 ret = LTTNG_ERR_UND;
2398 goto error;
2399 }
2400
2401 return nb_event;
2402
2403 error:
2404 /* Return negative value to differentiate return code */
2405 return -ret;
2406 }
2407
2408 /*
2409 * Using the session list, filled a lttng_session array to send back to the
2410 * client for session listing.
2411 *
2412 * The session list lock MUST be acquired before calling this function. Use
2413 * session_lock_list() and session_unlock_list().
2414 */
2415 void cmd_list_lttng_sessions(struct lttng_session *sessions, uid_t uid,
2416 gid_t gid)
2417 {
2418 int ret;
2419 unsigned int i = 0;
2420 struct ltt_session *session;
2421 struct ltt_session_list *list = session_get_list();
2422
2423 DBG("Getting all available session for UID %d GID %d",
2424 uid, gid);
2425 /*
2426 * Iterate over session list and append data after the control struct in
2427 * the buffer.
2428 */
2429 cds_list_for_each_entry(session, &list->head, list) {
2430 /*
2431 * Only list the sessions the user can control.
2432 */
2433 if (!session_access_ok(session, uid, gid)) {
2434 continue;
2435 }
2436
2437 struct ltt_kernel_session *ksess = session->kernel_session;
2438 struct ltt_ust_session *usess = session->ust_session;
2439
2440 if (session->consumer->type == CONSUMER_DST_NET ||
2441 (ksess && ksess->consumer->type == CONSUMER_DST_NET) ||
2442 (usess && usess->consumer->type == CONSUMER_DST_NET)) {
2443 ret = build_network_session_path(sessions[i].path,
2444 sizeof(sessions[i].path), session);
2445 } else {
2446 ret = snprintf(sessions[i].path, sizeof(sessions[i].path), "%s",
2447 session->consumer->dst.trace_path);
2448 }
2449 if (ret < 0) {
2450 PERROR("snprintf session path");
2451 continue;
2452 }
2453
2454 strncpy(sessions[i].name, session->name, NAME_MAX);
2455 sessions[i].name[NAME_MAX - 1] = '\0';
2456 sessions[i].enabled = session->enabled;
2457 sessions[i].snapshot_mode = session->snapshot_mode;
2458 i++;
2459 }
2460 }
2461
2462 /*
2463 * Command LTTNG_DATA_PENDING returning 0 if the data is NOT pending meaning
2464 * ready for trace analysis (or any kind of reader) or else 1 for pending data.
2465 */
2466 int cmd_data_pending(struct ltt_session *session)
2467 {
2468 int ret;
2469 struct ltt_kernel_session *ksess = session->kernel_session;
2470 struct ltt_ust_session *usess = session->ust_session;
2471
2472 assert(session);
2473
2474 /* Session MUST be stopped to ask for data availability. */
2475 if (session->enabled) {
2476 ret = LTTNG_ERR_SESSION_STARTED;
2477 goto error;
2478 }
2479
2480 if (ksess && ksess->consumer) {
2481 ret = consumer_is_data_pending(ksess->id, ksess->consumer);
2482 if (ret == 1) {
2483 /* Data is still being extracted for the kernel. */
2484 goto error;
2485 }
2486 }
2487
2488 if (usess && usess->consumer) {
2489 ret = consumer_is_data_pending(usess->id, usess->consumer);
2490 if (ret == 1) {
2491 /* Data is still being extracted for the kernel. */
2492 goto error;
2493 }
2494 }
2495
2496 /* Data is ready to be read by a viewer */
2497 ret = 0;
2498
2499 error:
2500 return ret;
2501 }
2502
2503 /*
2504 * Command LTTNG_SNAPSHOT_ADD_OUTPUT from the lttng ctl library.
2505 *
2506 * Return LTTNG_OK on success or else a LTTNG_ERR code.
2507 */
2508 int cmd_snapshot_add_output(struct ltt_session *session,
2509 struct lttng_snapshot_output *output, uint32_t *id)
2510 {
2511 int ret;
2512 struct snapshot_output *new_output;
2513
2514 assert(session);
2515 assert(output);
2516
2517 DBG("Cmd snapshot add output for session %s", session->name);
2518
2519 /*
2520 * Permission denied to create an output if the session is not
2521 * set in no output mode.
2522 */
2523 if (session->output_traces) {
2524 ret = LTTNG_ERR_EPERM;
2525 goto error;
2526 }
2527
2528 /* Only one output is allowed until we have the "tee" feature. */
2529 if (session->snapshot.nb_output == 1) {
2530 ret = LTTNG_ERR_SNAPSHOT_OUTPUT_EXIST;
2531 goto error;
2532 }
2533
2534 new_output = snapshot_output_alloc();
2535 if (!new_output) {
2536 ret = LTTNG_ERR_NOMEM;
2537 goto error;
2538 }
2539
2540 ret = snapshot_output_init(output->max_size, output->name,
2541 output->ctrl_url, output->data_url, session->consumer, new_output,
2542 &session->snapshot);
2543 if (ret < 0) {
2544 if (ret == -ENOMEM) {
2545 ret = LTTNG_ERR_NOMEM;
2546 } else {
2547 ret = LTTNG_ERR_INVALID;
2548 }
2549 goto free_error;
2550 }
2551
2552 rcu_read_lock();
2553 snapshot_add_output(&session->snapshot, new_output);
2554 if (id) {
2555 *id = new_output->id;
2556 }
2557 rcu_read_unlock();
2558
2559 return LTTNG_OK;
2560
2561 free_error:
2562 snapshot_output_destroy(new_output);
2563 error:
2564 return ret;
2565 }
2566
2567 /*
2568 * Command LTTNG_SNAPSHOT_DEL_OUTPUT from lib lttng ctl.
2569 *
2570 * Return LTTNG_OK on success or else a LTTNG_ERR code.
2571 */
2572 int cmd_snapshot_del_output(struct ltt_session *session,
2573 struct lttng_snapshot_output *output)
2574 {
2575 int ret;
2576 struct snapshot_output *sout = NULL;
2577
2578 assert(session);
2579 assert(output);
2580
2581 rcu_read_lock();
2582
2583 /*
2584 * Permission denied to create an output if the session is not
2585 * set in no output mode.
2586 */
2587 if (session->output_traces) {
2588 ret = LTTNG_ERR_EPERM;
2589 goto error;
2590 }
2591
2592 if (output->id) {
2593 DBG("Cmd snapshot del output id %" PRIu32 " for session %s", output->id,
2594 session->name);
2595 sout = snapshot_find_output_by_id(output->id, &session->snapshot);
2596 } else if (*output->name != '\0') {
2597 DBG("Cmd snapshot del output name %s for session %s", output->name,
2598 session->name);
2599 sout = snapshot_find_output_by_name(output->name, &session->snapshot);
2600 }
2601 if (!sout) {
2602 ret = LTTNG_ERR_INVALID;
2603 goto error;
2604 }
2605
2606 snapshot_delete_output(&session->snapshot, sout);
2607 snapshot_output_destroy(sout);
2608 ret = LTTNG_OK;
2609
2610 error:
2611 rcu_read_unlock();
2612 return ret;
2613 }
2614
2615 /*
2616 * Command LTTNG_SNAPSHOT_LIST_OUTPUT from lib lttng ctl.
2617 *
2618 * If no output is available, outputs is untouched and 0 is returned.
2619 *
2620 * Return the size of the newly allocated outputs or a negative LTTNG_ERR code.
2621 */
2622 ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
2623 struct lttng_snapshot_output **outputs)
2624 {
2625 int ret, idx = 0;
2626 struct lttng_snapshot_output *list;
2627 struct lttng_ht_iter iter;
2628 struct snapshot_output *output;
2629
2630 assert(session);
2631 assert(outputs);
2632
2633 DBG("Cmd snapshot list outputs for session %s", session->name);
2634
2635 /*
2636 * Permission denied to create an output if the session is not
2637 * set in no output mode.
2638 */
2639 if (session->output_traces) {
2640 ret = LTTNG_ERR_EPERM;
2641 goto error;
2642 }
2643
2644 if (session->snapshot.nb_output == 0) {
2645 ret = 0;
2646 goto error;
2647 }
2648
2649 list = zmalloc(session->snapshot.nb_output * sizeof(*list));
2650 if (!list) {
2651 ret = LTTNG_ERR_NOMEM;
2652 goto error;
2653 }
2654
2655 /* Copy list from session to the new list object. */
2656 cds_lfht_for_each_entry(session->snapshot.output_ht->ht, &iter.iter,
2657 output, node.node) {
2658 assert(output->consumer);
2659 list[idx].id = output->id;
2660 list[idx].max_size = output->max_size;
2661 strncpy(list[idx].name, output->name, sizeof(list[idx].name));
2662 if (output->consumer->type == CONSUMER_DST_LOCAL) {
2663 strncpy(list[idx].ctrl_url, output->consumer->dst.trace_path,
2664 sizeof(list[idx].ctrl_url));
2665 } else {
2666 /* Control URI. */
2667 ret = uri_to_str_url(&output->consumer->dst.net.control,
2668 list[idx].ctrl_url, sizeof(list[idx].ctrl_url));
2669 if (ret < 0) {
2670 ret = LTTNG_ERR_NOMEM;
2671 goto free_error;
2672 }
2673
2674 /* Data URI. */
2675 ret = uri_to_str_url(&output->consumer->dst.net.data,
2676 list[idx].data_url, sizeof(list[idx].data_url));
2677 if (ret < 0) {
2678 ret = LTTNG_ERR_NOMEM;
2679 goto free_error;
2680 }
2681 }
2682 idx++;
2683 }
2684
2685 *outputs = list;
2686 return session->snapshot.nb_output;
2687
2688 free_error:
2689 free(list);
2690 error:
2691 return -ret;
2692 }
2693
2694 /*
2695 * Send relayd sockets from snapshot output to consumer. Ignore request if the
2696 * snapshot output is *not* set with a remote destination.
2697 *
2698 * Return 0 on success or a LTTNG_ERR code.
2699 */
2700 static int set_relayd_for_snapshot(struct consumer_output *consumer,
2701 struct snapshot_output *snap_output, struct ltt_session *session)
2702 {
2703 int ret = LTTNG_OK;
2704 struct lttng_ht_iter iter;
2705 struct consumer_socket *socket;
2706
2707 assert(consumer);
2708 assert(snap_output);
2709 assert(session);
2710
2711 DBG2("Set relayd object from snapshot output");
2712
2713 /* Ignore if snapshot consumer output is not network. */
2714 if (snap_output->consumer->type != CONSUMER_DST_NET) {
2715 goto error;
2716 }
2717
2718 /*
2719 * For each consumer socket, create and send the relayd object of the
2720 * snapshot output.
2721 */
2722 rcu_read_lock();
2723 cds_lfht_for_each_entry(snap_output->consumer->socks->ht, &iter.iter,
2724 socket, node.node) {
2725 ret = send_consumer_relayd_sockets(0, session->id,
2726 snap_output->consumer, socket,
2727 session->name, session->hostname,
2728 session->live_timer);
2729 if (ret != LTTNG_OK) {
2730 rcu_read_unlock();
2731 goto error;
2732 }
2733 }
2734 rcu_read_unlock();
2735
2736 error:
2737 return ret;
2738 }
2739
2740 /*
2741 * Record a kernel snapshot.
2742 *
2743 * Return LTTNG_OK on success or a LTTNG_ERR code.
2744 */
2745 static int record_kernel_snapshot(struct ltt_kernel_session *ksess,
2746 struct snapshot_output *output, struct ltt_session *session,
2747 int wait, int nb_streams)
2748 {
2749 int ret;
2750
2751 assert(ksess);
2752 assert(output);
2753 assert(session);
2754
2755 /* Get the datetime for the snapshot output directory. */
2756 ret = utils_get_current_time_str("%Y%m%d-%H%M%S", output->datetime,
2757 sizeof(output->datetime));
2758 if (!ret) {
2759 ret = LTTNG_ERR_INVALID;
2760 goto error;
2761 }
2762
2763 /*
2764 * Copy kernel session sockets so we can communicate with the right
2765 * consumer for the snapshot record command.
2766 */
2767 ret = consumer_copy_sockets(output->consumer, ksess->consumer);
2768 if (ret < 0) {
2769 ret = LTTNG_ERR_NOMEM;
2770 goto error;
2771 }
2772
2773 ret = set_relayd_for_snapshot(ksess->consumer, output, session);
2774 if (ret != LTTNG_OK) {
2775 goto error_snapshot;
2776 }
2777
2778 ret = kernel_snapshot_record(ksess, output, wait, nb_streams);
2779 if (ret != LTTNG_OK) {
2780 goto error_snapshot;
2781 }
2782
2783 ret = LTTNG_OK;
2784
2785 error_snapshot:
2786 /* Clean up copied sockets so this output can use some other later on. */
2787 consumer_destroy_output_sockets(output->consumer);
2788 error:
2789 return ret;
2790 }
2791
2792 /*
2793 * Record a UST snapshot.
2794 *
2795 * Return 0 on success or a LTTNG_ERR error code.
2796 */
2797 static int record_ust_snapshot(struct ltt_ust_session *usess,
2798 struct snapshot_output *output, struct ltt_session *session,
2799 int wait, int nb_streams)
2800 {
2801 int ret;
2802
2803 assert(usess);
2804 assert(output);
2805 assert(session);
2806
2807 /* Get the datetime for the snapshot output directory. */
2808 ret = utils_get_current_time_str("%Y%m%d-%H%M%S", output->datetime,
2809 sizeof(output->datetime));
2810 if (!ret) {
2811 ret = LTTNG_ERR_INVALID;
2812 goto error;
2813 }
2814
2815 /*
2816 * Copy UST session sockets so we can communicate with the right
2817 * consumer for the snapshot record command.
2818 */
2819 ret = consumer_copy_sockets(output->consumer, usess->consumer);
2820 if (ret < 0) {
2821 ret = LTTNG_ERR_NOMEM;
2822 goto error;
2823 }
2824
2825 ret = set_relayd_for_snapshot(usess->consumer, output, session);
2826 if (ret != LTTNG_OK) {
2827 goto error_snapshot;
2828 }
2829
2830 ret = ust_app_snapshot_record(usess, output, wait, nb_streams);
2831 if (ret < 0) {
2832 if (ret == -EINVAL) {
2833 ret = LTTNG_ERR_INVALID;
2834 goto error_snapshot;
2835 }
2836
2837 ret = LTTNG_ERR_SNAPSHOT_FAIL;
2838 goto error_snapshot;
2839 }
2840
2841 ret = LTTNG_OK;
2842
2843 error_snapshot:
2844 /* Clean up copied sockets so this output can use some other later on. */
2845 consumer_destroy_output_sockets(output->consumer);
2846 error:
2847 return ret;
2848 }
2849
2850 /*
2851 * Returns the total number of streams for a session or a negative value
2852 * on error.
2853 */
2854 static unsigned int get_total_nb_stream(struct ltt_session *session)
2855 {
2856 unsigned int total_streams = 0;
2857
2858 if (session->kernel_session) {
2859 struct ltt_kernel_session *ksess = session->kernel_session;
2860
2861 total_streams += ksess->stream_count_global;
2862 }
2863
2864 if (session->ust_session) {
2865 struct ltt_ust_session *usess = session->ust_session;
2866
2867 total_streams += ust_app_get_nb_stream(usess);
2868 }
2869
2870 return total_streams;
2871 }
2872
2873 /*
2874 * Command LTTNG_SNAPSHOT_RECORD from lib lttng ctl.
2875 *
2876 * The wait parameter is ignored so this call always wait for the snapshot to
2877 * complete before returning.
2878 *
2879 * Return LTTNG_OK on success or else a LTTNG_ERR code.
2880 */
2881 int cmd_snapshot_record(struct ltt_session *session,
2882 struct lttng_snapshot_output *output, int wait)
2883 {
2884 int ret = LTTNG_OK;
2885 unsigned int use_tmp_output = 0;
2886 struct snapshot_output tmp_output;
2887 unsigned int nb_streams, snapshot_success = 0;
2888
2889 assert(session);
2890
2891 DBG("Cmd snapshot record for session %s", session->name);
2892
2893 /*
2894 * Permission denied to create an output if the session is not
2895 * set in no output mode.
2896 */
2897 if (session->output_traces) {
2898 ret = LTTNG_ERR_EPERM;
2899 goto error;
2900 }
2901
2902 /* The session needs to be started at least once. */
2903 if (!session->started) {
2904 ret = LTTNG_ERR_START_SESSION_ONCE;
2905 goto error;
2906 }
2907
2908 /* Use temporary output for the session. */
2909 if (output && *output->ctrl_url != '\0') {
2910 ret = snapshot_output_init(output->max_size, output->name,
2911 output->ctrl_url, output->data_url, session->consumer,
2912 &tmp_output, NULL);
2913 if (ret < 0) {
2914 if (ret == -ENOMEM) {
2915 ret = LTTNG_ERR_NOMEM;
2916 } else {
2917 ret = LTTNG_ERR_INVALID;
2918 }
2919 goto error;
2920 }
2921 /* Use the global session count for the temporary snapshot. */
2922 tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
2923 use_tmp_output = 1;
2924 }
2925
2926 /*
2927 * Get the total number of stream of that session which is used by the
2928 * maximum size of the snapshot feature.
2929 */
2930 nb_streams = get_total_nb_stream(session);
2931
2932 if (session->kernel_session) {
2933 struct ltt_kernel_session *ksess = session->kernel_session;
2934
2935 if (use_tmp_output) {
2936 ret = record_kernel_snapshot(ksess, &tmp_output, session,
2937 wait, nb_streams);
2938 if (ret != LTTNG_OK) {
2939 goto error;
2940 }
2941 snapshot_success = 1;
2942 } else {
2943 struct snapshot_output *sout;
2944 struct lttng_ht_iter iter;
2945
2946 rcu_read_lock();
2947 cds_lfht_for_each_entry(session->snapshot.output_ht->ht,
2948 &iter.iter, sout, node.node) {
2949 /*
2950 * Make a local copy of the output and assign the possible
2951 * temporary value given by the caller.
2952 */
2953 memset(&tmp_output, 0, sizeof(tmp_output));
2954 memcpy(&tmp_output, sout, sizeof(tmp_output));
2955
2956 /* Use temporary max size. */
2957 if (output->max_size != (uint64_t) -1ULL) {
2958 tmp_output.max_size = output->max_size;
2959 }
2960
2961 /* Use temporary name. */
2962 if (*output->name != '\0') {
2963 strncpy(tmp_output.name, output->name,
2964 sizeof(tmp_output.name));
2965 }
2966
2967 tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
2968
2969 ret = record_kernel_snapshot(ksess, &tmp_output,
2970 session, wait, nb_streams);
2971 if (ret != LTTNG_OK) {
2972 rcu_read_unlock();
2973 goto error;
2974 }
2975 snapshot_success = 1;
2976 }
2977 rcu_read_unlock();
2978 }
2979 }
2980
2981 if (session->ust_session) {
2982 struct ltt_ust_session *usess = session->ust_session;
2983
2984 if (use_tmp_output) {
2985 ret = record_ust_snapshot(usess, &tmp_output, session,
2986 wait, nb_streams);
2987 if (ret != LTTNG_OK) {
2988 goto error;
2989 }
2990 snapshot_success = 1;
2991 } else {
2992 struct snapshot_output *sout;
2993 struct lttng_ht_iter iter;
2994
2995 rcu_read_lock();
2996 cds_lfht_for_each_entry(session->snapshot.output_ht->ht,
2997 &iter.iter, sout, node.node) {
2998 /*
2999 * Make a local copy of the output and assign the possible
3000 * temporary value given by the caller.
3001 */
3002 memset(&tmp_output, 0, sizeof(tmp_output));
3003 memcpy(&tmp_output, sout, sizeof(tmp_output));
3004
3005 /* Use temporary max size. */
3006 if (output->max_size != (uint64_t) -1ULL) {
3007 tmp_output.max_size = output->max_size;
3008 }
3009
3010 /* Use temporary name. */
3011 if (*output->name != '\0') {
3012 strncpy(tmp_output.name, output->name,
3013 sizeof(tmp_output.name));
3014 }
3015
3016 tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
3017
3018 ret = record_ust_snapshot(usess, &tmp_output, session,
3019 wait, nb_streams);
3020 if (ret != LTTNG_OK) {
3021 rcu_read_unlock();
3022 goto error;
3023 }
3024 snapshot_success = 1;
3025 }
3026 rcu_read_unlock();
3027 }
3028 }
3029
3030 if (snapshot_success) {
3031 session->snapshot.nb_snapshot++;
3032 } else {
3033 ret = LTTNG_ERR_SNAPSHOT_FAIL;
3034 }
3035
3036 error:
3037 return ret;
3038 }
3039
3040 /*
3041 * Init command subsystem.
3042 */
3043 void cmd_init(void)
3044 {
3045 /*
3046 * Set network sequence index to 1 for streams to match a relayd
3047 * socket on the consumer side.
3048 */
3049 pthread_mutex_lock(&relayd_net_seq_idx_lock);
3050 relayd_net_seq_idx = 1;
3051 pthread_mutex_unlock(&relayd_net_seq_idx_lock);
3052
3053 DBG("Command subsystem initialized");
3054 }
This page took 0.12083 seconds and 5 git commands to generate.