10fb9c4921f36ba4b4955fe90b892aeb9ce08e9b
[lttng-ust.git] / liblttng-ust-ctl / ustctl.c
1 /*
2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Copyright (C) 2011-2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License only.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #define _GNU_SOURCE
20 #include <string.h>
21 #include <lttng/ust-ctl.h>
22 #include <lttng/ust-abi.h>
23 #include <lttng/ust-events.h>
24 #include <sys/mman.h>
25 #include <byteswap.h>
26
27 #include <usterr-signal-safe.h>
28 #include <ust-comm.h>
29 #include <helper.h>
30
31 #include "../libringbuffer/backend.h"
32 #include "../libringbuffer/frontend.h"
33 #include "../liblttng-ust/wait.h"
34 #include "../liblttng-ust/lttng-rb-clients.h"
35 #include "../liblttng-ust/clock.h"
36
37 /*
38 * Number of milliseconds to retry before failing metadata writes on
39 * buffer full condition. (10 seconds)
40 */
41 #define LTTNG_METADATA_TIMEOUT_MSEC 10000
42
43 /*
44 * Channel representation within consumer.
45 */
46 struct ustctl_consumer_channel {
47 struct lttng_channel *chan; /* lttng channel buffers */
48
49 /* initial attributes */
50 struct ustctl_consumer_channel_attr attr;
51 int wait_fd; /* monitor close() */
52 int wakeup_fd; /* monitor close() */
53 };
54
55 /*
56 * Stream representation within consumer.
57 */
58 struct ustctl_consumer_stream {
59 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
60 struct lttng_ust_lib_ring_buffer *buf;
61 struct ustctl_consumer_channel *chan;
62 int shm_fd, wait_fd, wakeup_fd;
63 int cpu;
64 uint64_t memory_map_size;
65 };
66
67 extern void lttng_ring_buffer_client_overwrite_init(void);
68 extern void lttng_ring_buffer_client_overwrite_rt_init(void);
69 extern void lttng_ring_buffer_client_discard_init(void);
70 extern void lttng_ring_buffer_client_discard_rt_init(void);
71 extern void lttng_ring_buffer_metadata_client_init(void);
72 extern void lttng_ring_buffer_client_overwrite_exit(void);
73 extern void lttng_ring_buffer_client_overwrite_rt_exit(void);
74 extern void lttng_ring_buffer_client_discard_exit(void);
75 extern void lttng_ring_buffer_client_discard_rt_exit(void);
76 extern void lttng_ring_buffer_metadata_client_exit(void);
77
78 volatile enum ust_loglevel ust_loglevel;
79
80 int ustctl_release_handle(int sock, int handle)
81 {
82 struct ustcomm_ust_msg lum;
83 struct ustcomm_ust_reply lur;
84
85 if (sock < 0 || handle < 0)
86 return 0;
87 memset(&lum, 0, sizeof(lum));
88 lum.handle = handle;
89 lum.cmd = LTTNG_UST_RELEASE;
90 return ustcomm_send_app_cmd(sock, &lum, &lur);
91 }
92
93 /*
94 * If sock is negative, it means we don't have to notify the other side
95 * (e.g. application has already vanished).
96 */
97 int ustctl_release_object(int sock, struct lttng_ust_object_data *data)
98 {
99 int ret;
100
101 if (!data)
102 return -EINVAL;
103
104 switch (data->type) {
105 case LTTNG_UST_OBJECT_TYPE_CHANNEL:
106 if (data->u.channel.wakeup_fd >= 0) {
107 ret = close(data->u.channel.wakeup_fd);
108 if (ret < 0) {
109 ret = -errno;
110 return ret;
111 }
112 }
113 free(data->u.channel.data);
114 break;
115 case LTTNG_UST_OBJECT_TYPE_STREAM:
116 if (data->u.stream.shm_fd >= 0) {
117 ret = close(data->u.stream.shm_fd);
118 if (ret < 0) {
119 ret = -errno;
120 return ret;
121 }
122 }
123 if (data->u.stream.wakeup_fd >= 0) {
124 ret = close(data->u.stream.wakeup_fd);
125 if (ret < 0) {
126 ret = -errno;
127 return ret;
128 }
129 }
130 break;
131 case LTTNG_UST_OBJECT_TYPE_EVENT:
132 case LTTNG_UST_OBJECT_TYPE_CONTEXT:
133 break;
134 default:
135 assert(0);
136 }
137 return ustctl_release_handle(sock, data->handle);
138 }
139
140 /*
141 * Send registration done packet to the application.
142 */
143 int ustctl_register_done(int sock)
144 {
145 struct ustcomm_ust_msg lum;
146 struct ustcomm_ust_reply lur;
147 int ret;
148
149 DBG("Sending register done command to %d", sock);
150 memset(&lum, 0, sizeof(lum));
151 lum.handle = LTTNG_UST_ROOT_HANDLE;
152 lum.cmd = LTTNG_UST_REGISTER_DONE;
153 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
154 if (ret)
155 return ret;
156 return 0;
157 }
158
159 /*
160 * returns session handle.
161 */
162 int ustctl_create_session(int sock)
163 {
164 struct ustcomm_ust_msg lum;
165 struct ustcomm_ust_reply lur;
166 int ret, session_handle;
167
168 /* Create session */
169 memset(&lum, 0, sizeof(lum));
170 lum.handle = LTTNG_UST_ROOT_HANDLE;
171 lum.cmd = LTTNG_UST_SESSION;
172 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
173 if (ret)
174 return ret;
175 session_handle = lur.ret_val;
176 DBG("received session handle %u", session_handle);
177 return session_handle;
178 }
179
180 int ustctl_create_event(int sock, struct lttng_ust_event *ev,
181 struct lttng_ust_object_data *channel_data,
182 struct lttng_ust_object_data **_event_data)
183 {
184 struct ustcomm_ust_msg lum;
185 struct ustcomm_ust_reply lur;
186 struct lttng_ust_object_data *event_data;
187 int ret;
188
189 if (!channel_data || !_event_data)
190 return -EINVAL;
191
192 event_data = zmalloc(sizeof(*event_data));
193 if (!event_data)
194 return -ENOMEM;
195 event_data->type = LTTNG_UST_OBJECT_TYPE_EVENT;
196 memset(&lum, 0, sizeof(lum));
197 lum.handle = channel_data->handle;
198 lum.cmd = LTTNG_UST_EVENT;
199 strncpy(lum.u.event.name, ev->name,
200 LTTNG_UST_SYM_NAME_LEN);
201 lum.u.event.instrumentation = ev->instrumentation;
202 lum.u.event.loglevel_type = ev->loglevel_type;
203 lum.u.event.loglevel = ev->loglevel;
204 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
205 if (ret) {
206 free(event_data);
207 return ret;
208 }
209 event_data->handle = lur.ret_val;
210 DBG("received event handle %u", event_data->handle);
211 *_event_data = event_data;
212 return 0;
213 }
214
215 int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx,
216 struct lttng_ust_object_data *obj_data,
217 struct lttng_ust_object_data **_context_data)
218 {
219 struct ustcomm_ust_msg lum;
220 struct ustcomm_ust_reply lur;
221 struct lttng_ust_object_data *context_data = NULL;
222 char *buf = NULL;
223 size_t len;
224 int ret;
225
226 if (!obj_data || !_context_data) {
227 ret = -EINVAL;
228 goto end;
229 }
230
231 context_data = zmalloc(sizeof(*context_data));
232 if (!context_data) {
233 ret = -ENOMEM;
234 goto end;
235 }
236 context_data->type = LTTNG_UST_OBJECT_TYPE_CONTEXT;
237 memset(&lum, 0, sizeof(lum));
238 lum.handle = obj_data->handle;
239 lum.cmd = LTTNG_UST_CONTEXT;
240
241 lum.u.context.ctx = ctx->ctx;
242 switch (ctx->ctx) {
243 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
244 lum.u.context.u.perf_counter = ctx->u.perf_counter;
245 break;
246 case LTTNG_UST_CONTEXT_APP_CONTEXT:
247 {
248 size_t provider_name_len = strlen(
249 ctx->u.app_ctx.provider_name) + 1;
250 size_t ctx_name_len = strlen(ctx->u.app_ctx.ctx_name) + 1;
251
252 lum.u.context.u.app_ctx.provider_name_len = provider_name_len;
253 lum.u.context.u.app_ctx.ctx_name_len = ctx_name_len;
254
255 len = provider_name_len + ctx_name_len;
256 buf = zmalloc(len);
257 if (!buf) {
258 ret = -ENOMEM;
259 goto end;
260 }
261 memcpy(buf, ctx->u.app_ctx.provider_name,
262 provider_name_len);
263 memcpy(buf + provider_name_len, ctx->u.app_ctx.ctx_name,
264 ctx_name_len);
265 break;
266 }
267 default:
268 break;
269 }
270 ret = ustcomm_send_app_msg(sock, &lum);
271 if (ret)
272 goto end;
273 if (buf) {
274 /* send var len ctx_name */
275 ret = ustcomm_send_unix_sock(sock, buf, len);
276 if (ret < 0) {
277 goto end;
278 }
279 if (ret != len) {
280 ret = -EINVAL;
281 goto end;
282 }
283 }
284 ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
285 if (ret < 0) {
286 goto end;
287 }
288 context_data->handle = -1;
289 DBG("Context created successfully");
290 *_context_data = context_data;
291 context_data = NULL;
292 end:
293 free(context_data);
294 free(buf);
295 return ret;
296 }
297
298 int ustctl_set_filter(int sock, struct lttng_ust_filter_bytecode *bytecode,
299 struct lttng_ust_object_data *obj_data)
300 {
301 struct ustcomm_ust_msg lum;
302 struct ustcomm_ust_reply lur;
303 int ret;
304
305 if (!obj_data)
306 return -EINVAL;
307
308 memset(&lum, 0, sizeof(lum));
309 lum.handle = obj_data->handle;
310 lum.cmd = LTTNG_UST_FILTER;
311 lum.u.filter.data_size = bytecode->len;
312 lum.u.filter.reloc_offset = bytecode->reloc_offset;
313 lum.u.filter.seqnum = bytecode->seqnum;
314
315 ret = ustcomm_send_app_msg(sock, &lum);
316 if (ret)
317 return ret;
318 /* send var len bytecode */
319 ret = ustcomm_send_unix_sock(sock, bytecode->data,
320 bytecode->len);
321 if (ret < 0) {
322 return ret;
323 }
324 if (ret != bytecode->len)
325 return -EINVAL;
326 return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
327 }
328
329 int ustctl_set_exclusion(int sock, struct lttng_ust_event_exclusion *exclusion,
330 struct lttng_ust_object_data *obj_data)
331 {
332 struct ustcomm_ust_msg lum;
333 struct ustcomm_ust_reply lur;
334 int ret;
335
336 if (!obj_data) {
337 return -EINVAL;
338 }
339
340 memset(&lum, 0, sizeof(lum));
341 lum.handle = obj_data->handle;
342 lum.cmd = LTTNG_UST_EXCLUSION;
343 lum.u.exclusion.count = exclusion->count;
344
345 ret = ustcomm_send_app_msg(sock, &lum);
346 if (ret) {
347 return ret;
348 }
349
350 /* send var len exclusion names */
351 ret = ustcomm_send_unix_sock(sock,
352 exclusion->names,
353 exclusion->count * LTTNG_UST_SYM_NAME_LEN);
354 if (ret < 0) {
355 return ret;
356 }
357 if (ret != exclusion->count * LTTNG_UST_SYM_NAME_LEN) {
358 return -EINVAL;
359 }
360 return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
361 }
362
363 /* Enable event, channel and session ioctl */
364 int ustctl_enable(int sock, struct lttng_ust_object_data *object)
365 {
366 struct ustcomm_ust_msg lum;
367 struct ustcomm_ust_reply lur;
368 int ret;
369
370 if (!object)
371 return -EINVAL;
372
373 memset(&lum, 0, sizeof(lum));
374 lum.handle = object->handle;
375 lum.cmd = LTTNG_UST_ENABLE;
376 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
377 if (ret)
378 return ret;
379 DBG("enabled handle %u", object->handle);
380 return 0;
381 }
382
383 /* Disable event, channel and session ioctl */
384 int ustctl_disable(int sock, struct lttng_ust_object_data *object)
385 {
386 struct ustcomm_ust_msg lum;
387 struct ustcomm_ust_reply lur;
388 int ret;
389
390 if (!object)
391 return -EINVAL;
392
393 memset(&lum, 0, sizeof(lum));
394 lum.handle = object->handle;
395 lum.cmd = LTTNG_UST_DISABLE;
396 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
397 if (ret)
398 return ret;
399 DBG("disable handle %u", object->handle);
400 return 0;
401 }
402
403 int ustctl_start_session(int sock, int handle)
404 {
405 struct lttng_ust_object_data obj;
406
407 obj.handle = handle;
408 return ustctl_enable(sock, &obj);
409 }
410
411 int ustctl_stop_session(int sock, int handle)
412 {
413 struct lttng_ust_object_data obj;
414
415 obj.handle = handle;
416 return ustctl_disable(sock, &obj);
417 }
418
419 int ustctl_tracepoint_list(int sock)
420 {
421 struct ustcomm_ust_msg lum;
422 struct ustcomm_ust_reply lur;
423 int ret, tp_list_handle;
424
425 memset(&lum, 0, sizeof(lum));
426 lum.handle = LTTNG_UST_ROOT_HANDLE;
427 lum.cmd = LTTNG_UST_TRACEPOINT_LIST;
428 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
429 if (ret)
430 return ret;
431 tp_list_handle = lur.ret_val;
432 DBG("received tracepoint list handle %u", tp_list_handle);
433 return tp_list_handle;
434 }
435
436 int ustctl_tracepoint_list_get(int sock, int tp_list_handle,
437 struct lttng_ust_tracepoint_iter *iter)
438 {
439 struct ustcomm_ust_msg lum;
440 struct ustcomm_ust_reply lur;
441 int ret;
442
443 if (!iter)
444 return -EINVAL;
445
446 memset(&lum, 0, sizeof(lum));
447 lum.handle = tp_list_handle;
448 lum.cmd = LTTNG_UST_TRACEPOINT_LIST_GET;
449 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
450 if (ret)
451 return ret;
452 DBG("received tracepoint list entry name %s loglevel %d",
453 lur.u.tracepoint.name,
454 lur.u.tracepoint.loglevel);
455 memcpy(iter, &lur.u.tracepoint, sizeof(*iter));
456 return 0;
457 }
458
459 int ustctl_tracepoint_field_list(int sock)
460 {
461 struct ustcomm_ust_msg lum;
462 struct ustcomm_ust_reply lur;
463 int ret, tp_field_list_handle;
464
465 memset(&lum, 0, sizeof(lum));
466 lum.handle = LTTNG_UST_ROOT_HANDLE;
467 lum.cmd = LTTNG_UST_TRACEPOINT_FIELD_LIST;
468 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
469 if (ret)
470 return ret;
471 tp_field_list_handle = lur.ret_val;
472 DBG("received tracepoint field list handle %u", tp_field_list_handle);
473 return tp_field_list_handle;
474 }
475
476 int ustctl_tracepoint_field_list_get(int sock, int tp_field_list_handle,
477 struct lttng_ust_field_iter *iter)
478 {
479 struct ustcomm_ust_msg lum;
480 struct ustcomm_ust_reply lur;
481 int ret;
482 ssize_t len;
483
484 if (!iter)
485 return -EINVAL;
486
487 memset(&lum, 0, sizeof(lum));
488 lum.handle = tp_field_list_handle;
489 lum.cmd = LTTNG_UST_TRACEPOINT_FIELD_LIST_GET;
490 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
491 if (ret)
492 return ret;
493 len = ustcomm_recv_unix_sock(sock, iter, sizeof(*iter));
494 if (len != sizeof(*iter)) {
495 return -EINVAL;
496 }
497 DBG("received tracepoint field list entry event_name %s event_loglevel %d field_name %s field_type %d",
498 iter->event_name,
499 iter->loglevel,
500 iter->field_name,
501 iter->type);
502 return 0;
503 }
504
505 int ustctl_tracer_version(int sock, struct lttng_ust_tracer_version *v)
506 {
507 struct ustcomm_ust_msg lum;
508 struct ustcomm_ust_reply lur;
509 int ret;
510
511 if (!v)
512 return -EINVAL;
513
514 memset(&lum, 0, sizeof(lum));
515 lum.handle = LTTNG_UST_ROOT_HANDLE;
516 lum.cmd = LTTNG_UST_TRACER_VERSION;
517 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
518 if (ret)
519 return ret;
520 memcpy(v, &lur.u.version, sizeof(*v));
521 DBG("received tracer version");
522 return 0;
523 }
524
525 int ustctl_wait_quiescent(int sock)
526 {
527 struct ustcomm_ust_msg lum;
528 struct ustcomm_ust_reply lur;
529 int ret;
530
531 memset(&lum, 0, sizeof(lum));
532 lum.handle = LTTNG_UST_ROOT_HANDLE;
533 lum.cmd = LTTNG_UST_WAIT_QUIESCENT;
534 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
535 if (ret)
536 return ret;
537 DBG("waited for quiescent state");
538 return 0;
539 }
540
541 int ustctl_calibrate(int sock, struct lttng_ust_calibrate *calibrate)
542 {
543 if (!calibrate)
544 return -EINVAL;
545
546 return -ENOSYS;
547 }
548
549 int ustctl_sock_flush_buffer(int sock, struct lttng_ust_object_data *object)
550 {
551 struct ustcomm_ust_msg lum;
552 struct ustcomm_ust_reply lur;
553 int ret;
554
555 if (!object)
556 return -EINVAL;
557
558 memset(&lum, 0, sizeof(lum));
559 lum.handle = object->handle;
560 lum.cmd = LTTNG_UST_FLUSH_BUFFER;
561 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
562 if (ret)
563 return ret;
564 DBG("flushed buffer handle %u", object->handle);
565 return 0;
566 }
567
568 static
569 int ustctl_send_channel(int sock,
570 enum lttng_ust_chan_type type,
571 void *data,
572 uint64_t size,
573 int wakeup_fd,
574 int send_fd_only)
575 {
576 ssize_t len;
577
578 if (!send_fd_only) {
579 /* Send mmap size */
580 len = ustcomm_send_unix_sock(sock, &size, sizeof(size));
581 if (len != sizeof(size)) {
582 if (len < 0)
583 return len;
584 else
585 return -EIO;
586 }
587
588 /* Send channel type */
589 len = ustcomm_send_unix_sock(sock, &type, sizeof(type));
590 if (len != sizeof(type)) {
591 if (len < 0)
592 return len;
593 else
594 return -EIO;
595 }
596 }
597
598 /* Send channel data */
599 len = ustcomm_send_unix_sock(sock, data, size);
600 if (len != size) {
601 if (len < 0)
602 return len;
603 else
604 return -EIO;
605 }
606
607 /* Send wakeup fd */
608 len = ustcomm_send_fds_unix_sock(sock, &wakeup_fd, 1);
609 if (len <= 0) {
610 if (len < 0)
611 return len;
612 else
613 return -EIO;
614 }
615 return 0;
616 }
617
618 static
619 int ustctl_send_stream(int sock,
620 uint32_t stream_nr,
621 uint64_t memory_map_size,
622 int shm_fd, int wakeup_fd,
623 int send_fd_only)
624 {
625 ssize_t len;
626 int fds[2];
627
628 if (!send_fd_only) {
629 if (shm_fd < 0) {
630 /* finish iteration */
631 uint64_t v = -1;
632
633 len = ustcomm_send_unix_sock(sock, &v, sizeof(v));
634 if (len != sizeof(v)) {
635 if (len < 0)
636 return len;
637 else
638 return -EIO;
639 }
640 return 0;
641 }
642
643 /* Send mmap size */
644 len = ustcomm_send_unix_sock(sock, &memory_map_size,
645 sizeof(memory_map_size));
646 if (len != sizeof(memory_map_size)) {
647 if (len < 0)
648 return len;
649 else
650 return -EIO;
651 }
652
653 /* Send stream nr */
654 len = ustcomm_send_unix_sock(sock, &stream_nr,
655 sizeof(stream_nr));
656 if (len != sizeof(stream_nr)) {
657 if (len < 0)
658 return len;
659 else
660 return -EIO;
661 }
662 }
663
664 /* Send shm fd and wakeup fd */
665 fds[0] = shm_fd;
666 fds[1] = wakeup_fd;
667 len = ustcomm_send_fds_unix_sock(sock, fds, 2);
668 if (len <= 0) {
669 if (len < 0)
670 return len;
671 else
672 return -EIO;
673 }
674 return 0;
675 }
676
677 int ustctl_recv_channel_from_consumer(int sock,
678 struct lttng_ust_object_data **_channel_data)
679 {
680 struct lttng_ust_object_data *channel_data;
681 ssize_t len;
682 int wakeup_fd;
683 int ret;
684
685 channel_data = zmalloc(sizeof(*channel_data));
686 if (!channel_data) {
687 ret = -ENOMEM;
688 goto error_alloc;
689 }
690 channel_data->type = LTTNG_UST_OBJECT_TYPE_CHANNEL;
691 channel_data->handle = -1;
692
693 /* recv mmap size */
694 len = ustcomm_recv_unix_sock(sock, &channel_data->size,
695 sizeof(channel_data->size));
696 if (len != sizeof(channel_data->size)) {
697 if (len < 0)
698 ret = len;
699 else
700 ret = -EINVAL;
701 goto error;
702 }
703
704 /* recv channel type */
705 len = ustcomm_recv_unix_sock(sock, &channel_data->u.channel.type,
706 sizeof(channel_data->u.channel.type));
707 if (len != sizeof(channel_data->u.channel.type)) {
708 if (len < 0)
709 ret = len;
710 else
711 ret = -EINVAL;
712 goto error;
713 }
714
715 /* recv channel data */
716 channel_data->u.channel.data = zmalloc(channel_data->size);
717 if (!channel_data->u.channel.data) {
718 ret = -ENOMEM;
719 goto error;
720 }
721 len = ustcomm_recv_unix_sock(sock, channel_data->u.channel.data,
722 channel_data->size);
723 if (len != channel_data->size) {
724 if (len < 0)
725 ret = len;
726 else
727 ret = -EINVAL;
728 goto error_recv_data;
729 }
730 /* recv wakeup fd */
731 len = ustcomm_recv_fds_unix_sock(sock, &wakeup_fd, 1);
732 if (len <= 0) {
733 if (len < 0) {
734 ret = len;
735 goto error_recv_data;
736 } else {
737 ret = -EIO;
738 goto error_recv_data;
739 }
740 }
741 channel_data->u.channel.wakeup_fd = wakeup_fd;
742 *_channel_data = channel_data;
743 return 0;
744
745 error_recv_data:
746 free(channel_data->u.channel.data);
747 error:
748 free(channel_data);
749 error_alloc:
750 return ret;
751 }
752
753 int ustctl_recv_stream_from_consumer(int sock,
754 struct lttng_ust_object_data **_stream_data)
755 {
756 struct lttng_ust_object_data *stream_data;
757 ssize_t len;
758 int ret;
759 int fds[2];
760
761 stream_data = zmalloc(sizeof(*stream_data));
762 if (!stream_data) {
763 ret = -ENOMEM;
764 goto error_alloc;
765 }
766
767 stream_data->type = LTTNG_UST_OBJECT_TYPE_STREAM;
768 stream_data->handle = -1;
769
770 /* recv mmap size */
771 len = ustcomm_recv_unix_sock(sock, &stream_data->size,
772 sizeof(stream_data->size));
773 if (len != sizeof(stream_data->size)) {
774 if (len < 0)
775 ret = len;
776 else
777 ret = -EINVAL;
778 goto error;
779 }
780 if (stream_data->size == -1) {
781 ret = -LTTNG_UST_ERR_NOENT;
782 goto error;
783 }
784
785 /* recv stream nr */
786 len = ustcomm_recv_unix_sock(sock, &stream_data->u.stream.stream_nr,
787 sizeof(stream_data->u.stream.stream_nr));
788 if (len != sizeof(stream_data->u.stream.stream_nr)) {
789 if (len < 0)
790 ret = len;
791 else
792 ret = -EINVAL;
793 goto error;
794 }
795
796 /* recv shm fd and wakeup fd */
797 len = ustcomm_recv_fds_unix_sock(sock, fds, 2);
798 if (len <= 0) {
799 if (len < 0) {
800 ret = len;
801 goto error;
802 } else {
803 ret = -EIO;
804 goto error;
805 }
806 }
807 stream_data->u.stream.shm_fd = fds[0];
808 stream_data->u.stream.wakeup_fd = fds[1];
809 *_stream_data = stream_data;
810 return 0;
811
812 error:
813 free(stream_data);
814 error_alloc:
815 return ret;
816 }
817
818 int ustctl_send_channel_to_ust(int sock, int session_handle,
819 struct lttng_ust_object_data *channel_data)
820 {
821 struct ustcomm_ust_msg lum;
822 struct ustcomm_ust_reply lur;
823 int ret;
824
825 if (!channel_data)
826 return -EINVAL;
827
828 memset(&lum, 0, sizeof(lum));
829 lum.handle = session_handle;
830 lum.cmd = LTTNG_UST_CHANNEL;
831 lum.u.channel.len = channel_data->size;
832 lum.u.channel.type = channel_data->u.channel.type;
833 ret = ustcomm_send_app_msg(sock, &lum);
834 if (ret)
835 return ret;
836
837 ret = ustctl_send_channel(sock,
838 channel_data->u.channel.type,
839 channel_data->u.channel.data,
840 channel_data->size,
841 channel_data->u.channel.wakeup_fd,
842 1);
843 if (ret)
844 return ret;
845 ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
846 if (!ret) {
847 channel_data->handle = lur.ret_val;
848 }
849 return ret;
850 }
851
852 int ustctl_send_stream_to_ust(int sock,
853 struct lttng_ust_object_data *channel_data,
854 struct lttng_ust_object_data *stream_data)
855 {
856 struct ustcomm_ust_msg lum;
857 struct ustcomm_ust_reply lur;
858 int ret;
859
860 memset(&lum, 0, sizeof(lum));
861 lum.handle = channel_data->handle;
862 lum.cmd = LTTNG_UST_STREAM;
863 lum.u.stream.len = stream_data->size;
864 lum.u.stream.stream_nr = stream_data->u.stream.stream_nr;
865 ret = ustcomm_send_app_msg(sock, &lum);
866 if (ret)
867 return ret;
868
869 assert(stream_data);
870 assert(stream_data->type == LTTNG_UST_OBJECT_TYPE_STREAM);
871
872 ret = ustctl_send_stream(sock,
873 stream_data->u.stream.stream_nr,
874 stream_data->size,
875 stream_data->u.stream.shm_fd,
876 stream_data->u.stream.wakeup_fd, 1);
877 if (ret)
878 return ret;
879 return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
880 }
881
882 int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data **dest,
883 struct lttng_ust_object_data *src)
884 {
885 struct lttng_ust_object_data *obj;
886 int ret;
887
888 if (src->handle != -1) {
889 ret = -EINVAL;
890 goto error;
891 }
892
893 obj = zmalloc(sizeof(*obj));
894 if (!obj) {
895 ret = -ENOMEM;
896 goto error;
897 }
898
899 obj->type = src->type;
900 obj->handle = src->handle;
901 obj->size = src->size;
902
903 switch (obj->type) {
904 case LTTNG_UST_OBJECT_TYPE_CHANNEL:
905 {
906 obj->u.channel.type = src->u.channel.type;
907 if (src->u.channel.wakeup_fd >= 0) {
908 obj->u.channel.wakeup_fd =
909 dup(src->u.channel.wakeup_fd);
910 if (obj->u.channel.wakeup_fd < 0) {
911 ret = errno;
912 goto chan_error_wakeup_fd;
913 }
914 } else {
915 obj->u.channel.wakeup_fd =
916 src->u.channel.wakeup_fd;
917 }
918 obj->u.channel.data = zmalloc(obj->size);
919 if (!obj->u.channel.data) {
920 ret = -ENOMEM;
921 goto chan_error_alloc;
922 }
923 memcpy(obj->u.channel.data, src->u.channel.data, obj->size);
924 break;
925
926 chan_error_alloc:
927 if (src->u.channel.wakeup_fd >= 0) {
928 int closeret;
929
930 closeret = close(obj->u.channel.wakeup_fd);
931 if (closeret) {
932 PERROR("close");
933 }
934 }
935 chan_error_wakeup_fd:
936 goto error_type;
937
938 }
939
940 case LTTNG_UST_OBJECT_TYPE_STREAM:
941 {
942 obj->u.stream.stream_nr = src->u.stream.stream_nr;
943 if (src->u.stream.wakeup_fd >= 0) {
944 obj->u.stream.wakeup_fd =
945 dup(src->u.stream.wakeup_fd);
946 if (obj->u.stream.wakeup_fd < 0) {
947 ret = errno;
948 goto stream_error_wakeup_fd;
949 }
950 } else {
951 obj->u.stream.wakeup_fd =
952 src->u.stream.wakeup_fd;
953 }
954
955 if (src->u.stream.shm_fd >= 0) {
956 obj->u.stream.shm_fd =
957 dup(src->u.stream.shm_fd);
958 if (obj->u.stream.shm_fd < 0) {
959 ret = errno;
960 goto stream_error_shm_fd;
961 }
962 } else {
963 obj->u.stream.shm_fd =
964 src->u.stream.shm_fd;
965 }
966 break;
967
968 stream_error_shm_fd:
969 if (src->u.stream.wakeup_fd >= 0) {
970 int closeret;
971
972 closeret = close(obj->u.stream.wakeup_fd);
973 if (closeret) {
974 PERROR("close");
975 }
976 }
977 stream_error_wakeup_fd:
978 goto error_type;
979 }
980
981 default:
982 ret = -EINVAL;
983 goto error_type;
984 }
985
986 *dest = obj;
987 return 0;
988
989 error_type:
990 free(obj);
991 error:
992 return ret;
993 }
994
995
996 /* Buffer operations */
997
998 int ustctl_get_nr_stream_per_channel(void)
999 {
1000 return num_possible_cpus();
1001 }
1002
1003 struct ustctl_consumer_channel *
1004 ustctl_create_channel(struct ustctl_consumer_channel_attr *attr,
1005 const int *stream_fds, int nr_stream_fds)
1006 {
1007 struct ustctl_consumer_channel *chan;
1008 const char *transport_name;
1009 struct lttng_transport *transport;
1010
1011 switch (attr->type) {
1012 case LTTNG_UST_CHAN_PER_CPU:
1013 if (attr->output == LTTNG_UST_MMAP) {
1014 if (attr->overwrite) {
1015 if (attr->read_timer_interval == 0) {
1016 transport_name = "relay-overwrite-mmap";
1017 } else {
1018 transport_name = "relay-overwrite-rt-mmap";
1019 }
1020 } else {
1021 if (attr->read_timer_interval == 0) {
1022 transport_name = "relay-discard-mmap";
1023 } else {
1024 transport_name = "relay-discard-rt-mmap";
1025 }
1026 }
1027 } else {
1028 return NULL;
1029 }
1030 break;
1031 case LTTNG_UST_CHAN_METADATA:
1032 if (attr->output == LTTNG_UST_MMAP)
1033 transport_name = "relay-metadata-mmap";
1034 else
1035 return NULL;
1036 break;
1037 default:
1038 transport_name = "<unknown>";
1039 return NULL;
1040 }
1041
1042 transport = lttng_transport_find(transport_name);
1043 if (!transport) {
1044 DBG("LTTng transport %s not found\n",
1045 transport_name);
1046 return NULL;
1047 }
1048
1049 chan = zmalloc(sizeof(*chan));
1050 if (!chan)
1051 return NULL;
1052
1053 chan->chan = transport->ops.channel_create(transport_name, NULL,
1054 attr->subbuf_size, attr->num_subbuf,
1055 attr->switch_timer_interval,
1056 attr->read_timer_interval,
1057 attr->uuid, attr->chan_id,
1058 stream_fds, nr_stream_fds);
1059 if (!chan->chan) {
1060 goto chan_error;
1061 }
1062 chan->chan->ops = &transport->ops;
1063 memcpy(&chan->attr, attr, sizeof(chan->attr));
1064 chan->wait_fd = ustctl_channel_get_wait_fd(chan);
1065 chan->wakeup_fd = ustctl_channel_get_wakeup_fd(chan);
1066 return chan;
1067
1068 chan_error:
1069 free(chan);
1070 return NULL;
1071 }
1072
1073 void ustctl_destroy_channel(struct ustctl_consumer_channel *chan)
1074 {
1075 (void) ustctl_channel_close_wait_fd(chan);
1076 (void) ustctl_channel_close_wakeup_fd(chan);
1077 chan->chan->ops->channel_destroy(chan->chan);
1078 free(chan);
1079 }
1080
1081 int ustctl_send_channel_to_sessiond(int sock,
1082 struct ustctl_consumer_channel *channel)
1083 {
1084 struct shm_object_table *table;
1085
1086 table = channel->chan->handle->table;
1087 if (table->size <= 0)
1088 return -EINVAL;
1089 return ustctl_send_channel(sock,
1090 channel->attr.type,
1091 table->objects[0].memory_map,
1092 table->objects[0].memory_map_size,
1093 channel->wakeup_fd,
1094 0);
1095 }
1096
1097 int ustctl_send_stream_to_sessiond(int sock,
1098 struct ustctl_consumer_stream *stream)
1099 {
1100 if (!stream)
1101 return ustctl_send_stream(sock, -1U, -1U, -1, -1, 0);
1102
1103 return ustctl_send_stream(sock,
1104 stream->cpu,
1105 stream->memory_map_size,
1106 stream->shm_fd, stream->wakeup_fd,
1107 0);
1108 }
1109
1110 int ustctl_write_metadata_to_channel(
1111 struct ustctl_consumer_channel *channel,
1112 const char *metadata_str, /* NOT null-terminated */
1113 size_t len) /* metadata length */
1114 {
1115 struct lttng_ust_lib_ring_buffer_ctx ctx;
1116 struct lttng_channel *chan = channel->chan;
1117 const char *str = metadata_str;
1118 int ret = 0, waitret;
1119 size_t reserve_len, pos;
1120
1121 for (pos = 0; pos < len; pos += reserve_len) {
1122 reserve_len = min_t(size_t,
1123 chan->ops->packet_avail_size(chan->chan, chan->handle),
1124 len - pos);
1125 lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len,
1126 sizeof(char), -1, chan->handle, NULL);
1127 /*
1128 * We don't care about metadata buffer's records lost
1129 * count, because we always retry here. Report error if
1130 * we need to bail out after timeout or being
1131 * interrupted.
1132 */
1133 waitret = wait_cond_interruptible_timeout(
1134 ({
1135 ret = chan->ops->event_reserve(&ctx, 0);
1136 ret != -ENOBUFS || !ret;
1137 }),
1138 LTTNG_METADATA_TIMEOUT_MSEC);
1139 if (waitret == -ETIMEDOUT || waitret == -EINTR || ret) {
1140 DBG("LTTng: Failure to write metadata to buffers (%s)\n",
1141 waitret == -EINTR ? "interrupted" :
1142 (ret == -ENOBUFS ? "timeout" : "I/O error"));
1143 if (waitret == -EINTR)
1144 ret = waitret;
1145 goto end;
1146 }
1147 chan->ops->event_write(&ctx, &str[pos], reserve_len);
1148 chan->ops->event_commit(&ctx);
1149 }
1150 end:
1151 return ret;
1152 }
1153
1154 /*
1155 * Write at most one packet in the channel.
1156 * Returns the number of bytes written on success, < 0 on error.
1157 */
1158 ssize_t ustctl_write_one_packet_to_channel(
1159 struct ustctl_consumer_channel *channel,
1160 const char *metadata_str, /* NOT null-terminated */
1161 size_t len) /* metadata length */
1162 {
1163 struct lttng_ust_lib_ring_buffer_ctx ctx;
1164 struct lttng_channel *chan = channel->chan;
1165 const char *str = metadata_str;
1166 ssize_t reserve_len;
1167 int ret;
1168
1169 reserve_len = min_t(ssize_t,
1170 chan->ops->packet_avail_size(chan->chan, chan->handle),
1171 len);
1172 lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len,
1173 sizeof(char), -1, chan->handle, NULL);
1174 ret = chan->ops->event_reserve(&ctx, 0);
1175 if (ret != 0) {
1176 DBG("LTTng: event reservation failed");
1177 assert(ret < 0);
1178 reserve_len = ret;
1179 goto end;
1180 }
1181 chan->ops->event_write(&ctx, str, reserve_len);
1182 chan->ops->event_commit(&ctx);
1183
1184 end:
1185 return reserve_len;
1186 }
1187
1188 int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel *consumer_chan)
1189 {
1190 struct channel *chan;
1191 int ret;
1192
1193 chan = consumer_chan->chan->chan;
1194 ret = ring_buffer_channel_close_wait_fd(&chan->backend.config,
1195 chan, chan->handle);
1196 if (!ret)
1197 consumer_chan->wait_fd = -1;
1198 return ret;
1199 }
1200
1201 int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel *consumer_chan)
1202 {
1203 struct channel *chan;
1204 int ret;
1205
1206 chan = consumer_chan->chan->chan;
1207 ret = ring_buffer_channel_close_wakeup_fd(&chan->backend.config,
1208 chan, chan->handle);
1209 if (!ret)
1210 consumer_chan->wakeup_fd = -1;
1211 return ret;
1212 }
1213
1214 int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream *stream)
1215 {
1216 struct channel *chan;
1217
1218 chan = stream->chan->chan->chan;
1219 return ring_buffer_stream_close_wait_fd(&chan->backend.config,
1220 chan, stream->handle, stream->cpu);
1221 }
1222
1223 int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream *stream)
1224 {
1225 struct channel *chan;
1226
1227 chan = stream->chan->chan->chan;
1228 return ring_buffer_stream_close_wakeup_fd(&chan->backend.config,
1229 chan, stream->handle, stream->cpu);
1230 }
1231
1232 struct ustctl_consumer_stream *
1233 ustctl_create_stream(struct ustctl_consumer_channel *channel,
1234 int cpu)
1235 {
1236 struct ustctl_consumer_stream *stream;
1237 struct lttng_ust_shm_handle *handle;
1238 struct channel *chan;
1239 int shm_fd, wait_fd, wakeup_fd;
1240 uint64_t memory_map_size;
1241 struct lttng_ust_lib_ring_buffer *buf;
1242 int ret;
1243
1244 if (!channel)
1245 return NULL;
1246 handle = channel->chan->handle;
1247 if (!handle)
1248 return NULL;
1249
1250 chan = channel->chan->chan;
1251 buf = channel_get_ring_buffer(&chan->backend.config,
1252 chan, cpu, handle, &shm_fd, &wait_fd,
1253 &wakeup_fd, &memory_map_size);
1254 if (!buf)
1255 return NULL;
1256 ret = lib_ring_buffer_open_read(buf, handle);
1257 if (ret)
1258 return NULL;
1259
1260 stream = zmalloc(sizeof(*stream));
1261 if (!stream)
1262 goto alloc_error;
1263 stream->handle = handle;
1264 stream->buf = buf;
1265 stream->chan = channel;
1266 stream->shm_fd = shm_fd;
1267 stream->wait_fd = wait_fd;
1268 stream->wakeup_fd = wakeup_fd;
1269 stream->memory_map_size = memory_map_size;
1270 stream->cpu = cpu;
1271 return stream;
1272
1273 alloc_error:
1274 return NULL;
1275 }
1276
1277 void ustctl_destroy_stream(struct ustctl_consumer_stream *stream)
1278 {
1279 struct lttng_ust_lib_ring_buffer *buf;
1280 struct ustctl_consumer_channel *consumer_chan;
1281
1282 assert(stream);
1283 buf = stream->buf;
1284 consumer_chan = stream->chan;
1285 (void) ustctl_stream_close_wait_fd(stream);
1286 (void) ustctl_stream_close_wakeup_fd(stream);
1287 lib_ring_buffer_release_read(buf, consumer_chan->chan->handle);
1288 free(stream);
1289 }
1290
1291 int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel *chan)
1292 {
1293 if (!chan)
1294 return -EINVAL;
1295 return shm_get_wait_fd(chan->chan->handle,
1296 &chan->chan->handle->chan._ref);
1297 }
1298
1299 int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel *chan)
1300 {
1301 if (!chan)
1302 return -EINVAL;
1303 return shm_get_wakeup_fd(chan->chan->handle,
1304 &chan->chan->handle->chan._ref);
1305 }
1306
1307 int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream *stream)
1308 {
1309 struct lttng_ust_lib_ring_buffer *buf;
1310 struct ustctl_consumer_channel *consumer_chan;
1311
1312 if (!stream)
1313 return -EINVAL;
1314 buf = stream->buf;
1315 consumer_chan = stream->chan;
1316 return shm_get_wait_fd(consumer_chan->chan->handle, &buf->self._ref);
1317 }
1318
1319 int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream *stream)
1320 {
1321 struct lttng_ust_lib_ring_buffer *buf;
1322 struct ustctl_consumer_channel *consumer_chan;
1323
1324 if (!stream)
1325 return -EINVAL;
1326 buf = stream->buf;
1327 consumer_chan = stream->chan;
1328 return shm_get_wakeup_fd(consumer_chan->chan->handle, &buf->self._ref);
1329 }
1330
1331 /* For mmap mode, readable without "get" operation */
1332
1333 void *ustctl_get_mmap_base(struct ustctl_consumer_stream *stream)
1334 {
1335 struct lttng_ust_lib_ring_buffer *buf;
1336 struct ustctl_consumer_channel *consumer_chan;
1337
1338 if (!stream)
1339 return NULL;
1340 buf = stream->buf;
1341 consumer_chan = stream->chan;
1342 return shmp(consumer_chan->chan->handle, buf->backend.memory_map);
1343 }
1344
1345 /* returns the length to mmap. */
1346 int ustctl_get_mmap_len(struct ustctl_consumer_stream *stream,
1347 unsigned long *len)
1348 {
1349 struct ustctl_consumer_channel *consumer_chan;
1350 unsigned long mmap_buf_len;
1351 struct channel *chan;
1352
1353 if (!stream)
1354 return -EINVAL;
1355 consumer_chan = stream->chan;
1356 chan = consumer_chan->chan->chan;
1357 if (chan->backend.config.output != RING_BUFFER_MMAP)
1358 return -EINVAL;
1359 mmap_buf_len = chan->backend.buf_size;
1360 if (chan->backend.extra_reader_sb)
1361 mmap_buf_len += chan->backend.subbuf_size;
1362 if (mmap_buf_len > INT_MAX)
1363 return -EFBIG;
1364 *len = mmap_buf_len;
1365 return 0;
1366 }
1367
1368 /* returns the maximum size for sub-buffers. */
1369 int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream *stream,
1370 unsigned long *len)
1371 {
1372 struct ustctl_consumer_channel *consumer_chan;
1373 struct channel *chan;
1374
1375 if (!stream)
1376 return -EINVAL;
1377 consumer_chan = stream->chan;
1378 chan = consumer_chan->chan->chan;
1379 *len = chan->backend.subbuf_size;
1380 return 0;
1381 }
1382
1383 /*
1384 * For mmap mode, operate on the current packet (between get/put or
1385 * get_next/put_next).
1386 */
1387
1388 /* returns the offset of the subbuffer belonging to the mmap reader. */
1389 int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream *stream,
1390 unsigned long *off)
1391 {
1392 struct channel *chan;
1393 unsigned long sb_bindex;
1394 struct lttng_ust_lib_ring_buffer *buf;
1395 struct ustctl_consumer_channel *consumer_chan;
1396 struct lttng_ust_lib_ring_buffer_backend_pages_shmp *barray_idx;
1397 struct lttng_ust_lib_ring_buffer_backend_pages *pages;
1398
1399 if (!stream)
1400 return -EINVAL;
1401 buf = stream->buf;
1402 consumer_chan = stream->chan;
1403 chan = consumer_chan->chan->chan;
1404 if (chan->backend.config.output != RING_BUFFER_MMAP)
1405 return -EINVAL;
1406 sb_bindex = subbuffer_id_get_index(&chan->backend.config,
1407 buf->backend.buf_rsb.id);
1408 barray_idx = shmp_index(consumer_chan->chan->handle, buf->backend.array,
1409 sb_bindex);
1410 if (!barray_idx)
1411 return -EINVAL;
1412 pages = shmp(consumer_chan->chan->handle, barray_idx->shmp);
1413 if (!pages)
1414 return -EINVAL;
1415 *off = pages->mmap_offset;
1416 return 0;
1417 }
1418
1419 /* returns the size of the current sub-buffer, without padding (for mmap). */
1420 int ustctl_get_subbuf_size(struct ustctl_consumer_stream *stream,
1421 unsigned long *len)
1422 {
1423 struct ustctl_consumer_channel *consumer_chan;
1424 struct channel *chan;
1425 struct lttng_ust_lib_ring_buffer *buf;
1426
1427 if (!stream)
1428 return -EINVAL;
1429
1430 buf = stream->buf;
1431 consumer_chan = stream->chan;
1432 chan = consumer_chan->chan->chan;
1433 *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf,
1434 consumer_chan->chan->handle);
1435 return 0;
1436 }
1437
1438 /* returns the size of the current sub-buffer, without padding (for mmap). */
1439 int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream *stream,
1440 unsigned long *len)
1441 {
1442 struct ustctl_consumer_channel *consumer_chan;
1443 struct channel *chan;
1444 struct lttng_ust_lib_ring_buffer *buf;
1445
1446 if (!stream)
1447 return -EINVAL;
1448 buf = stream->buf;
1449 consumer_chan = stream->chan;
1450 chan = consumer_chan->chan->chan;
1451 *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf,
1452 consumer_chan->chan->handle);
1453 *len = PAGE_ALIGN(*len);
1454 return 0;
1455 }
1456
1457 /* Get exclusive read access to the next sub-buffer that can be read. */
1458 int ustctl_get_next_subbuf(struct ustctl_consumer_stream *stream)
1459 {
1460 struct lttng_ust_lib_ring_buffer *buf;
1461 struct ustctl_consumer_channel *consumer_chan;
1462
1463 if (!stream)
1464 return -EINVAL;
1465 buf = stream->buf;
1466 consumer_chan = stream->chan;
1467 return lib_ring_buffer_get_next_subbuf(buf,
1468 consumer_chan->chan->handle);
1469 }
1470
1471
1472 /* Release exclusive sub-buffer access, move consumer forward. */
1473 int ustctl_put_next_subbuf(struct ustctl_consumer_stream *stream)
1474 {
1475 struct lttng_ust_lib_ring_buffer *buf;
1476 struct ustctl_consumer_channel *consumer_chan;
1477
1478 if (!stream)
1479 return -EINVAL;
1480 buf = stream->buf;
1481 consumer_chan = stream->chan;
1482 lib_ring_buffer_put_next_subbuf(buf, consumer_chan->chan->handle);
1483 return 0;
1484 }
1485
1486 /* snapshot */
1487
1488 /* Get a snapshot of the current ring buffer producer and consumer positions */
1489 int ustctl_snapshot(struct ustctl_consumer_stream *stream)
1490 {
1491 struct lttng_ust_lib_ring_buffer *buf;
1492 struct ustctl_consumer_channel *consumer_chan;
1493
1494 if (!stream)
1495 return -EINVAL;
1496 buf = stream->buf;
1497 consumer_chan = stream->chan;
1498 return lib_ring_buffer_snapshot(buf, &buf->cons_snapshot,
1499 &buf->prod_snapshot, consumer_chan->chan->handle);
1500 }
1501
1502 /* Get the consumer position (iteration start) */
1503 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream *stream,
1504 unsigned long *pos)
1505 {
1506 struct lttng_ust_lib_ring_buffer *buf;
1507
1508 if (!stream)
1509 return -EINVAL;
1510 buf = stream->buf;
1511 *pos = buf->cons_snapshot;
1512 return 0;
1513 }
1514
1515 /* Get the producer position (iteration end) */
1516 int ustctl_snapshot_get_produced(struct ustctl_consumer_stream *stream,
1517 unsigned long *pos)
1518 {
1519 struct lttng_ust_lib_ring_buffer *buf;
1520
1521 if (!stream)
1522 return -EINVAL;
1523 buf = stream->buf;
1524 *pos = buf->prod_snapshot;
1525 return 0;
1526 }
1527
1528 /* Get exclusive read access to the specified sub-buffer position */
1529 int ustctl_get_subbuf(struct ustctl_consumer_stream *stream,
1530 unsigned long *pos)
1531 {
1532 struct lttng_ust_lib_ring_buffer *buf;
1533 struct ustctl_consumer_channel *consumer_chan;
1534
1535 if (!stream)
1536 return -EINVAL;
1537 buf = stream->buf;
1538 consumer_chan = stream->chan;
1539 return lib_ring_buffer_get_subbuf(buf, *pos,
1540 consumer_chan->chan->handle);
1541 }
1542
1543 /* Release exclusive sub-buffer access */
1544 int ustctl_put_subbuf(struct ustctl_consumer_stream *stream)
1545 {
1546 struct lttng_ust_lib_ring_buffer *buf;
1547 struct ustctl_consumer_channel *consumer_chan;
1548
1549 if (!stream)
1550 return -EINVAL;
1551 buf = stream->buf;
1552 consumer_chan = stream->chan;
1553 lib_ring_buffer_put_subbuf(buf, consumer_chan->chan->handle);
1554 return 0;
1555 }
1556
1557 void ustctl_flush_buffer(struct ustctl_consumer_stream *stream,
1558 int producer_active)
1559 {
1560 struct lttng_ust_lib_ring_buffer *buf;
1561 struct ustctl_consumer_channel *consumer_chan;
1562
1563 assert(stream);
1564 buf = stream->buf;
1565 consumer_chan = stream->chan;
1566 lib_ring_buffer_switch_slow(buf,
1567 producer_active ? SWITCH_ACTIVE : SWITCH_FLUSH,
1568 consumer_chan->chan->handle);
1569 }
1570
1571 static
1572 struct lttng_ust_client_lib_ring_buffer_client_cb *get_client_cb(
1573 struct lttng_ust_lib_ring_buffer *buf,
1574 struct lttng_ust_shm_handle *handle)
1575 {
1576 struct channel *chan;
1577 const struct lttng_ust_lib_ring_buffer_config *config;
1578 struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
1579
1580 chan = shmp(handle, buf->backend.chan);
1581 if (!chan)
1582 return NULL;
1583 config = &chan->backend.config;
1584 if (!config->cb_ptr)
1585 return NULL;
1586 client_cb = caa_container_of(config->cb_ptr,
1587 struct lttng_ust_client_lib_ring_buffer_client_cb,
1588 parent);
1589 return client_cb;
1590 }
1591
1592 int ustctl_get_timestamp_begin(struct ustctl_consumer_stream *stream,
1593 uint64_t *timestamp_begin)
1594 {
1595 struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
1596 struct lttng_ust_lib_ring_buffer *buf;
1597 struct lttng_ust_shm_handle *handle;
1598
1599 if (!stream || !timestamp_begin)
1600 return -EINVAL;
1601 buf = stream->buf;
1602 handle = stream->chan->chan->handle;
1603 client_cb = get_client_cb(buf, handle);
1604 if (!client_cb)
1605 return -ENOSYS;
1606 return client_cb->timestamp_begin(buf, handle, timestamp_begin);
1607 }
1608
1609 int ustctl_get_timestamp_end(struct ustctl_consumer_stream *stream,
1610 uint64_t *timestamp_end)
1611 {
1612 struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
1613 struct lttng_ust_lib_ring_buffer *buf;
1614 struct lttng_ust_shm_handle *handle;
1615
1616 if (!stream || !timestamp_end)
1617 return -EINVAL;
1618 buf = stream->buf;
1619 handle = stream->chan->chan->handle;
1620 client_cb = get_client_cb(buf, handle);
1621 if (!client_cb)
1622 return -ENOSYS;
1623 return client_cb->timestamp_end(buf, handle, timestamp_end);
1624 }
1625
1626 int ustctl_get_events_discarded(struct ustctl_consumer_stream *stream,
1627 uint64_t *events_discarded)
1628 {
1629 struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
1630 struct lttng_ust_lib_ring_buffer *buf;
1631 struct lttng_ust_shm_handle *handle;
1632
1633 if (!stream || !events_discarded)
1634 return -EINVAL;
1635 buf = stream->buf;
1636 handle = stream->chan->chan->handle;
1637 client_cb = get_client_cb(buf, handle);
1638 if (!client_cb)
1639 return -ENOSYS;
1640 return client_cb->events_discarded(buf, handle, events_discarded);
1641 }
1642
1643 int ustctl_get_content_size(struct ustctl_consumer_stream *stream,
1644 uint64_t *content_size)
1645 {
1646 struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
1647 struct lttng_ust_lib_ring_buffer *buf;
1648 struct lttng_ust_shm_handle *handle;
1649
1650 if (!stream || !content_size)
1651 return -EINVAL;
1652 buf = stream->buf;
1653 handle = stream->chan->chan->handle;
1654 client_cb = get_client_cb(buf, handle);
1655 if (!client_cb)
1656 return -ENOSYS;
1657 return client_cb->content_size(buf, handle, content_size);
1658 }
1659
1660 int ustctl_get_packet_size(struct ustctl_consumer_stream *stream,
1661 uint64_t *packet_size)
1662 {
1663 struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
1664 struct lttng_ust_lib_ring_buffer *buf;
1665 struct lttng_ust_shm_handle *handle;
1666
1667 if (!stream || !packet_size)
1668 return -EINVAL;
1669 buf = stream->buf;
1670 handle = stream->chan->chan->handle;
1671 client_cb = get_client_cb(buf, handle);
1672 if (!client_cb)
1673 return -ENOSYS;
1674 return client_cb->packet_size(buf, handle, packet_size);
1675 }
1676
1677 int ustctl_get_stream_id(struct ustctl_consumer_stream *stream,
1678 uint64_t *stream_id)
1679 {
1680 struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
1681 struct lttng_ust_lib_ring_buffer *buf;
1682 struct lttng_ust_shm_handle *handle;
1683
1684 if (!stream || !stream_id)
1685 return -EINVAL;
1686 buf = stream->buf;
1687 handle = stream->chan->chan->handle;
1688 client_cb = get_client_cb(buf, handle);
1689 if (!client_cb)
1690 return -ENOSYS;
1691 return client_cb->stream_id(buf, handle, stream_id);
1692 }
1693
1694 int ustctl_get_current_timestamp(struct ustctl_consumer_stream *stream,
1695 uint64_t *ts)
1696 {
1697 struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
1698 struct lttng_ust_lib_ring_buffer *buf;
1699 struct lttng_ust_shm_handle *handle;
1700
1701 if (!stream || !ts)
1702 return -EINVAL;
1703 buf = stream->buf;
1704 handle = stream->chan->chan->handle;
1705 client_cb = get_client_cb(buf, handle);
1706 if (!client_cb || !client_cb->current_timestamp)
1707 return -ENOSYS;
1708 return client_cb->current_timestamp(buf, handle, ts);
1709 }
1710
1711 #if defined(__x86_64__) || defined(__i386__)
1712
1713 int ustctl_has_perf_counters(void)
1714 {
1715 return 1;
1716 }
1717
1718 #else
1719
1720 int ustctl_has_perf_counters(void)
1721 {
1722 return 0;
1723 }
1724
1725 #endif
1726
1727 /*
1728 * Returns 0 on success, negative error value on error.
1729 */
1730 int ustctl_recv_reg_msg(int sock,
1731 enum ustctl_socket_type *type,
1732 uint32_t *major,
1733 uint32_t *minor,
1734 uint32_t *pid,
1735 uint32_t *ppid,
1736 uint32_t *uid,
1737 uint32_t *gid,
1738 uint32_t *bits_per_long,
1739 uint32_t *uint8_t_alignment,
1740 uint32_t *uint16_t_alignment,
1741 uint32_t *uint32_t_alignment,
1742 uint32_t *uint64_t_alignment,
1743 uint32_t *long_alignment,
1744 int *byte_order,
1745 char *name)
1746 {
1747 ssize_t len;
1748 struct ustctl_reg_msg reg_msg;
1749
1750 len = ustcomm_recv_unix_sock(sock, &reg_msg, sizeof(reg_msg));
1751 if (len > 0 && len != sizeof(reg_msg))
1752 return -EIO;
1753 if (len == 0)
1754 return -EPIPE;
1755 if (len < 0)
1756 return len;
1757
1758 if (reg_msg.magic == LTTNG_UST_COMM_MAGIC) {
1759 *byte_order = BYTE_ORDER == BIG_ENDIAN ?
1760 BIG_ENDIAN : LITTLE_ENDIAN;
1761 } else if (reg_msg.magic == bswap_32(LTTNG_UST_COMM_MAGIC)) {
1762 *byte_order = BYTE_ORDER == BIG_ENDIAN ?
1763 LITTLE_ENDIAN : BIG_ENDIAN;
1764 } else {
1765 return -LTTNG_UST_ERR_INVAL_MAGIC;
1766 }
1767 switch (reg_msg.socket_type) {
1768 case 0: *type = USTCTL_SOCKET_CMD;
1769 break;
1770 case 1: *type = USTCTL_SOCKET_NOTIFY;
1771 break;
1772 default:
1773 return -LTTNG_UST_ERR_INVAL_SOCKET_TYPE;
1774 }
1775 *major = reg_msg.major;
1776 *minor = reg_msg.minor;
1777 *pid = reg_msg.pid;
1778 *ppid = reg_msg.ppid;
1779 *uid = reg_msg.uid;
1780 *gid = reg_msg.gid;
1781 *bits_per_long = reg_msg.bits_per_long;
1782 *uint8_t_alignment = reg_msg.uint8_t_alignment;
1783 *uint16_t_alignment = reg_msg.uint16_t_alignment;
1784 *uint32_t_alignment = reg_msg.uint32_t_alignment;
1785 *uint64_t_alignment = reg_msg.uint64_t_alignment;
1786 *long_alignment = reg_msg.long_alignment;
1787 memcpy(name, reg_msg.name, LTTNG_UST_ABI_PROCNAME_LEN);
1788 if (reg_msg.major != LTTNG_UST_ABI_MAJOR_VERSION) {
1789 return -LTTNG_UST_ERR_UNSUP_MAJOR;
1790 }
1791
1792 return 0;
1793 }
1794
1795 int ustctl_recv_notify(int sock, enum ustctl_notify_cmd *notify_cmd)
1796 {
1797 struct ustcomm_notify_hdr header;
1798 ssize_t len;
1799
1800 len = ustcomm_recv_unix_sock(sock, &header, sizeof(header));
1801 if (len > 0 && len != sizeof(header))
1802 return -EIO;
1803 if (len == 0)
1804 return -EPIPE;
1805 if (len < 0)
1806 return len;
1807 switch (header.notify_cmd) {
1808 case 0:
1809 *notify_cmd = USTCTL_NOTIFY_CMD_EVENT;
1810 break;
1811 case 1:
1812 *notify_cmd = USTCTL_NOTIFY_CMD_CHANNEL;
1813 break;
1814 case 2:
1815 *notify_cmd = USTCTL_NOTIFY_CMD_ENUM;
1816 break;
1817 default:
1818 return -EINVAL;
1819 }
1820 return 0;
1821 }
1822
1823 /*
1824 * Returns 0 on success, negative error value on error.
1825 */
1826 int ustctl_recv_register_event(int sock,
1827 int *session_objd,
1828 int *channel_objd,
1829 char *event_name,
1830 int *loglevel,
1831 char **signature,
1832 size_t *nr_fields,
1833 struct ustctl_field **fields,
1834 char **model_emf_uri)
1835 {
1836 ssize_t len;
1837 struct ustcomm_notify_event_msg msg;
1838 size_t signature_len, fields_len, model_emf_uri_len;
1839 char *a_sign = NULL, *a_model_emf_uri = NULL;
1840 struct ustctl_field *a_fields = NULL;
1841
1842 len = ustcomm_recv_unix_sock(sock, &msg, sizeof(msg));
1843 if (len > 0 && len != sizeof(msg))
1844 return -EIO;
1845 if (len == 0)
1846 return -EPIPE;
1847 if (len < 0)
1848 return len;
1849
1850 *session_objd = msg.session_objd;
1851 *channel_objd = msg.channel_objd;
1852 strncpy(event_name, msg.event_name, LTTNG_UST_SYM_NAME_LEN);
1853 event_name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
1854 *loglevel = msg.loglevel;
1855 signature_len = msg.signature_len;
1856 fields_len = msg.fields_len;
1857
1858 if (fields_len % sizeof(*a_fields) != 0) {
1859 return -EINVAL;
1860 }
1861
1862 model_emf_uri_len = msg.model_emf_uri_len;
1863
1864 /* recv signature. contains at least \0. */
1865 a_sign = zmalloc(signature_len);
1866 if (!a_sign)
1867 return -ENOMEM;
1868 len = ustcomm_recv_unix_sock(sock, a_sign, signature_len);
1869 if (len > 0 && len != signature_len) {
1870 len = -EIO;
1871 goto signature_error;
1872 }
1873 if (len == 0) {
1874 len = -EPIPE;
1875 goto signature_error;
1876 }
1877 if (len < 0) {
1878 goto signature_error;
1879 }
1880 /* Enforce end of string */
1881 a_sign[signature_len - 1] = '\0';
1882
1883 /* recv fields */
1884 if (fields_len) {
1885 a_fields = zmalloc(fields_len);
1886 if (!a_fields) {
1887 len = -ENOMEM;
1888 goto signature_error;
1889 }
1890 len = ustcomm_recv_unix_sock(sock, a_fields, fields_len);
1891 if (len > 0 && len != fields_len) {
1892 len = -EIO;
1893 goto fields_error;
1894 }
1895 if (len == 0) {
1896 len = -EPIPE;
1897 goto fields_error;
1898 }
1899 if (len < 0) {
1900 goto fields_error;
1901 }
1902 }
1903
1904 if (model_emf_uri_len) {
1905 /* recv model_emf_uri_len */
1906 a_model_emf_uri = zmalloc(model_emf_uri_len);
1907 if (!a_model_emf_uri) {
1908 len = -ENOMEM;
1909 goto fields_error;
1910 }
1911 len = ustcomm_recv_unix_sock(sock, a_model_emf_uri,
1912 model_emf_uri_len);
1913 if (len > 0 && len != model_emf_uri_len) {
1914 len = -EIO;
1915 goto model_error;
1916 }
1917 if (len == 0) {
1918 len = -EPIPE;
1919 goto model_error;
1920 }
1921 if (len < 0) {
1922 goto model_error;
1923 }
1924 /* Enforce end of string */
1925 a_model_emf_uri[model_emf_uri_len - 1] = '\0';
1926 }
1927
1928 *signature = a_sign;
1929 *nr_fields = fields_len / sizeof(*a_fields);
1930 *fields = a_fields;
1931 *model_emf_uri = a_model_emf_uri;
1932
1933 return 0;
1934
1935 model_error:
1936 free(a_model_emf_uri);
1937 fields_error:
1938 free(a_fields);
1939 signature_error:
1940 free(a_sign);
1941 return len;
1942 }
1943
1944 /*
1945 * Returns 0 on success, negative error value on error.
1946 */
1947 int ustctl_reply_register_event(int sock,
1948 uint32_t id,
1949 int ret_code)
1950 {
1951 ssize_t len;
1952 struct {
1953 struct ustcomm_notify_hdr header;
1954 struct ustcomm_notify_event_reply r;
1955 } reply;
1956
1957 memset(&reply, 0, sizeof(reply));
1958 reply.header.notify_cmd = USTCTL_NOTIFY_CMD_EVENT;
1959 reply.r.ret_code = ret_code;
1960 reply.r.event_id = id;
1961 len = ustcomm_send_unix_sock(sock, &reply, sizeof(reply));
1962 if (len > 0 && len != sizeof(reply))
1963 return -EIO;
1964 if (len < 0)
1965 return len;
1966 return 0;
1967 }
1968
1969 /*
1970 * Returns 0 on success, negative UST or system error value on error.
1971 */
1972 int ustctl_recv_register_enum(int sock,
1973 int *session_objd,
1974 char *enum_name,
1975 struct ustctl_enum_entry **entries,
1976 size_t *nr_entries)
1977 {
1978 ssize_t len;
1979 struct ustcomm_notify_enum_msg msg;
1980 size_t entries_len;
1981 struct ustctl_enum_entry *a_entries = NULL;
1982
1983 len = ustcomm_recv_unix_sock(sock, &msg, sizeof(msg));
1984 if (len > 0 && len != sizeof(msg))
1985 return -EIO;
1986 if (len == 0)
1987 return -EPIPE;
1988 if (len < 0)
1989 return len;
1990
1991 *session_objd = msg.session_objd;
1992 strncpy(enum_name, msg.enum_name, LTTNG_UST_SYM_NAME_LEN);
1993 enum_name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
1994 entries_len = msg.entries_len;
1995
1996 if (entries_len % sizeof(*a_entries) != 0) {
1997 return -EINVAL;
1998 }
1999
2000 /* recv entries */
2001 if (entries_len) {
2002 a_entries = zmalloc(entries_len);
2003 if (!a_entries)
2004 return -ENOMEM;
2005 len = ustcomm_recv_unix_sock(sock, a_entries, entries_len);
2006 if (len > 0 && len != entries_len) {
2007 len = -EIO;
2008 goto entries_error;
2009 }
2010 if (len == 0) {
2011 len = -EPIPE;
2012 goto entries_error;
2013 }
2014 if (len < 0) {
2015 goto entries_error;
2016 }
2017 }
2018 *nr_entries = entries_len / sizeof(*a_entries);
2019 *entries = a_entries;
2020
2021 return 0;
2022
2023 entries_error:
2024 free(a_entries);
2025 return len;
2026 }
2027
2028 /*
2029 * Returns 0 on success, negative error value on error.
2030 */
2031 int ustctl_reply_register_enum(int sock,
2032 uint64_t id,
2033 int ret_code)
2034 {
2035 ssize_t len;
2036 struct {
2037 struct ustcomm_notify_hdr header;
2038 struct ustcomm_notify_enum_reply r;
2039 } reply;
2040
2041 memset(&reply, 0, sizeof(reply));
2042 reply.header.notify_cmd = USTCTL_NOTIFY_CMD_ENUM;
2043 reply.r.ret_code = ret_code;
2044 reply.r.enum_id = id;
2045 len = ustcomm_send_unix_sock(sock, &reply, sizeof(reply));
2046 if (len > 0 && len != sizeof(reply))
2047 return -EIO;
2048 if (len < 0)
2049 return len;
2050 return 0;
2051 }
2052
2053 /*
2054 * Returns 0 on success, negative UST or system error value on error.
2055 */
2056 int ustctl_recv_register_channel(int sock,
2057 int *session_objd, /* session descriptor (output) */
2058 int *channel_objd, /* channel descriptor (output) */
2059 size_t *nr_fields,
2060 struct ustctl_field **fields)
2061 {
2062 ssize_t len;
2063 struct ustcomm_notify_channel_msg msg;
2064 size_t fields_len;
2065 struct ustctl_field *a_fields;
2066
2067 len = ustcomm_recv_unix_sock(sock, &msg, sizeof(msg));
2068 if (len > 0 && len != sizeof(msg))
2069 return -EIO;
2070 if (len == 0)
2071 return -EPIPE;
2072 if (len < 0)
2073 return len;
2074
2075 *session_objd = msg.session_objd;
2076 *channel_objd = msg.channel_objd;
2077 fields_len = msg.ctx_fields_len;
2078
2079 if (fields_len % sizeof(*a_fields) != 0) {
2080 return -EINVAL;
2081 }
2082
2083 /* recv fields */
2084 if (fields_len) {
2085 a_fields = zmalloc(fields_len);
2086 if (!a_fields) {
2087 len = -ENOMEM;
2088 goto alloc_error;
2089 }
2090 len = ustcomm_recv_unix_sock(sock, a_fields, fields_len);
2091 if (len > 0 && len != fields_len) {
2092 len = -EIO;
2093 goto fields_error;
2094 }
2095 if (len == 0) {
2096 len = -EPIPE;
2097 goto fields_error;
2098 }
2099 if (len < 0) {
2100 goto fields_error;
2101 }
2102 *fields = a_fields;
2103 } else {
2104 *fields = NULL;
2105 }
2106 *nr_fields = fields_len / sizeof(*a_fields);
2107 return 0;
2108
2109 fields_error:
2110 free(a_fields);
2111 alloc_error:
2112 return len;
2113 }
2114
2115 /*
2116 * Returns 0 on success, negative error value on error.
2117 */
2118 int ustctl_reply_register_channel(int sock,
2119 uint32_t chan_id,
2120 enum ustctl_channel_header header_type,
2121 int ret_code)
2122 {
2123 ssize_t len;
2124 struct {
2125 struct ustcomm_notify_hdr header;
2126 struct ustcomm_notify_channel_reply r;
2127 } reply;
2128
2129 memset(&reply, 0, sizeof(reply));
2130 reply.header.notify_cmd = USTCTL_NOTIFY_CMD_CHANNEL;
2131 reply.r.ret_code = ret_code;
2132 reply.r.chan_id = chan_id;
2133 switch (header_type) {
2134 case USTCTL_CHANNEL_HEADER_COMPACT:
2135 reply.r.header_type = 1;
2136 break;
2137 case USTCTL_CHANNEL_HEADER_LARGE:
2138 reply.r.header_type = 2;
2139 break;
2140 default:
2141 reply.r.header_type = 0;
2142 break;
2143 }
2144 len = ustcomm_send_unix_sock(sock, &reply, sizeof(reply));
2145 if (len > 0 && len != sizeof(reply))
2146 return -EIO;
2147 if (len < 0)
2148 return len;
2149 return 0;
2150 }
2151
2152 static __attribute__((constructor))
2153 void ustctl_init(void)
2154 {
2155 init_usterr();
2156 lttng_ust_clock_init();
2157 lttng_ring_buffer_metadata_client_init();
2158 lttng_ring_buffer_client_overwrite_init();
2159 lttng_ring_buffer_client_overwrite_rt_init();
2160 lttng_ring_buffer_client_discard_init();
2161 lttng_ring_buffer_client_discard_rt_init();
2162 lib_ringbuffer_signal_init();
2163 }
2164
2165 static __attribute__((destructor))
2166 void ustctl_exit(void)
2167 {
2168 lttng_ring_buffer_client_discard_rt_exit();
2169 lttng_ring_buffer_client_discard_exit();
2170 lttng_ring_buffer_client_overwrite_rt_exit();
2171 lttng_ring_buffer_client_overwrite_exit();
2172 lttng_ring_buffer_metadata_client_exit();
2173 }
This page took 0.070361 seconds and 3 git commands to generate.