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