2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Copyright (C) 2011-2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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.
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.
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.
21 #include <lttng/ust-ctl.h>
22 #include <lttng/ust-abi.h>
23 #include <lttng/ust-events.h>
27 #include <usterr-signal-safe.h>
31 #include "../libringbuffer/backend.h"
32 #include "../libringbuffer/frontend.h"
33 #include "../liblttng-ust/wait.h"
34 #include "../liblttng-ust/lttng-rb-clients.h"
37 * Number of milliseconds to retry before failing metadata writes on
38 * buffer full condition. (10 seconds)
40 #define LTTNG_METADATA_TIMEOUT_MSEC 10000
43 * Channel representation within consumer.
45 struct ustctl_consumer_channel
{
46 struct lttng_channel
*chan
; /* lttng channel buffers */
48 /* initial attributes */
49 struct ustctl_consumer_channel_attr attr
;
50 int wait_fd
; /* monitor close() */
51 int wakeup_fd
; /* monitor close() */
55 * Stream representation within consumer.
57 struct ustctl_consumer_stream
{
58 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
59 struct lttng_ust_lib_ring_buffer
*buf
;
60 struct ustctl_consumer_channel
*chan
;
61 int shm_fd
, wait_fd
, wakeup_fd
;
63 uint64_t memory_map_size
;
66 extern void lttng_ring_buffer_client_overwrite_init(void);
67 extern void lttng_ring_buffer_client_overwrite_rt_init(void);
68 extern void lttng_ring_buffer_client_discard_init(void);
69 extern void lttng_ring_buffer_client_discard_rt_init(void);
70 extern void lttng_ring_buffer_metadata_client_init(void);
71 extern void lttng_ring_buffer_client_overwrite_exit(void);
72 extern void lttng_ring_buffer_client_overwrite_rt_exit(void);
73 extern void lttng_ring_buffer_client_discard_exit(void);
74 extern void lttng_ring_buffer_client_discard_rt_exit(void);
75 extern void lttng_ring_buffer_metadata_client_exit(void);
77 volatile enum ust_loglevel ust_loglevel
;
79 int ustctl_release_handle(int sock
, int handle
)
81 struct ustcomm_ust_msg lum
;
82 struct ustcomm_ust_reply lur
;
84 if (sock
< 0 || handle
< 0)
86 memset(&lum
, 0, sizeof(lum
));
88 lum
.cmd
= LTTNG_UST_RELEASE
;
89 return ustcomm_send_app_cmd(sock
, &lum
, &lur
);
93 * If sock is negative, it means we don't have to notify the other side
94 * (e.g. application has already vanished).
96 int ustctl_release_object(int sock
, struct lttng_ust_object_data
*data
)
103 switch (data
->type
) {
104 case LTTNG_UST_OBJECT_TYPE_CHANNEL
:
105 if (data
->u
.channel
.wakeup_fd
>= 0) {
106 ret
= close(data
->u
.channel
.wakeup_fd
);
112 free(data
->u
.channel
.data
);
114 case LTTNG_UST_OBJECT_TYPE_STREAM
:
115 if (data
->u
.stream
.shm_fd
>= 0) {
116 ret
= close(data
->u
.stream
.shm_fd
);
122 if (data
->u
.stream
.wakeup_fd
>= 0) {
123 ret
= close(data
->u
.stream
.wakeup_fd
);
130 case LTTNG_UST_OBJECT_TYPE_EVENT
:
131 case LTTNG_UST_OBJECT_TYPE_CONTEXT
:
136 return ustctl_release_handle(sock
, data
->handle
);
140 * Send registration done packet to the application.
142 int ustctl_register_done(int sock
)
144 struct ustcomm_ust_msg lum
;
145 struct ustcomm_ust_reply lur
;
148 DBG("Sending register done command to %d", sock
);
149 memset(&lum
, 0, sizeof(lum
));
150 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
151 lum
.cmd
= LTTNG_UST_REGISTER_DONE
;
152 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
159 * returns session handle.
161 int ustctl_create_session(int sock
)
163 struct ustcomm_ust_msg lum
;
164 struct ustcomm_ust_reply lur
;
165 int ret
, session_handle
;
168 memset(&lum
, 0, sizeof(lum
));
169 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
170 lum
.cmd
= LTTNG_UST_SESSION
;
171 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
174 session_handle
= lur
.ret_val
;
175 DBG("received session handle %u", session_handle
);
176 return session_handle
;
179 int ustctl_create_event(int sock
, struct lttng_ust_event
*ev
,
180 struct lttng_ust_object_data
*channel_data
,
181 struct lttng_ust_object_data
**_event_data
)
183 struct ustcomm_ust_msg lum
;
184 struct ustcomm_ust_reply lur
;
185 struct lttng_ust_object_data
*event_data
;
188 if (!channel_data
|| !_event_data
)
191 event_data
= zmalloc(sizeof(*event_data
));
194 event_data
->type
= LTTNG_UST_OBJECT_TYPE_EVENT
;
195 memset(&lum
, 0, sizeof(lum
));
196 lum
.handle
= channel_data
->handle
;
197 lum
.cmd
= LTTNG_UST_EVENT
;
198 strncpy(lum
.u
.event
.name
, ev
->name
,
199 LTTNG_UST_SYM_NAME_LEN
);
200 lum
.u
.event
.instrumentation
= ev
->instrumentation
;
201 lum
.u
.event
.loglevel_type
= ev
->loglevel_type
;
202 lum
.u
.event
.loglevel
= ev
->loglevel
;
203 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
208 event_data
->handle
= lur
.ret_val
;
209 DBG("received event handle %u", event_data
->handle
);
210 *_event_data
= event_data
;
214 int ustctl_add_context(int sock
, struct lttng_ust_context
*ctx
,
215 struct lttng_ust_object_data
*obj_data
,
216 struct lttng_ust_object_data
**_context_data
)
218 struct ustcomm_ust_msg lum
;
219 struct ustcomm_ust_reply lur
;
220 struct lttng_ust_object_data
*context_data
;
223 if (!obj_data
|| !_context_data
)
226 context_data
= zmalloc(sizeof(*context_data
));
229 context_data
->type
= LTTNG_UST_OBJECT_TYPE_CONTEXT
;
230 memset(&lum
, 0, sizeof(lum
));
231 lum
.handle
= obj_data
->handle
;
232 lum
.cmd
= LTTNG_UST_CONTEXT
;
233 lum
.u
.context
.ctx
= ctx
->ctx
;
234 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
239 context_data
->handle
= -1;
240 DBG("Context created successfully");
241 *_context_data
= context_data
;
245 int ustctl_set_filter(int sock
, struct lttng_ust_filter_bytecode
*bytecode
,
246 struct lttng_ust_object_data
*obj_data
)
248 struct ustcomm_ust_msg lum
;
249 struct ustcomm_ust_reply lur
;
255 memset(&lum
, 0, sizeof(lum
));
256 lum
.handle
= obj_data
->handle
;
257 lum
.cmd
= LTTNG_UST_FILTER
;
258 lum
.u
.filter
.data_size
= bytecode
->len
;
259 lum
.u
.filter
.reloc_offset
= bytecode
->reloc_offset
;
260 lum
.u
.filter
.seqnum
= bytecode
->seqnum
;
262 ret
= ustcomm_send_app_msg(sock
, &lum
);
265 /* send var len bytecode */
266 ret
= ustcomm_send_unix_sock(sock
, bytecode
->data
,
271 if (ret
!= bytecode
->len
)
273 return ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
276 int ustctl_set_exclusion(int sock
, struct lttng_ust_event_exclusion
*exclusion
,
277 struct lttng_ust_object_data
*obj_data
)
279 struct ustcomm_ust_msg lum
;
280 struct ustcomm_ust_reply lur
;
287 memset(&lum
, 0, sizeof(lum
));
288 lum
.handle
= obj_data
->handle
;
289 lum
.cmd
= LTTNG_UST_EXCLUSION
;
290 lum
.u
.exclusion
.count
= exclusion
->count
;
292 ret
= ustcomm_send_app_msg(sock
, &lum
);
297 /* send var len bytecode */
298 ret
= ustcomm_send_unix_sock(sock
,
300 exclusion
->count
* LTTNG_UST_SYM_NAME_LEN
);
304 if (ret
!= exclusion
->count
* LTTNG_UST_SYM_NAME_LEN
) {
307 return ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
310 /* Enable event, channel and session ioctl */
311 int ustctl_enable(int sock
, struct lttng_ust_object_data
*object
)
313 struct ustcomm_ust_msg lum
;
314 struct ustcomm_ust_reply lur
;
320 memset(&lum
, 0, sizeof(lum
));
321 lum
.handle
= object
->handle
;
322 lum
.cmd
= LTTNG_UST_ENABLE
;
323 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
326 DBG("enabled handle %u", object
->handle
);
330 /* Disable event, channel and session ioctl */
331 int ustctl_disable(int sock
, struct lttng_ust_object_data
*object
)
333 struct ustcomm_ust_msg lum
;
334 struct ustcomm_ust_reply lur
;
340 memset(&lum
, 0, sizeof(lum
));
341 lum
.handle
= object
->handle
;
342 lum
.cmd
= LTTNG_UST_DISABLE
;
343 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
346 DBG("disable handle %u", object
->handle
);
350 int ustctl_start_session(int sock
, int handle
)
352 struct lttng_ust_object_data obj
;
355 return ustctl_enable(sock
, &obj
);
358 int ustctl_stop_session(int sock
, int handle
)
360 struct lttng_ust_object_data obj
;
363 return ustctl_disable(sock
, &obj
);
366 int ustctl_tracepoint_list(int sock
)
368 struct ustcomm_ust_msg lum
;
369 struct ustcomm_ust_reply lur
;
370 int ret
, tp_list_handle
;
372 memset(&lum
, 0, sizeof(lum
));
373 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
374 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST
;
375 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
378 tp_list_handle
= lur
.ret_val
;
379 DBG("received tracepoint list handle %u", tp_list_handle
);
380 return tp_list_handle
;
383 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
384 struct lttng_ust_tracepoint_iter
*iter
)
386 struct ustcomm_ust_msg lum
;
387 struct ustcomm_ust_reply lur
;
393 memset(&lum
, 0, sizeof(lum
));
394 lum
.handle
= tp_list_handle
;
395 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST_GET
;
396 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
399 DBG("received tracepoint list entry name %s loglevel %d",
400 lur
.u
.tracepoint
.name
,
401 lur
.u
.tracepoint
.loglevel
);
402 memcpy(iter
, &lur
.u
.tracepoint
, sizeof(*iter
));
406 int ustctl_tracepoint_field_list(int sock
)
408 struct ustcomm_ust_msg lum
;
409 struct ustcomm_ust_reply lur
;
410 int ret
, tp_field_list_handle
;
412 memset(&lum
, 0, sizeof(lum
));
413 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
414 lum
.cmd
= LTTNG_UST_TRACEPOINT_FIELD_LIST
;
415 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
418 tp_field_list_handle
= lur
.ret_val
;
419 DBG("received tracepoint field list handle %u", tp_field_list_handle
);
420 return tp_field_list_handle
;
423 int ustctl_tracepoint_field_list_get(int sock
, int tp_field_list_handle
,
424 struct lttng_ust_field_iter
*iter
)
426 struct ustcomm_ust_msg lum
;
427 struct ustcomm_ust_reply lur
;
434 memset(&lum
, 0, sizeof(lum
));
435 lum
.handle
= tp_field_list_handle
;
436 lum
.cmd
= LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
;
437 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
440 len
= ustcomm_recv_unix_sock(sock
, iter
, sizeof(*iter
));
441 if (len
!= sizeof(*iter
)) {
444 DBG("received tracepoint field list entry event_name %s event_loglevel %d field_name %s field_type %d",
452 int ustctl_tracer_version(int sock
, struct lttng_ust_tracer_version
*v
)
454 struct ustcomm_ust_msg lum
;
455 struct ustcomm_ust_reply lur
;
461 memset(&lum
, 0, sizeof(lum
));
462 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
463 lum
.cmd
= LTTNG_UST_TRACER_VERSION
;
464 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
467 memcpy(v
, &lur
.u
.version
, sizeof(*v
));
468 DBG("received tracer version");
472 int ustctl_wait_quiescent(int sock
)
474 struct ustcomm_ust_msg lum
;
475 struct ustcomm_ust_reply lur
;
478 memset(&lum
, 0, sizeof(lum
));
479 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
480 lum
.cmd
= LTTNG_UST_WAIT_QUIESCENT
;
481 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
484 DBG("waited for quiescent state");
488 int ustctl_calibrate(int sock
, struct lttng_ust_calibrate
*calibrate
)
496 int ustctl_sock_flush_buffer(int sock
, struct lttng_ust_object_data
*object
)
498 struct ustcomm_ust_msg lum
;
499 struct ustcomm_ust_reply lur
;
505 memset(&lum
, 0, sizeof(lum
));
506 lum
.handle
= object
->handle
;
507 lum
.cmd
= LTTNG_UST_FLUSH_BUFFER
;
508 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
511 DBG("flushed buffer handle %u", object
->handle
);
516 int ustctl_send_channel(int sock
,
517 enum lttng_ust_chan_type type
,
527 len
= ustcomm_send_unix_sock(sock
, &size
, sizeof(size
));
528 if (len
!= sizeof(size
)) {
535 /* Send channel type */
536 len
= ustcomm_send_unix_sock(sock
, &type
, sizeof(type
));
537 if (len
!= sizeof(type
)) {
545 /* Send channel data */
546 len
= ustcomm_send_unix_sock(sock
, data
, size
);
555 len
= ustcomm_send_fds_unix_sock(sock
, &wakeup_fd
, 1);
566 int ustctl_send_stream(int sock
,
568 uint64_t memory_map_size
,
569 int shm_fd
, int wakeup_fd
,
577 /* finish iteration */
580 len
= ustcomm_send_unix_sock(sock
, &v
, sizeof(v
));
581 if (len
!= sizeof(v
)) {
591 len
= ustcomm_send_unix_sock(sock
, &memory_map_size
,
592 sizeof(memory_map_size
));
593 if (len
!= sizeof(memory_map_size
)) {
601 len
= ustcomm_send_unix_sock(sock
, &stream_nr
,
603 if (len
!= sizeof(stream_nr
)) {
611 /* Send shm fd and wakeup fd */
614 len
= ustcomm_send_fds_unix_sock(sock
, fds
, 2);
624 int ustctl_recv_channel_from_consumer(int sock
,
625 struct lttng_ust_object_data
**_channel_data
)
627 struct lttng_ust_object_data
*channel_data
;
632 channel_data
= zmalloc(sizeof(*channel_data
));
637 channel_data
->type
= LTTNG_UST_OBJECT_TYPE_CHANNEL
;
638 channel_data
->handle
= -1;
641 len
= ustcomm_recv_unix_sock(sock
, &channel_data
->size
,
642 sizeof(channel_data
->size
));
643 if (len
!= sizeof(channel_data
->size
)) {
651 /* recv channel type */
652 len
= ustcomm_recv_unix_sock(sock
, &channel_data
->u
.channel
.type
,
653 sizeof(channel_data
->u
.channel
.type
));
654 if (len
!= sizeof(channel_data
->u
.channel
.type
)) {
662 /* recv channel data */
663 channel_data
->u
.channel
.data
= zmalloc(channel_data
->size
);
664 if (!channel_data
->u
.channel
.data
) {
668 len
= ustcomm_recv_unix_sock(sock
, channel_data
->u
.channel
.data
,
670 if (len
!= channel_data
->size
) {
675 goto error_recv_data
;
678 len
= ustcomm_recv_fds_unix_sock(sock
, &wakeup_fd
, 1);
682 goto error_recv_data
;
685 goto error_recv_data
;
688 channel_data
->u
.channel
.wakeup_fd
= wakeup_fd
;
689 *_channel_data
= channel_data
;
693 free(channel_data
->u
.channel
.data
);
700 int ustctl_recv_stream_from_consumer(int sock
,
701 struct lttng_ust_object_data
**_stream_data
)
703 struct lttng_ust_object_data
*stream_data
;
708 stream_data
= zmalloc(sizeof(*stream_data
));
714 stream_data
->type
= LTTNG_UST_OBJECT_TYPE_STREAM
;
715 stream_data
->handle
= -1;
718 len
= ustcomm_recv_unix_sock(sock
, &stream_data
->size
,
719 sizeof(stream_data
->size
));
720 if (len
!= sizeof(stream_data
->size
)) {
727 if (stream_data
->size
== -1) {
728 ret
= -LTTNG_UST_ERR_NOENT
;
733 len
= ustcomm_recv_unix_sock(sock
, &stream_data
->u
.stream
.stream_nr
,
734 sizeof(stream_data
->u
.stream
.stream_nr
));
735 if (len
!= sizeof(stream_data
->u
.stream
.stream_nr
)) {
743 /* recv shm fd and wakeup fd */
744 len
= ustcomm_recv_fds_unix_sock(sock
, fds
, 2);
754 stream_data
->u
.stream
.shm_fd
= fds
[0];
755 stream_data
->u
.stream
.wakeup_fd
= fds
[1];
756 *_stream_data
= stream_data
;
765 int ustctl_send_channel_to_ust(int sock
, int session_handle
,
766 struct lttng_ust_object_data
*channel_data
)
768 struct ustcomm_ust_msg lum
;
769 struct ustcomm_ust_reply lur
;
775 memset(&lum
, 0, sizeof(lum
));
776 lum
.handle
= session_handle
;
777 lum
.cmd
= LTTNG_UST_CHANNEL
;
778 lum
.u
.channel
.len
= channel_data
->size
;
779 lum
.u
.channel
.type
= channel_data
->u
.channel
.type
;
780 ret
= ustcomm_send_app_msg(sock
, &lum
);
784 ret
= ustctl_send_channel(sock
,
785 channel_data
->u
.channel
.type
,
786 channel_data
->u
.channel
.data
,
788 channel_data
->u
.channel
.wakeup_fd
,
792 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
794 channel_data
->handle
= lur
.ret_val
;
799 int ustctl_send_stream_to_ust(int sock
,
800 struct lttng_ust_object_data
*channel_data
,
801 struct lttng_ust_object_data
*stream_data
)
803 struct ustcomm_ust_msg lum
;
804 struct ustcomm_ust_reply lur
;
807 memset(&lum
, 0, sizeof(lum
));
808 lum
.handle
= channel_data
->handle
;
809 lum
.cmd
= LTTNG_UST_STREAM
;
810 lum
.u
.stream
.len
= stream_data
->size
;
811 lum
.u
.stream
.stream_nr
= stream_data
->u
.stream
.stream_nr
;
812 ret
= ustcomm_send_app_msg(sock
, &lum
);
817 assert(stream_data
->type
== LTTNG_UST_OBJECT_TYPE_STREAM
);
819 ret
= ustctl_send_stream(sock
,
820 stream_data
->u
.stream
.stream_nr
,
822 stream_data
->u
.stream
.shm_fd
,
823 stream_data
->u
.stream
.wakeup_fd
, 1);
826 return ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
829 int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data
**dest
,
830 struct lttng_ust_object_data
*src
)
832 struct lttng_ust_object_data
*obj
;
835 if (src
->handle
!= -1) {
840 obj
= zmalloc(sizeof(*obj
));
846 obj
->type
= src
->type
;
847 obj
->handle
= src
->handle
;
848 obj
->size
= src
->size
;
851 case LTTNG_UST_OBJECT_TYPE_CHANNEL
:
853 obj
->u
.channel
.type
= src
->u
.channel
.type
;
854 if (src
->u
.channel
.wakeup_fd
>= 0) {
855 obj
->u
.channel
.wakeup_fd
=
856 dup(src
->u
.channel
.wakeup_fd
);
857 if (obj
->u
.channel
.wakeup_fd
< 0) {
859 goto chan_error_wakeup_fd
;
862 obj
->u
.channel
.wakeup_fd
=
863 src
->u
.channel
.wakeup_fd
;
865 obj
->u
.channel
.data
= zmalloc(obj
->size
);
866 if (!obj
->u
.channel
.data
) {
868 goto chan_error_alloc
;
870 memcpy(obj
->u
.channel
.data
, src
->u
.channel
.data
, obj
->size
);
874 if (src
->u
.channel
.wakeup_fd
>= 0) {
877 closeret
= close(obj
->u
.channel
.wakeup_fd
);
882 chan_error_wakeup_fd
:
887 case LTTNG_UST_OBJECT_TYPE_STREAM
:
889 obj
->u
.stream
.stream_nr
= src
->u
.stream
.stream_nr
;
890 if (src
->u
.stream
.wakeup_fd
>= 0) {
891 obj
->u
.stream
.wakeup_fd
=
892 dup(src
->u
.stream
.wakeup_fd
);
893 if (obj
->u
.stream
.wakeup_fd
< 0) {
895 goto stream_error_wakeup_fd
;
898 obj
->u
.stream
.wakeup_fd
=
899 src
->u
.stream
.wakeup_fd
;
902 if (src
->u
.stream
.shm_fd
>= 0) {
903 obj
->u
.stream
.shm_fd
=
904 dup(src
->u
.stream
.shm_fd
);
905 if (obj
->u
.stream
.shm_fd
< 0) {
907 goto stream_error_shm_fd
;
910 obj
->u
.stream
.shm_fd
=
911 src
->u
.stream
.shm_fd
;
916 if (src
->u
.stream
.wakeup_fd
>= 0) {
919 closeret
= close(obj
->u
.stream
.wakeup_fd
);
924 stream_error_wakeup_fd
:
943 /* Buffer operations */
945 struct ustctl_consumer_channel
*
946 ustctl_create_channel(struct ustctl_consumer_channel_attr
*attr
)
948 struct ustctl_consumer_channel
*chan
;
949 const char *transport_name
;
950 struct lttng_transport
*transport
;
952 switch (attr
->type
) {
953 case LTTNG_UST_CHAN_PER_CPU
:
954 if (attr
->output
== LTTNG_UST_MMAP
) {
955 if (attr
->overwrite
) {
956 if (attr
->read_timer_interval
== 0) {
957 transport_name
= "relay-overwrite-mmap";
959 transport_name
= "relay-overwrite-rt-mmap";
962 if (attr
->read_timer_interval
== 0) {
963 transport_name
= "relay-discard-mmap";
965 transport_name
= "relay-discard-rt-mmap";
972 case LTTNG_UST_CHAN_METADATA
:
973 if (attr
->output
== LTTNG_UST_MMAP
)
974 transport_name
= "relay-metadata-mmap";
979 transport_name
= "<unknown>";
983 transport
= lttng_transport_find(transport_name
);
985 DBG("LTTng transport %s not found\n",
990 chan
= zmalloc(sizeof(*chan
));
994 chan
->chan
= transport
->ops
.channel_create(transport_name
, NULL
,
995 attr
->subbuf_size
, attr
->num_subbuf
,
996 attr
->switch_timer_interval
,
997 attr
->read_timer_interval
,
998 attr
->uuid
, attr
->chan_id
);
1002 chan
->chan
->ops
= &transport
->ops
;
1003 memcpy(&chan
->attr
, attr
, sizeof(chan
->attr
));
1004 chan
->wait_fd
= ustctl_channel_get_wait_fd(chan
);
1005 chan
->wakeup_fd
= ustctl_channel_get_wakeup_fd(chan
);
1013 void ustctl_destroy_channel(struct ustctl_consumer_channel
*chan
)
1015 (void) ustctl_channel_close_wait_fd(chan
);
1016 (void) ustctl_channel_close_wakeup_fd(chan
);
1017 chan
->chan
->ops
->channel_destroy(chan
->chan
);
1021 int ustctl_send_channel_to_sessiond(int sock
,
1022 struct ustctl_consumer_channel
*channel
)
1024 struct shm_object_table
*table
;
1026 table
= channel
->chan
->handle
->table
;
1027 if (table
->size
<= 0)
1029 return ustctl_send_channel(sock
,
1031 table
->objects
[0].memory_map
,
1032 table
->objects
[0].memory_map_size
,
1037 int ustctl_send_stream_to_sessiond(int sock
,
1038 struct ustctl_consumer_stream
*stream
)
1041 return ustctl_send_stream(sock
, -1U, -1U, -1, -1, 0);
1043 return ustctl_send_stream(sock
,
1045 stream
->memory_map_size
,
1046 stream
->shm_fd
, stream
->wakeup_fd
,
1050 int ustctl_write_metadata_to_channel(
1051 struct ustctl_consumer_channel
*channel
,
1052 const char *metadata_str
, /* NOT null-terminated */
1053 size_t len
) /* metadata length */
1055 struct lttng_ust_lib_ring_buffer_ctx ctx
;
1056 struct lttng_channel
*chan
= channel
->chan
;
1057 const char *str
= metadata_str
;
1058 int ret
= 0, waitret
;
1059 size_t reserve_len
, pos
;
1061 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
1062 reserve_len
= min_t(size_t,
1063 chan
->ops
->packet_avail_size(chan
->chan
, chan
->handle
),
1065 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
1066 sizeof(char), -1, chan
->handle
);
1068 * We don't care about metadata buffer's records lost
1069 * count, because we always retry here. Report error if
1070 * we need to bail out after timeout or being
1073 waitret
= wait_cond_interruptible_timeout(
1075 ret
= chan
->ops
->event_reserve(&ctx
, 0);
1076 ret
!= -ENOBUFS
|| !ret
;
1078 LTTNG_METADATA_TIMEOUT_MSEC
);
1079 if (waitret
== -ETIMEDOUT
|| waitret
== -EINTR
|| ret
) {
1080 DBG("LTTng: Failure to write metadata to buffers (%s)\n",
1081 waitret
== -EINTR
? "interrupted" :
1082 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
1083 if (waitret
== -EINTR
)
1087 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
1088 chan
->ops
->event_commit(&ctx
);
1095 * Write at most one packet in the channel.
1096 * Returns the number of bytes written on success, < 0 on error.
1098 ssize_t
ustctl_write_one_packet_to_channel(
1099 struct ustctl_consumer_channel
*channel
,
1100 const char *metadata_str
, /* NOT null-terminated */
1101 size_t len
) /* metadata length */
1103 struct lttng_ust_lib_ring_buffer_ctx ctx
;
1104 struct lttng_channel
*chan
= channel
->chan
;
1105 const char *str
= metadata_str
;
1106 ssize_t reserve_len
;
1109 reserve_len
= min_t(ssize_t
,
1110 chan
->ops
->packet_avail_size(chan
->chan
, chan
->handle
),
1112 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
1113 sizeof(char), -1, chan
->handle
);
1114 ret
= chan
->ops
->event_reserve(&ctx
, 0);
1116 DBG("LTTng: event reservation failed");
1121 chan
->ops
->event_write(&ctx
, str
, reserve_len
);
1122 chan
->ops
->event_commit(&ctx
);
1128 int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel
*consumer_chan
)
1130 struct channel
*chan
;
1133 chan
= consumer_chan
->chan
->chan
;
1134 ret
= ring_buffer_channel_close_wait_fd(&chan
->backend
.config
,
1135 chan
, chan
->handle
);
1137 consumer_chan
->wait_fd
= -1;
1141 int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel
*consumer_chan
)
1143 struct channel
*chan
;
1146 chan
= consumer_chan
->chan
->chan
;
1147 ret
= ring_buffer_channel_close_wakeup_fd(&chan
->backend
.config
,
1148 chan
, chan
->handle
);
1150 consumer_chan
->wakeup_fd
= -1;
1154 int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream
*stream
)
1156 struct channel
*chan
;
1158 chan
= stream
->chan
->chan
->chan
;
1159 return ring_buffer_stream_close_wait_fd(&chan
->backend
.config
,
1160 chan
, stream
->handle
, stream
->cpu
);
1163 int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream
*stream
)
1165 struct channel
*chan
;
1167 chan
= stream
->chan
->chan
->chan
;
1168 return ring_buffer_stream_close_wakeup_fd(&chan
->backend
.config
,
1169 chan
, stream
->handle
, stream
->cpu
);
1172 struct ustctl_consumer_stream
*
1173 ustctl_create_stream(struct ustctl_consumer_channel
*channel
,
1176 struct ustctl_consumer_stream
*stream
;
1177 struct lttng_ust_shm_handle
*handle
;
1178 struct channel
*chan
;
1179 int shm_fd
, wait_fd
, wakeup_fd
;
1180 uint64_t memory_map_size
;
1181 struct lttng_ust_lib_ring_buffer
*buf
;
1186 handle
= channel
->chan
->handle
;
1190 chan
= channel
->chan
->chan
;
1191 buf
= channel_get_ring_buffer(&chan
->backend
.config
,
1192 chan
, cpu
, handle
, &shm_fd
, &wait_fd
,
1193 &wakeup_fd
, &memory_map_size
);
1196 ret
= lib_ring_buffer_open_read(buf
, handle
);
1200 stream
= zmalloc(sizeof(*stream
));
1203 stream
->handle
= handle
;
1205 stream
->chan
= channel
;
1206 stream
->shm_fd
= shm_fd
;
1207 stream
->wait_fd
= wait_fd
;
1208 stream
->wakeup_fd
= wakeup_fd
;
1209 stream
->memory_map_size
= memory_map_size
;
1217 void ustctl_destroy_stream(struct ustctl_consumer_stream
*stream
)
1219 struct lttng_ust_lib_ring_buffer
*buf
;
1220 struct ustctl_consumer_channel
*consumer_chan
;
1224 consumer_chan
= stream
->chan
;
1225 (void) ustctl_stream_close_wait_fd(stream
);
1226 (void) ustctl_stream_close_wakeup_fd(stream
);
1227 lib_ring_buffer_release_read(buf
, consumer_chan
->chan
->handle
);
1231 int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel
*chan
)
1235 return shm_get_wait_fd(chan
->chan
->handle
,
1236 &chan
->chan
->handle
->chan
._ref
);
1239 int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel
*chan
)
1243 return shm_get_wakeup_fd(chan
->chan
->handle
,
1244 &chan
->chan
->handle
->chan
._ref
);
1247 int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream
*stream
)
1249 struct lttng_ust_lib_ring_buffer
*buf
;
1250 struct ustctl_consumer_channel
*consumer_chan
;
1255 consumer_chan
= stream
->chan
;
1256 return shm_get_wait_fd(consumer_chan
->chan
->handle
, &buf
->self
._ref
);
1259 int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream
*stream
)
1261 struct lttng_ust_lib_ring_buffer
*buf
;
1262 struct ustctl_consumer_channel
*consumer_chan
;
1267 consumer_chan
= stream
->chan
;
1268 return shm_get_wakeup_fd(consumer_chan
->chan
->handle
, &buf
->self
._ref
);
1271 /* For mmap mode, readable without "get" operation */
1273 void *ustctl_get_mmap_base(struct ustctl_consumer_stream
*stream
)
1275 struct lttng_ust_lib_ring_buffer
*buf
;
1276 struct ustctl_consumer_channel
*consumer_chan
;
1281 consumer_chan
= stream
->chan
;
1282 return shmp(consumer_chan
->chan
->handle
, buf
->backend
.memory_map
);
1285 /* returns the length to mmap. */
1286 int ustctl_get_mmap_len(struct ustctl_consumer_stream
*stream
,
1289 struct ustctl_consumer_channel
*consumer_chan
;
1290 unsigned long mmap_buf_len
;
1291 struct channel
*chan
;
1295 consumer_chan
= stream
->chan
;
1296 chan
= consumer_chan
->chan
->chan
;
1297 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
1299 mmap_buf_len
= chan
->backend
.buf_size
;
1300 if (chan
->backend
.extra_reader_sb
)
1301 mmap_buf_len
+= chan
->backend
.subbuf_size
;
1302 if (mmap_buf_len
> INT_MAX
)
1304 *len
= mmap_buf_len
;
1308 /* returns the maximum size for sub-buffers. */
1309 int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream
*stream
,
1312 struct ustctl_consumer_channel
*consumer_chan
;
1313 struct channel
*chan
;
1317 consumer_chan
= stream
->chan
;
1318 chan
= consumer_chan
->chan
->chan
;
1319 *len
= chan
->backend
.subbuf_size
;
1324 * For mmap mode, operate on the current packet (between get/put or
1325 * get_next/put_next).
1328 /* returns the offset of the subbuffer belonging to the mmap reader. */
1329 int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream
*stream
,
1332 struct channel
*chan
;
1333 unsigned long sb_bindex
;
1334 struct lttng_ust_lib_ring_buffer
*buf
;
1335 struct ustctl_consumer_channel
*consumer_chan
;
1340 consumer_chan
= stream
->chan
;
1341 chan
= consumer_chan
->chan
->chan
;
1342 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
1344 sb_bindex
= subbuffer_id_get_index(&chan
->backend
.config
,
1345 buf
->backend
.buf_rsb
.id
);
1346 *off
= shmp(consumer_chan
->chan
->handle
,
1347 shmp_index(consumer_chan
->chan
->handle
, buf
->backend
.array
, sb_bindex
)->shmp
)->mmap_offset
;
1351 /* returns the size of the current sub-buffer, without padding (for mmap). */
1352 int ustctl_get_subbuf_size(struct ustctl_consumer_stream
*stream
,
1355 struct ustctl_consumer_channel
*consumer_chan
;
1356 struct channel
*chan
;
1357 struct lttng_ust_lib_ring_buffer
*buf
;
1363 consumer_chan
= stream
->chan
;
1364 chan
= consumer_chan
->chan
->chan
;
1365 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
1366 consumer_chan
->chan
->handle
);
1370 /* returns the size of the current sub-buffer, without padding (for mmap). */
1371 int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream
*stream
,
1374 struct ustctl_consumer_channel
*consumer_chan
;
1375 struct channel
*chan
;
1376 struct lttng_ust_lib_ring_buffer
*buf
;
1381 consumer_chan
= stream
->chan
;
1382 chan
= consumer_chan
->chan
->chan
;
1383 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
1384 consumer_chan
->chan
->handle
);
1385 *len
= PAGE_ALIGN(*len
);
1389 /* Get exclusive read access to the next sub-buffer that can be read. */
1390 int ustctl_get_next_subbuf(struct ustctl_consumer_stream
*stream
)
1392 struct lttng_ust_lib_ring_buffer
*buf
;
1393 struct ustctl_consumer_channel
*consumer_chan
;
1398 consumer_chan
= stream
->chan
;
1399 return lib_ring_buffer_get_next_subbuf(buf
,
1400 consumer_chan
->chan
->handle
);
1404 /* Release exclusive sub-buffer access, move consumer forward. */
1405 int ustctl_put_next_subbuf(struct ustctl_consumer_stream
*stream
)
1407 struct lttng_ust_lib_ring_buffer
*buf
;
1408 struct ustctl_consumer_channel
*consumer_chan
;
1413 consumer_chan
= stream
->chan
;
1414 lib_ring_buffer_put_next_subbuf(buf
, consumer_chan
->chan
->handle
);
1420 /* Get a snapshot of the current ring buffer producer and consumer positions */
1421 int ustctl_snapshot(struct ustctl_consumer_stream
*stream
)
1423 struct lttng_ust_lib_ring_buffer
*buf
;
1424 struct ustctl_consumer_channel
*consumer_chan
;
1429 consumer_chan
= stream
->chan
;
1430 return lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
1431 &buf
->prod_snapshot
, consumer_chan
->chan
->handle
);
1434 /* Get the consumer position (iteration start) */
1435 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream
*stream
,
1438 struct lttng_ust_lib_ring_buffer
*buf
;
1443 *pos
= buf
->cons_snapshot
;
1447 /* Get the producer position (iteration end) */
1448 int ustctl_snapshot_get_produced(struct ustctl_consumer_stream
*stream
,
1451 struct lttng_ust_lib_ring_buffer
*buf
;
1456 *pos
= buf
->prod_snapshot
;
1460 /* Get exclusive read access to the specified sub-buffer position */
1461 int ustctl_get_subbuf(struct ustctl_consumer_stream
*stream
,
1464 struct lttng_ust_lib_ring_buffer
*buf
;
1465 struct ustctl_consumer_channel
*consumer_chan
;
1470 consumer_chan
= stream
->chan
;
1471 return lib_ring_buffer_get_subbuf(buf
, *pos
,
1472 consumer_chan
->chan
->handle
);
1475 /* Release exclusive sub-buffer access */
1476 int ustctl_put_subbuf(struct ustctl_consumer_stream
*stream
)
1478 struct lttng_ust_lib_ring_buffer
*buf
;
1479 struct ustctl_consumer_channel
*consumer_chan
;
1484 consumer_chan
= stream
->chan
;
1485 lib_ring_buffer_put_subbuf(buf
, consumer_chan
->chan
->handle
);
1489 void ustctl_flush_buffer(struct ustctl_consumer_stream
*stream
,
1490 int producer_active
)
1492 struct lttng_ust_lib_ring_buffer
*buf
;
1493 struct ustctl_consumer_channel
*consumer_chan
;
1497 consumer_chan
= stream
->chan
;
1498 lib_ring_buffer_switch_slow(buf
,
1499 producer_active
? SWITCH_ACTIVE
: SWITCH_FLUSH
,
1500 consumer_chan
->chan
->handle
);
1504 struct lttng_ust_client_lib_ring_buffer_client_cb
*get_client_cb(
1505 struct lttng_ust_lib_ring_buffer
*buf
,
1506 struct lttng_ust_shm_handle
*handle
)
1508 struct channel
*chan
;
1509 const struct lttng_ust_lib_ring_buffer_config
*config
;
1510 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1512 chan
= shmp(handle
, buf
->backend
.chan
);
1513 config
= &chan
->backend
.config
;
1514 if (!config
->cb_ptr
)
1516 client_cb
= caa_container_of(config
->cb_ptr
,
1517 struct lttng_ust_client_lib_ring_buffer_client_cb
,
1522 int ustctl_get_timestamp_begin(struct ustctl_consumer_stream
*stream
,
1523 uint64_t *timestamp_begin
)
1525 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1526 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1527 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1529 if (!stream
|| !timestamp_begin
)
1531 client_cb
= get_client_cb(buf
, handle
);
1534 return client_cb
->timestamp_begin(buf
, handle
, timestamp_begin
);
1537 int ustctl_get_timestamp_end(struct ustctl_consumer_stream
*stream
,
1538 uint64_t *timestamp_end
)
1540 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1541 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1542 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1544 if (!stream
|| !timestamp_end
)
1546 client_cb
= get_client_cb(buf
, handle
);
1549 return client_cb
->timestamp_end(buf
, handle
, timestamp_end
);
1552 int ustctl_get_events_discarded(struct ustctl_consumer_stream
*stream
,
1553 uint64_t *events_discarded
)
1555 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1556 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1557 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1559 if (!stream
|| !events_discarded
)
1561 client_cb
= get_client_cb(buf
, handle
);
1564 return client_cb
->events_discarded(buf
, handle
, events_discarded
);
1567 int ustctl_get_content_size(struct ustctl_consumer_stream
*stream
,
1568 uint64_t *content_size
)
1570 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1571 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1572 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1574 if (!stream
|| !content_size
)
1576 client_cb
= get_client_cb(buf
, handle
);
1579 return client_cb
->content_size(buf
, handle
, content_size
);
1582 int ustctl_get_packet_size(struct ustctl_consumer_stream
*stream
,
1583 uint64_t *packet_size
)
1585 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1586 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1587 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1589 if (!stream
|| !packet_size
)
1591 client_cb
= get_client_cb(buf
, handle
);
1594 return client_cb
->packet_size(buf
, handle
, packet_size
);
1597 int ustctl_get_stream_id(struct ustctl_consumer_stream
*stream
,
1598 uint64_t *stream_id
)
1600 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1601 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1602 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1604 if (!stream
|| !stream_id
)
1606 client_cb
= get_client_cb(buf
, handle
);
1609 return client_cb
->stream_id(buf
, handle
, stream_id
);
1612 int ustctl_get_current_timestamp(struct ustctl_consumer_stream
*stream
,
1615 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1616 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1617 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1621 client_cb
= get_client_cb(buf
, handle
);
1622 if (!client_cb
|| !client_cb
->current_timestamp
)
1624 return client_cb
->current_timestamp(buf
, handle
, ts
);
1628 * Returns 0 on success, negative error value on error.
1630 int ustctl_recv_reg_msg(int sock
,
1631 enum ustctl_socket_type
*type
,
1638 uint32_t *bits_per_long
,
1639 uint32_t *uint8_t_alignment
,
1640 uint32_t *uint16_t_alignment
,
1641 uint32_t *uint32_t_alignment
,
1642 uint32_t *uint64_t_alignment
,
1643 uint32_t *long_alignment
,
1648 struct ustctl_reg_msg reg_msg
;
1650 len
= ustcomm_recv_unix_sock(sock
, ®_msg
, sizeof(reg_msg
));
1651 if (len
> 0 && len
!= sizeof(reg_msg
))
1658 if (reg_msg
.magic
== LTTNG_UST_COMM_MAGIC
) {
1659 *byte_order
= BYTE_ORDER
== BIG_ENDIAN
?
1660 BIG_ENDIAN
: LITTLE_ENDIAN
;
1661 } else if (reg_msg
.magic
== bswap_32(LTTNG_UST_COMM_MAGIC
)) {
1662 *byte_order
= BYTE_ORDER
== BIG_ENDIAN
?
1663 LITTLE_ENDIAN
: BIG_ENDIAN
;
1665 return -LTTNG_UST_ERR_INVAL_MAGIC
;
1667 switch (reg_msg
.socket_type
) {
1668 case 0: *type
= USTCTL_SOCKET_CMD
;
1670 case 1: *type
= USTCTL_SOCKET_NOTIFY
;
1673 return -LTTNG_UST_ERR_INVAL_SOCKET_TYPE
;
1675 *major
= reg_msg
.major
;
1676 *minor
= reg_msg
.minor
;
1678 *ppid
= reg_msg
.ppid
;
1681 *bits_per_long
= reg_msg
.bits_per_long
;
1682 *uint8_t_alignment
= reg_msg
.uint8_t_alignment
;
1683 *uint16_t_alignment
= reg_msg
.uint16_t_alignment
;
1684 *uint32_t_alignment
= reg_msg
.uint32_t_alignment
;
1685 *uint64_t_alignment
= reg_msg
.uint64_t_alignment
;
1686 *long_alignment
= reg_msg
.long_alignment
;
1687 memcpy(name
, reg_msg
.name
, LTTNG_UST_ABI_PROCNAME_LEN
);
1688 if (reg_msg
.major
!= LTTNG_UST_ABI_MAJOR_VERSION
) {
1689 return -LTTNG_UST_ERR_UNSUP_MAJOR
;
1695 int ustctl_recv_notify(int sock
, enum ustctl_notify_cmd
*notify_cmd
)
1697 struct ustcomm_notify_hdr header
;
1700 len
= ustcomm_recv_unix_sock(sock
, &header
, sizeof(header
));
1701 if (len
> 0 && len
!= sizeof(header
))
1707 switch (header
.notify_cmd
) {
1709 *notify_cmd
= USTCTL_NOTIFY_CMD_EVENT
;
1712 *notify_cmd
= USTCTL_NOTIFY_CMD_CHANNEL
;
1721 * Returns 0 on success, negative error value on error.
1723 int ustctl_recv_register_event(int sock
,
1730 struct ustctl_field
**fields
,
1731 char **model_emf_uri
)
1734 struct ustcomm_notify_event_msg msg
;
1735 size_t signature_len
, fields_len
, model_emf_uri_len
;
1736 char *a_sign
= NULL
, *a_model_emf_uri
= NULL
;
1737 struct ustctl_field
*a_fields
= NULL
;
1739 len
= ustcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
1740 if (len
> 0 && len
!= sizeof(msg
))
1747 *session_objd
= msg
.session_objd
;
1748 *channel_objd
= msg
.channel_objd
;
1749 strncpy(event_name
, msg
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1750 event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1751 *loglevel
= msg
.loglevel
;
1752 signature_len
= msg
.signature_len
;
1753 fields_len
= msg
.fields_len
;
1755 if (fields_len
% sizeof(*a_fields
) != 0) {
1759 model_emf_uri_len
= msg
.model_emf_uri_len
;
1761 /* recv signature. contains at least \0. */
1762 a_sign
= zmalloc(signature_len
);
1765 len
= ustcomm_recv_unix_sock(sock
, a_sign
, signature_len
);
1766 if (len
> 0 && len
!= signature_len
) {
1768 goto signature_error
;
1772 goto signature_error
;
1775 goto signature_error
;
1777 /* Enforce end of string */
1778 a_sign
[signature_len
- 1] = '\0';
1782 a_fields
= zmalloc(fields_len
);
1785 goto signature_error
;
1787 len
= ustcomm_recv_unix_sock(sock
, a_fields
, fields_len
);
1788 if (len
> 0 && len
!= fields_len
) {
1801 if (model_emf_uri_len
) {
1802 /* recv model_emf_uri_len */
1803 a_model_emf_uri
= zmalloc(model_emf_uri_len
);
1804 if (!a_model_emf_uri
) {
1808 len
= ustcomm_recv_unix_sock(sock
, a_model_emf_uri
,
1810 if (len
> 0 && len
!= model_emf_uri_len
) {
1821 /* Enforce end of string */
1822 a_model_emf_uri
[model_emf_uri_len
- 1] = '\0';
1825 *signature
= a_sign
;
1826 *nr_fields
= fields_len
/ sizeof(*a_fields
);
1828 *model_emf_uri
= a_model_emf_uri
;
1833 free(a_model_emf_uri
);
1842 * Returns 0 on success, negative error value on error.
1844 int ustctl_reply_register_event(int sock
,
1850 struct ustcomm_notify_hdr header
;
1851 struct ustcomm_notify_event_reply r
;
1854 memset(&reply
, 0, sizeof(reply
));
1855 reply
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_EVENT
;
1856 reply
.r
.ret_code
= ret_code
;
1857 reply
.r
.event_id
= id
;
1858 len
= ustcomm_send_unix_sock(sock
, &reply
, sizeof(reply
));
1859 if (len
> 0 && len
!= sizeof(reply
))
1867 * Returns 0 on success, negative UST or system error value on error.
1869 int ustctl_recv_register_channel(int sock
,
1870 int *session_objd
, /* session descriptor (output) */
1871 int *channel_objd
, /* channel descriptor (output) */
1873 struct ustctl_field
**fields
)
1876 struct ustcomm_notify_channel_msg msg
;
1878 struct ustctl_field
*a_fields
;
1880 len
= ustcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
1881 if (len
> 0 && len
!= sizeof(msg
))
1888 *session_objd
= msg
.session_objd
;
1889 *channel_objd
= msg
.channel_objd
;
1890 fields_len
= msg
.ctx_fields_len
;
1892 if (fields_len
% sizeof(*a_fields
) != 0) {
1898 a_fields
= zmalloc(fields_len
);
1903 len
= ustcomm_recv_unix_sock(sock
, a_fields
, fields_len
);
1904 if (len
> 0 && len
!= fields_len
) {
1919 *nr_fields
= fields_len
/ sizeof(*a_fields
);
1929 * Returns 0 on success, negative error value on error.
1931 int ustctl_reply_register_channel(int sock
,
1933 enum ustctl_channel_header header_type
,
1938 struct ustcomm_notify_hdr header
;
1939 struct ustcomm_notify_channel_reply r
;
1942 memset(&reply
, 0, sizeof(reply
));
1943 reply
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_CHANNEL
;
1944 reply
.r
.ret_code
= ret_code
;
1945 reply
.r
.chan_id
= chan_id
;
1946 switch (header_type
) {
1947 case USTCTL_CHANNEL_HEADER_COMPACT
:
1948 reply
.r
.header_type
= 1;
1950 case USTCTL_CHANNEL_HEADER_LARGE
:
1951 reply
.r
.header_type
= 2;
1954 reply
.r
.header_type
= 0;
1957 len
= ustcomm_send_unix_sock(sock
, &reply
, sizeof(reply
));
1958 if (len
> 0 && len
!= sizeof(reply
))
1965 static __attribute__((constructor
))
1966 void ustctl_init(void)
1969 lttng_ring_buffer_metadata_client_init();
1970 lttng_ring_buffer_client_overwrite_init();
1971 lttng_ring_buffer_client_overwrite_rt_init();
1972 lttng_ring_buffer_client_discard_init();
1973 lttng_ring_buffer_client_discard_rt_init();
1974 lib_ringbuffer_signal_init();
1977 static __attribute__((destructor
))
1978 void ustctl_exit(void)
1980 lttng_ring_buffer_client_discard_rt_exit();
1981 lttng_ring_buffer_client_discard_exit();
1982 lttng_ring_buffer_client_overwrite_rt_exit();
1983 lttng_ring_buffer_client_overwrite_exit();
1984 lttng_ring_buffer_metadata_client_exit();