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 /* Enable event, channel and session ioctl */
277 int ustctl_enable(int sock
, struct lttng_ust_object_data
*object
)
279 struct ustcomm_ust_msg lum
;
280 struct ustcomm_ust_reply lur
;
286 memset(&lum
, 0, sizeof(lum
));
287 lum
.handle
= object
->handle
;
288 lum
.cmd
= LTTNG_UST_ENABLE
;
289 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
292 DBG("enabled handle %u", object
->handle
);
296 /* Disable event, channel and session ioctl */
297 int ustctl_disable(int sock
, struct lttng_ust_object_data
*object
)
299 struct ustcomm_ust_msg lum
;
300 struct ustcomm_ust_reply lur
;
306 memset(&lum
, 0, sizeof(lum
));
307 lum
.handle
= object
->handle
;
308 lum
.cmd
= LTTNG_UST_DISABLE
;
309 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
312 DBG("disable handle %u", object
->handle
);
316 int ustctl_start_session(int sock
, int handle
)
318 struct lttng_ust_object_data obj
;
321 return ustctl_enable(sock
, &obj
);
324 int ustctl_stop_session(int sock
, int handle
)
326 struct lttng_ust_object_data obj
;
329 return ustctl_disable(sock
, &obj
);
332 int ustctl_tracepoint_list(int sock
)
334 struct ustcomm_ust_msg lum
;
335 struct ustcomm_ust_reply lur
;
336 int ret
, tp_list_handle
;
338 memset(&lum
, 0, sizeof(lum
));
339 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
340 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST
;
341 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
344 tp_list_handle
= lur
.ret_val
;
345 DBG("received tracepoint list handle %u", tp_list_handle
);
346 return tp_list_handle
;
349 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
350 struct lttng_ust_tracepoint_iter
*iter
)
352 struct ustcomm_ust_msg lum
;
353 struct ustcomm_ust_reply lur
;
359 memset(&lum
, 0, sizeof(lum
));
360 lum
.handle
= tp_list_handle
;
361 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST_GET
;
362 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
365 DBG("received tracepoint list entry name %s loglevel %d",
366 lur
.u
.tracepoint
.name
,
367 lur
.u
.tracepoint
.loglevel
);
368 memcpy(iter
, &lur
.u
.tracepoint
, sizeof(*iter
));
372 int ustctl_tracepoint_field_list(int sock
)
374 struct ustcomm_ust_msg lum
;
375 struct ustcomm_ust_reply lur
;
376 int ret
, tp_field_list_handle
;
378 memset(&lum
, 0, sizeof(lum
));
379 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
380 lum
.cmd
= LTTNG_UST_TRACEPOINT_FIELD_LIST
;
381 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
384 tp_field_list_handle
= lur
.ret_val
;
385 DBG("received tracepoint field list handle %u", tp_field_list_handle
);
386 return tp_field_list_handle
;
389 int ustctl_tracepoint_field_list_get(int sock
, int tp_field_list_handle
,
390 struct lttng_ust_field_iter
*iter
)
392 struct ustcomm_ust_msg lum
;
393 struct ustcomm_ust_reply lur
;
400 memset(&lum
, 0, sizeof(lum
));
401 lum
.handle
= tp_field_list_handle
;
402 lum
.cmd
= LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
;
403 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
406 len
= ustcomm_recv_unix_sock(sock
, iter
, sizeof(*iter
));
407 if (len
!= sizeof(*iter
)) {
410 DBG("received tracepoint field list entry event_name %s event_loglevel %d field_name %s field_type %d",
418 int ustctl_tracer_version(int sock
, struct lttng_ust_tracer_version
*v
)
420 struct ustcomm_ust_msg lum
;
421 struct ustcomm_ust_reply lur
;
427 memset(&lum
, 0, sizeof(lum
));
428 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
429 lum
.cmd
= LTTNG_UST_TRACER_VERSION
;
430 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
433 memcpy(v
, &lur
.u
.version
, sizeof(*v
));
434 DBG("received tracer version");
438 int ustctl_wait_quiescent(int sock
)
440 struct ustcomm_ust_msg lum
;
441 struct ustcomm_ust_reply lur
;
444 memset(&lum
, 0, sizeof(lum
));
445 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
446 lum
.cmd
= LTTNG_UST_WAIT_QUIESCENT
;
447 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
450 DBG("waited for quiescent state");
454 int ustctl_calibrate(int sock
, struct lttng_ust_calibrate
*calibrate
)
462 int ustctl_sock_flush_buffer(int sock
, struct lttng_ust_object_data
*object
)
464 struct ustcomm_ust_msg lum
;
465 struct ustcomm_ust_reply lur
;
471 memset(&lum
, 0, sizeof(lum
));
472 lum
.handle
= object
->handle
;
473 lum
.cmd
= LTTNG_UST_FLUSH_BUFFER
;
474 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
477 DBG("flushed buffer handle %u", object
->handle
);
482 int ustctl_send_channel(int sock
,
483 enum lttng_ust_chan_type type
,
493 len
= ustcomm_send_unix_sock(sock
, &size
, sizeof(size
));
494 if (len
!= sizeof(size
)) {
501 /* Send channel type */
502 len
= ustcomm_send_unix_sock(sock
, &type
, sizeof(type
));
503 if (len
!= sizeof(type
)) {
511 /* Send channel data */
512 len
= ustcomm_send_unix_sock(sock
, data
, size
);
521 len
= ustcomm_send_fds_unix_sock(sock
, &wakeup_fd
, 1);
532 int ustctl_send_stream(int sock
,
534 uint64_t memory_map_size
,
535 int shm_fd
, int wakeup_fd
,
543 /* finish iteration */
546 len
= ustcomm_send_unix_sock(sock
, &v
, sizeof(v
));
547 if (len
!= sizeof(v
)) {
557 len
= ustcomm_send_unix_sock(sock
, &memory_map_size
,
558 sizeof(memory_map_size
));
559 if (len
!= sizeof(memory_map_size
)) {
567 len
= ustcomm_send_unix_sock(sock
, &stream_nr
,
569 if (len
!= sizeof(stream_nr
)) {
577 /* Send shm fd and wakeup fd */
580 len
= ustcomm_send_fds_unix_sock(sock
, fds
, 2);
590 int ustctl_recv_channel_from_consumer(int sock
,
591 struct lttng_ust_object_data
**_channel_data
)
593 struct lttng_ust_object_data
*channel_data
;
598 channel_data
= zmalloc(sizeof(*channel_data
));
603 channel_data
->type
= LTTNG_UST_OBJECT_TYPE_CHANNEL
;
604 channel_data
->handle
= -1;
607 len
= ustcomm_recv_unix_sock(sock
, &channel_data
->size
,
608 sizeof(channel_data
->size
));
609 if (len
!= sizeof(channel_data
->size
)) {
617 /* recv channel type */
618 len
= ustcomm_recv_unix_sock(sock
, &channel_data
->u
.channel
.type
,
619 sizeof(channel_data
->u
.channel
.type
));
620 if (len
!= sizeof(channel_data
->u
.channel
.type
)) {
628 /* recv channel data */
629 channel_data
->u
.channel
.data
= zmalloc(channel_data
->size
);
630 if (!channel_data
->u
.channel
.data
) {
634 len
= ustcomm_recv_unix_sock(sock
, channel_data
->u
.channel
.data
,
636 if (len
!= channel_data
->size
) {
641 goto error_recv_data
;
644 len
= ustcomm_recv_fds_unix_sock(sock
, &wakeup_fd
, 1);
648 goto error_recv_data
;
651 goto error_recv_data
;
654 channel_data
->u
.channel
.wakeup_fd
= wakeup_fd
;
655 *_channel_data
= channel_data
;
659 free(channel_data
->u
.channel
.data
);
666 int ustctl_recv_stream_from_consumer(int sock
,
667 struct lttng_ust_object_data
**_stream_data
)
669 struct lttng_ust_object_data
*stream_data
;
674 stream_data
= zmalloc(sizeof(*stream_data
));
680 stream_data
->type
= LTTNG_UST_OBJECT_TYPE_STREAM
;
681 stream_data
->handle
= -1;
684 len
= ustcomm_recv_unix_sock(sock
, &stream_data
->size
,
685 sizeof(stream_data
->size
));
686 if (len
!= sizeof(stream_data
->size
)) {
693 if (stream_data
->size
== -1) {
694 ret
= -LTTNG_UST_ERR_NOENT
;
699 len
= ustcomm_recv_unix_sock(sock
, &stream_data
->u
.stream
.stream_nr
,
700 sizeof(stream_data
->u
.stream
.stream_nr
));
701 if (len
!= sizeof(stream_data
->u
.stream
.stream_nr
)) {
709 /* recv shm fd and wakeup fd */
710 len
= ustcomm_recv_fds_unix_sock(sock
, fds
, 2);
720 stream_data
->u
.stream
.shm_fd
= fds
[0];
721 stream_data
->u
.stream
.wakeup_fd
= fds
[1];
722 *_stream_data
= stream_data
;
731 int ustctl_send_channel_to_ust(int sock
, int session_handle
,
732 struct lttng_ust_object_data
*channel_data
)
734 struct ustcomm_ust_msg lum
;
735 struct ustcomm_ust_reply lur
;
741 memset(&lum
, 0, sizeof(lum
));
742 lum
.handle
= session_handle
;
743 lum
.cmd
= LTTNG_UST_CHANNEL
;
744 lum
.u
.channel
.len
= channel_data
->size
;
745 lum
.u
.channel
.type
= channel_data
->u
.channel
.type
;
746 ret
= ustcomm_send_app_msg(sock
, &lum
);
750 ret
= ustctl_send_channel(sock
,
751 channel_data
->u
.channel
.type
,
752 channel_data
->u
.channel
.data
,
754 channel_data
->u
.channel
.wakeup_fd
,
758 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
760 channel_data
->handle
= lur
.ret_val
;
765 int ustctl_send_stream_to_ust(int sock
,
766 struct lttng_ust_object_data
*channel_data
,
767 struct lttng_ust_object_data
*stream_data
)
769 struct ustcomm_ust_msg lum
;
770 struct ustcomm_ust_reply lur
;
773 memset(&lum
, 0, sizeof(lum
));
774 lum
.handle
= channel_data
->handle
;
775 lum
.cmd
= LTTNG_UST_STREAM
;
776 lum
.u
.stream
.len
= stream_data
->size
;
777 lum
.u
.stream
.stream_nr
= stream_data
->u
.stream
.stream_nr
;
778 ret
= ustcomm_send_app_msg(sock
, &lum
);
783 assert(stream_data
->type
== LTTNG_UST_OBJECT_TYPE_STREAM
);
785 ret
= ustctl_send_stream(sock
,
786 stream_data
->u
.stream
.stream_nr
,
788 stream_data
->u
.stream
.shm_fd
,
789 stream_data
->u
.stream
.wakeup_fd
, 1);
792 return ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
795 int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data
**dest
,
796 struct lttng_ust_object_data
*src
)
798 struct lttng_ust_object_data
*obj
;
801 if (src
->handle
!= -1) {
806 obj
= zmalloc(sizeof(*obj
));
812 obj
->type
= src
->type
;
813 obj
->handle
= src
->handle
;
814 obj
->size
= src
->size
;
817 case LTTNG_UST_OBJECT_TYPE_CHANNEL
:
819 obj
->u
.channel
.type
= src
->u
.channel
.type
;
820 if (src
->u
.channel
.wakeup_fd
>= 0) {
821 obj
->u
.channel
.wakeup_fd
=
822 dup(src
->u
.channel
.wakeup_fd
);
823 if (obj
->u
.channel
.wakeup_fd
< 0) {
825 goto chan_error_wakeup_fd
;
828 obj
->u
.channel
.wakeup_fd
=
829 src
->u
.channel
.wakeup_fd
;
831 obj
->u
.channel
.data
= zmalloc(obj
->size
);
832 if (!obj
->u
.channel
.data
) {
834 goto chan_error_alloc
;
836 memcpy(obj
->u
.channel
.data
, src
->u
.channel
.data
, obj
->size
);
840 if (src
->u
.channel
.wakeup_fd
>= 0) {
843 closeret
= close(obj
->u
.channel
.wakeup_fd
);
848 chan_error_wakeup_fd
:
853 case LTTNG_UST_OBJECT_TYPE_STREAM
:
855 obj
->u
.stream
.stream_nr
= src
->u
.stream
.stream_nr
;
856 if (src
->u
.stream
.wakeup_fd
>= 0) {
857 obj
->u
.stream
.wakeup_fd
=
858 dup(src
->u
.stream
.wakeup_fd
);
859 if (obj
->u
.stream
.wakeup_fd
< 0) {
861 goto stream_error_wakeup_fd
;
864 obj
->u
.stream
.wakeup_fd
=
865 src
->u
.stream
.wakeup_fd
;
868 if (src
->u
.stream
.shm_fd
>= 0) {
869 obj
->u
.stream
.shm_fd
=
870 dup(src
->u
.stream
.shm_fd
);
871 if (obj
->u
.stream
.shm_fd
< 0) {
873 goto stream_error_shm_fd
;
876 obj
->u
.stream
.shm_fd
=
877 src
->u
.stream
.shm_fd
;
882 if (src
->u
.stream
.wakeup_fd
>= 0) {
885 closeret
= close(obj
->u
.stream
.wakeup_fd
);
890 stream_error_wakeup_fd
:
909 /* Buffer operations */
911 struct ustctl_consumer_channel
*
912 ustctl_create_channel(struct ustctl_consumer_channel_attr
*attr
)
914 struct ustctl_consumer_channel
*chan
;
915 const char *transport_name
;
916 struct lttng_transport
*transport
;
918 switch (attr
->type
) {
919 case LTTNG_UST_CHAN_PER_CPU
:
920 if (attr
->output
== LTTNG_UST_MMAP
) {
921 if (attr
->overwrite
) {
922 if (attr
->read_timer_interval
== 0) {
923 transport_name
= "relay-overwrite-mmap";
925 transport_name
= "relay-overwrite-rt-mmap";
928 if (attr
->read_timer_interval
== 0) {
929 transport_name
= "relay-discard-mmap";
931 transport_name
= "relay-discard-rt-mmap";
938 case LTTNG_UST_CHAN_METADATA
:
939 if (attr
->output
== LTTNG_UST_MMAP
)
940 transport_name
= "relay-metadata-mmap";
945 transport_name
= "<unknown>";
949 transport
= lttng_transport_find(transport_name
);
951 DBG("LTTng transport %s not found\n",
956 chan
= zmalloc(sizeof(*chan
));
960 chan
->chan
= transport
->ops
.channel_create(transport_name
, NULL
,
961 attr
->subbuf_size
, attr
->num_subbuf
,
962 attr
->switch_timer_interval
,
963 attr
->read_timer_interval
,
964 attr
->uuid
, attr
->chan_id
);
968 chan
->chan
->ops
= &transport
->ops
;
969 memcpy(&chan
->attr
, attr
, sizeof(chan
->attr
));
970 chan
->wait_fd
= ustctl_channel_get_wait_fd(chan
);
971 chan
->wakeup_fd
= ustctl_channel_get_wakeup_fd(chan
);
979 void ustctl_destroy_channel(struct ustctl_consumer_channel
*chan
)
981 chan
->chan
->ops
->channel_destroy(chan
->chan
);
985 int ustctl_send_channel_to_sessiond(int sock
,
986 struct ustctl_consumer_channel
*channel
)
988 struct shm_object_table
*table
;
990 table
= channel
->chan
->handle
->table
;
991 if (table
->size
<= 0)
993 return ustctl_send_channel(sock
,
995 table
->objects
[0].memory_map
,
996 table
->objects
[0].memory_map_size
,
1001 int ustctl_send_stream_to_sessiond(int sock
,
1002 struct ustctl_consumer_stream
*stream
)
1005 return ustctl_send_stream(sock
, -1U, -1U, -1, -1, 0);
1007 return ustctl_send_stream(sock
,
1009 stream
->memory_map_size
,
1010 stream
->shm_fd
, stream
->wakeup_fd
,
1014 int ustctl_write_metadata_to_channel(
1015 struct ustctl_consumer_channel
*channel
,
1016 const char *metadata_str
, /* NOT null-terminated */
1017 size_t len
) /* metadata length */
1019 struct lttng_ust_lib_ring_buffer_ctx ctx
;
1020 struct lttng_channel
*chan
= channel
->chan
;
1021 const char *str
= metadata_str
;
1022 int ret
= 0, waitret
;
1023 size_t reserve_len
, pos
;
1025 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
1026 reserve_len
= min_t(size_t,
1027 chan
->ops
->packet_avail_size(chan
->chan
, chan
->handle
),
1029 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
1030 sizeof(char), -1, chan
->handle
);
1032 * We don't care about metadata buffer's records lost
1033 * count, because we always retry here. Report error if
1034 * we need to bail out after timeout or being
1037 waitret
= wait_cond_interruptible_timeout(
1039 ret
= chan
->ops
->event_reserve(&ctx
, 0);
1040 ret
!= -ENOBUFS
|| !ret
;
1042 LTTNG_METADATA_TIMEOUT_MSEC
);
1043 if (waitret
== -ETIMEDOUT
|| waitret
== -EINTR
|| ret
) {
1044 DBG("LTTng: Failure to write metadata to buffers (%s)\n",
1045 waitret
== -EINTR
? "interrupted" :
1046 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
1047 if (waitret
== -EINTR
)
1051 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
1052 chan
->ops
->event_commit(&ctx
);
1059 * Write at most one packet in the channel.
1060 * Returns the number of bytes written on success, < 0 on error.
1062 ssize_t
ustctl_write_one_packet_to_channel(
1063 struct ustctl_consumer_channel
*channel
,
1064 const char *metadata_str
, /* NOT null-terminated */
1065 size_t len
) /* metadata length */
1067 struct lttng_ust_lib_ring_buffer_ctx ctx
;
1068 struct lttng_channel
*chan
= channel
->chan
;
1069 const char *str
= metadata_str
;
1070 ssize_t reserve_len
;
1073 reserve_len
= min_t(ssize_t
,
1074 chan
->ops
->packet_avail_size(chan
->chan
, chan
->handle
),
1076 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
1077 sizeof(char), -1, chan
->handle
);
1078 ret
= chan
->ops
->event_reserve(&ctx
, 0);
1080 DBG("LTTng: event reservation failed");
1085 chan
->ops
->event_write(&ctx
, str
, reserve_len
);
1086 chan
->ops
->event_commit(&ctx
);
1092 int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel
*consumer_chan
)
1094 struct channel
*chan
;
1097 chan
= consumer_chan
->chan
->chan
;
1098 ret
= ring_buffer_channel_close_wait_fd(&chan
->backend
.config
,
1099 chan
, chan
->handle
);
1101 consumer_chan
->wait_fd
= -1;
1105 int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel
*consumer_chan
)
1107 struct channel
*chan
;
1110 chan
= consumer_chan
->chan
->chan
;
1111 ret
= ring_buffer_channel_close_wakeup_fd(&chan
->backend
.config
,
1112 chan
, chan
->handle
);
1114 consumer_chan
->wakeup_fd
= -1;
1118 int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream
*stream
)
1120 struct channel
*chan
;
1122 chan
= stream
->chan
->chan
->chan
;
1123 return ring_buffer_stream_close_wait_fd(&chan
->backend
.config
,
1124 chan
, stream
->handle
, stream
->cpu
);
1127 int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream
*stream
)
1129 struct channel
*chan
;
1131 chan
= stream
->chan
->chan
->chan
;
1132 return ring_buffer_stream_close_wakeup_fd(&chan
->backend
.config
,
1133 chan
, stream
->handle
, stream
->cpu
);
1136 struct ustctl_consumer_stream
*
1137 ustctl_create_stream(struct ustctl_consumer_channel
*channel
,
1140 struct ustctl_consumer_stream
*stream
;
1141 struct lttng_ust_shm_handle
*handle
;
1142 struct channel
*chan
;
1143 int shm_fd
, wait_fd
, wakeup_fd
;
1144 uint64_t memory_map_size
;
1145 struct lttng_ust_lib_ring_buffer
*buf
;
1150 handle
= channel
->chan
->handle
;
1154 chan
= channel
->chan
->chan
;
1155 buf
= channel_get_ring_buffer(&chan
->backend
.config
,
1156 chan
, cpu
, handle
, &shm_fd
, &wait_fd
,
1157 &wakeup_fd
, &memory_map_size
);
1160 ret
= lib_ring_buffer_open_read(buf
, handle
);
1164 stream
= zmalloc(sizeof(*stream
));
1167 stream
->handle
= handle
;
1169 stream
->chan
= channel
;
1170 stream
->shm_fd
= shm_fd
;
1171 stream
->wait_fd
= wait_fd
;
1172 stream
->wakeup_fd
= wakeup_fd
;
1173 stream
->memory_map_size
= memory_map_size
;
1181 void ustctl_destroy_stream(struct ustctl_consumer_stream
*stream
)
1183 struct lttng_ust_lib_ring_buffer
*buf
;
1184 struct ustctl_consumer_channel
*consumer_chan
;
1188 consumer_chan
= stream
->chan
;
1189 lib_ring_buffer_release_read(buf
, consumer_chan
->chan
->handle
);
1193 int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel
*chan
)
1197 return shm_get_wait_fd(chan
->chan
->handle
,
1198 &chan
->chan
->handle
->chan
._ref
);
1201 int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel
*chan
)
1205 return shm_get_wakeup_fd(chan
->chan
->handle
,
1206 &chan
->chan
->handle
->chan
._ref
);
1209 int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream
*stream
)
1211 struct lttng_ust_lib_ring_buffer
*buf
;
1212 struct ustctl_consumer_channel
*consumer_chan
;
1217 consumer_chan
= stream
->chan
;
1218 return shm_get_wait_fd(consumer_chan
->chan
->handle
, &buf
->self
._ref
);
1221 int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream
*stream
)
1223 struct lttng_ust_lib_ring_buffer
*buf
;
1224 struct ustctl_consumer_channel
*consumer_chan
;
1229 consumer_chan
= stream
->chan
;
1230 return shm_get_wakeup_fd(consumer_chan
->chan
->handle
, &buf
->self
._ref
);
1233 /* For mmap mode, readable without "get" operation */
1235 void *ustctl_get_mmap_base(struct ustctl_consumer_stream
*stream
)
1237 struct lttng_ust_lib_ring_buffer
*buf
;
1238 struct ustctl_consumer_channel
*consumer_chan
;
1243 consumer_chan
= stream
->chan
;
1244 return shmp(consumer_chan
->chan
->handle
, buf
->backend
.memory_map
);
1247 /* returns the length to mmap. */
1248 int ustctl_get_mmap_len(struct ustctl_consumer_stream
*stream
,
1251 struct ustctl_consumer_channel
*consumer_chan
;
1252 unsigned long mmap_buf_len
;
1253 struct channel
*chan
;
1257 consumer_chan
= stream
->chan
;
1258 chan
= consumer_chan
->chan
->chan
;
1259 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
1261 mmap_buf_len
= chan
->backend
.buf_size
;
1262 if (chan
->backend
.extra_reader_sb
)
1263 mmap_buf_len
+= chan
->backend
.subbuf_size
;
1264 if (mmap_buf_len
> INT_MAX
)
1266 *len
= mmap_buf_len
;
1270 /* returns the maximum size for sub-buffers. */
1271 int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream
*stream
,
1274 struct ustctl_consumer_channel
*consumer_chan
;
1275 struct channel
*chan
;
1279 consumer_chan
= stream
->chan
;
1280 chan
= consumer_chan
->chan
->chan
;
1281 *len
= chan
->backend
.subbuf_size
;
1286 * For mmap mode, operate on the current packet (between get/put or
1287 * get_next/put_next).
1290 /* returns the offset of the subbuffer belonging to the mmap reader. */
1291 int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream
*stream
,
1294 struct channel
*chan
;
1295 unsigned long sb_bindex
;
1296 struct lttng_ust_lib_ring_buffer
*buf
;
1297 struct ustctl_consumer_channel
*consumer_chan
;
1302 consumer_chan
= stream
->chan
;
1303 chan
= consumer_chan
->chan
->chan
;
1304 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
1306 sb_bindex
= subbuffer_id_get_index(&chan
->backend
.config
,
1307 buf
->backend
.buf_rsb
.id
);
1308 *off
= shmp(consumer_chan
->chan
->handle
,
1309 shmp_index(consumer_chan
->chan
->handle
, buf
->backend
.array
, sb_bindex
)->shmp
)->mmap_offset
;
1313 /* returns the size of the current sub-buffer, without padding (for mmap). */
1314 int ustctl_get_subbuf_size(struct ustctl_consumer_stream
*stream
,
1317 struct ustctl_consumer_channel
*consumer_chan
;
1318 struct channel
*chan
;
1319 struct lttng_ust_lib_ring_buffer
*buf
;
1325 consumer_chan
= stream
->chan
;
1326 chan
= consumer_chan
->chan
->chan
;
1327 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
1328 consumer_chan
->chan
->handle
);
1332 /* returns the size of the current sub-buffer, without padding (for mmap). */
1333 int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream
*stream
,
1336 struct ustctl_consumer_channel
*consumer_chan
;
1337 struct channel
*chan
;
1338 struct lttng_ust_lib_ring_buffer
*buf
;
1343 consumer_chan
= stream
->chan
;
1344 chan
= consumer_chan
->chan
->chan
;
1345 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
1346 consumer_chan
->chan
->handle
);
1347 *len
= PAGE_ALIGN(*len
);
1351 /* Get exclusive read access to the next sub-buffer that can be read. */
1352 int ustctl_get_next_subbuf(struct ustctl_consumer_stream
*stream
)
1354 struct lttng_ust_lib_ring_buffer
*buf
;
1355 struct ustctl_consumer_channel
*consumer_chan
;
1360 consumer_chan
= stream
->chan
;
1361 return lib_ring_buffer_get_next_subbuf(buf
,
1362 consumer_chan
->chan
->handle
);
1366 /* Release exclusive sub-buffer access, move consumer forward. */
1367 int ustctl_put_next_subbuf(struct ustctl_consumer_stream
*stream
)
1369 struct lttng_ust_lib_ring_buffer
*buf
;
1370 struct ustctl_consumer_channel
*consumer_chan
;
1375 consumer_chan
= stream
->chan
;
1376 lib_ring_buffer_put_next_subbuf(buf
, consumer_chan
->chan
->handle
);
1382 /* Get a snapshot of the current ring buffer producer and consumer positions */
1383 int ustctl_snapshot(struct ustctl_consumer_stream
*stream
)
1385 struct lttng_ust_lib_ring_buffer
*buf
;
1386 struct ustctl_consumer_channel
*consumer_chan
;
1391 consumer_chan
= stream
->chan
;
1392 return lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
1393 &buf
->prod_snapshot
, consumer_chan
->chan
->handle
);
1396 /* Get the consumer position (iteration start) */
1397 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream
*stream
,
1400 struct lttng_ust_lib_ring_buffer
*buf
;
1405 *pos
= buf
->cons_snapshot
;
1409 /* Get the producer position (iteration end) */
1410 int ustctl_snapshot_get_produced(struct ustctl_consumer_stream
*stream
,
1413 struct lttng_ust_lib_ring_buffer
*buf
;
1418 *pos
= buf
->prod_snapshot
;
1422 /* Get exclusive read access to the specified sub-buffer position */
1423 int ustctl_get_subbuf(struct ustctl_consumer_stream
*stream
,
1426 struct lttng_ust_lib_ring_buffer
*buf
;
1427 struct ustctl_consumer_channel
*consumer_chan
;
1432 consumer_chan
= stream
->chan
;
1433 return lib_ring_buffer_get_subbuf(buf
, *pos
,
1434 consumer_chan
->chan
->handle
);
1437 /* Release exclusive sub-buffer access */
1438 int ustctl_put_subbuf(struct ustctl_consumer_stream
*stream
)
1440 struct lttng_ust_lib_ring_buffer
*buf
;
1441 struct ustctl_consumer_channel
*consumer_chan
;
1446 consumer_chan
= stream
->chan
;
1447 lib_ring_buffer_put_subbuf(buf
, consumer_chan
->chan
->handle
);
1451 void ustctl_flush_buffer(struct ustctl_consumer_stream
*stream
,
1452 int producer_active
)
1454 struct lttng_ust_lib_ring_buffer
*buf
;
1455 struct ustctl_consumer_channel
*consumer_chan
;
1459 consumer_chan
= stream
->chan
;
1460 lib_ring_buffer_switch_slow(buf
,
1461 producer_active
? SWITCH_ACTIVE
: SWITCH_FLUSH
,
1462 consumer_chan
->chan
->handle
);
1466 struct lttng_ust_client_lib_ring_buffer_client_cb
*get_client_cb(
1467 struct lttng_ust_lib_ring_buffer
*buf
,
1468 struct lttng_ust_shm_handle
*handle
)
1470 struct channel
*chan
;
1471 const struct lttng_ust_lib_ring_buffer_config
*config
;
1472 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1474 chan
= shmp(handle
, buf
->backend
.chan
);
1475 config
= &chan
->backend
.config
;
1476 if (!config
->cb_ptr
)
1478 client_cb
= caa_container_of(config
->cb_ptr
,
1479 struct lttng_ust_client_lib_ring_buffer_client_cb
,
1484 int ustctl_get_timestamp_begin(struct ustctl_consumer_stream
*stream
,
1485 uint64_t *timestamp_begin
)
1487 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1488 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1489 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1491 if (!stream
|| !timestamp_begin
)
1493 client_cb
= get_client_cb(buf
, handle
);
1496 return client_cb
->timestamp_begin(buf
, handle
, timestamp_begin
);
1499 int ustctl_get_timestamp_end(struct ustctl_consumer_stream
*stream
,
1500 uint64_t *timestamp_end
)
1502 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1503 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1504 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1506 if (!stream
|| !timestamp_end
)
1508 client_cb
= get_client_cb(buf
, handle
);
1511 return client_cb
->timestamp_end(buf
, handle
, timestamp_end
);
1514 int ustctl_get_events_discarded(struct ustctl_consumer_stream
*stream
,
1515 uint64_t *events_discarded
)
1517 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1518 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1519 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1521 if (!stream
|| !events_discarded
)
1523 client_cb
= get_client_cb(buf
, handle
);
1526 return client_cb
->events_discarded(buf
, handle
, events_discarded
);
1529 int ustctl_get_content_size(struct ustctl_consumer_stream
*stream
,
1530 uint64_t *content_size
)
1532 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1533 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1534 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1536 if (!stream
|| !content_size
)
1538 client_cb
= get_client_cb(buf
, handle
);
1541 return client_cb
->content_size(buf
, handle
, content_size
);
1544 int ustctl_get_packet_size(struct ustctl_consumer_stream
*stream
,
1545 uint64_t *packet_size
)
1547 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1548 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1549 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1551 if (!stream
|| !packet_size
)
1553 client_cb
= get_client_cb(buf
, handle
);
1556 return client_cb
->packet_size(buf
, handle
, packet_size
);
1559 int ustctl_get_stream_id(struct ustctl_consumer_stream
*stream
,
1560 uint64_t *stream_id
)
1562 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1563 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1564 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1566 if (!stream
|| !stream_id
)
1568 client_cb
= get_client_cb(buf
, handle
);
1571 return client_cb
->stream_id(buf
, handle
, stream_id
);
1574 int ustctl_get_current_timestamp(struct ustctl_consumer_stream
*stream
,
1577 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1578 struct lttng_ust_lib_ring_buffer
*buf
= stream
->buf
;
1579 struct lttng_ust_shm_handle
*handle
= stream
->chan
->chan
->handle
;
1583 client_cb
= get_client_cb(buf
, handle
);
1584 if (!client_cb
|| !client_cb
->current_timestamp
)
1586 return client_cb
->current_timestamp(buf
, handle
, ts
);
1590 * Returns 0 on success, negative error value on error.
1592 int ustctl_recv_reg_msg(int sock
,
1593 enum ustctl_socket_type
*type
,
1600 uint32_t *bits_per_long
,
1601 uint32_t *uint8_t_alignment
,
1602 uint32_t *uint16_t_alignment
,
1603 uint32_t *uint32_t_alignment
,
1604 uint32_t *uint64_t_alignment
,
1605 uint32_t *long_alignment
,
1610 struct ustctl_reg_msg reg_msg
;
1612 len
= ustcomm_recv_unix_sock(sock
, ®_msg
, sizeof(reg_msg
));
1613 if (len
> 0 && len
!= sizeof(reg_msg
))
1620 if (reg_msg
.magic
== LTTNG_UST_COMM_MAGIC
) {
1621 *byte_order
= BYTE_ORDER
== BIG_ENDIAN
?
1622 BIG_ENDIAN
: LITTLE_ENDIAN
;
1623 } else if (reg_msg
.magic
== bswap_32(LTTNG_UST_COMM_MAGIC
)) {
1624 *byte_order
= BYTE_ORDER
== BIG_ENDIAN
?
1625 LITTLE_ENDIAN
: BIG_ENDIAN
;
1627 return -LTTNG_UST_ERR_INVAL_MAGIC
;
1629 switch (reg_msg
.socket_type
) {
1630 case 0: *type
= USTCTL_SOCKET_CMD
;
1632 case 1: *type
= USTCTL_SOCKET_NOTIFY
;
1635 return -LTTNG_UST_ERR_INVAL_SOCKET_TYPE
;
1637 *major
= reg_msg
.major
;
1638 *minor
= reg_msg
.minor
;
1640 *ppid
= reg_msg
.ppid
;
1643 *bits_per_long
= reg_msg
.bits_per_long
;
1644 *uint8_t_alignment
= reg_msg
.uint8_t_alignment
;
1645 *uint16_t_alignment
= reg_msg
.uint16_t_alignment
;
1646 *uint32_t_alignment
= reg_msg
.uint32_t_alignment
;
1647 *uint64_t_alignment
= reg_msg
.uint64_t_alignment
;
1648 *long_alignment
= reg_msg
.long_alignment
;
1649 memcpy(name
, reg_msg
.name
, LTTNG_UST_ABI_PROCNAME_LEN
);
1650 if (reg_msg
.major
!= LTTNG_UST_ABI_MAJOR_VERSION
) {
1651 return -LTTNG_UST_ERR_UNSUP_MAJOR
;
1657 int ustctl_recv_notify(int sock
, enum ustctl_notify_cmd
*notify_cmd
)
1659 struct ustcomm_notify_hdr header
;
1662 len
= ustcomm_recv_unix_sock(sock
, &header
, sizeof(header
));
1663 if (len
> 0 && len
!= sizeof(header
))
1669 switch (header
.notify_cmd
) {
1671 *notify_cmd
= USTCTL_NOTIFY_CMD_EVENT
;
1674 *notify_cmd
= USTCTL_NOTIFY_CMD_CHANNEL
;
1683 * Returns 0 on success, negative error value on error.
1685 int ustctl_recv_register_event(int sock
,
1692 struct ustctl_field
**fields
,
1693 char **model_emf_uri
)
1696 struct ustcomm_notify_event_msg msg
;
1697 size_t signature_len
, fields_len
, model_emf_uri_len
;
1698 char *a_sign
= NULL
, *a_model_emf_uri
= NULL
;
1699 struct ustctl_field
*a_fields
= NULL
;
1701 len
= ustcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
1702 if (len
> 0 && len
!= sizeof(msg
))
1709 *session_objd
= msg
.session_objd
;
1710 *channel_objd
= msg
.channel_objd
;
1711 strncpy(event_name
, msg
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1712 event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1713 *loglevel
= msg
.loglevel
;
1714 signature_len
= msg
.signature_len
;
1715 fields_len
= msg
.fields_len
;
1717 if (fields_len
% sizeof(*a_fields
) != 0) {
1721 model_emf_uri_len
= msg
.model_emf_uri_len
;
1723 /* recv signature. contains at least \0. */
1724 a_sign
= zmalloc(signature_len
);
1727 len
= ustcomm_recv_unix_sock(sock
, a_sign
, signature_len
);
1728 if (len
> 0 && len
!= signature_len
) {
1730 goto signature_error
;
1734 goto signature_error
;
1737 goto signature_error
;
1739 /* Enforce end of string */
1740 a_sign
[signature_len
- 1] = '\0';
1744 a_fields
= zmalloc(fields_len
);
1747 goto signature_error
;
1749 len
= ustcomm_recv_unix_sock(sock
, a_fields
, fields_len
);
1750 if (len
> 0 && len
!= fields_len
) {
1763 if (model_emf_uri_len
) {
1764 /* recv model_emf_uri_len */
1765 a_model_emf_uri
= zmalloc(model_emf_uri_len
);
1766 if (!a_model_emf_uri
) {
1770 len
= ustcomm_recv_unix_sock(sock
, a_model_emf_uri
,
1772 if (len
> 0 && len
!= model_emf_uri_len
) {
1783 /* Enforce end of string */
1784 a_model_emf_uri
[model_emf_uri_len
- 1] = '\0';
1787 *signature
= a_sign
;
1788 *nr_fields
= fields_len
/ sizeof(*a_fields
);
1790 *model_emf_uri
= a_model_emf_uri
;
1795 free(a_model_emf_uri
);
1804 * Returns 0 on success, negative error value on error.
1806 int ustctl_reply_register_event(int sock
,
1812 struct ustcomm_notify_hdr header
;
1813 struct ustcomm_notify_event_reply r
;
1816 memset(&reply
, 0, sizeof(reply
));
1817 reply
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_EVENT
;
1818 reply
.r
.ret_code
= ret_code
;
1819 reply
.r
.event_id
= id
;
1820 len
= ustcomm_send_unix_sock(sock
, &reply
, sizeof(reply
));
1821 if (len
> 0 && len
!= sizeof(reply
))
1829 * Returns 0 on success, negative UST or system error value on error.
1831 int ustctl_recv_register_channel(int sock
,
1832 int *session_objd
, /* session descriptor (output) */
1833 int *channel_objd
, /* channel descriptor (output) */
1835 struct ustctl_field
**fields
)
1838 struct ustcomm_notify_channel_msg msg
;
1840 struct ustctl_field
*a_fields
;
1842 len
= ustcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
1843 if (len
> 0 && len
!= sizeof(msg
))
1850 *session_objd
= msg
.session_objd
;
1851 *channel_objd
= msg
.channel_objd
;
1852 fields_len
= msg
.ctx_fields_len
;
1854 if (fields_len
% sizeof(*a_fields
) != 0) {
1860 a_fields
= zmalloc(fields_len
);
1865 len
= ustcomm_recv_unix_sock(sock
, a_fields
, fields_len
);
1866 if (len
> 0 && len
!= fields_len
) {
1881 *nr_fields
= fields_len
/ sizeof(*a_fields
);
1891 * Returns 0 on success, negative error value on error.
1893 int ustctl_reply_register_channel(int sock
,
1895 enum ustctl_channel_header header_type
,
1900 struct ustcomm_notify_hdr header
;
1901 struct ustcomm_notify_channel_reply r
;
1904 memset(&reply
, 0, sizeof(reply
));
1905 reply
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_CHANNEL
;
1906 reply
.r
.ret_code
= ret_code
;
1907 reply
.r
.chan_id
= chan_id
;
1908 switch (header_type
) {
1909 case USTCTL_CHANNEL_HEADER_COMPACT
:
1910 reply
.r
.header_type
= 1;
1912 case USTCTL_CHANNEL_HEADER_LARGE
:
1913 reply
.r
.header_type
= 2;
1916 reply
.r
.header_type
= 0;
1919 len
= ustcomm_send_unix_sock(sock
, &reply
, sizeof(reply
));
1920 if (len
> 0 && len
!= sizeof(reply
))
1927 static __attribute__((constructor
))
1928 void ustctl_init(void)
1931 lttng_ring_buffer_metadata_client_init();
1932 lttng_ring_buffer_client_overwrite_init();
1933 lttng_ring_buffer_client_overwrite_rt_init();
1934 lttng_ring_buffer_client_discard_init();
1935 lttng_ring_buffer_client_discard_rt_init();
1936 lib_ringbuffer_signal_init();
1939 static __attribute__((destructor
))
1940 void ustctl_exit(void)
1942 lttng_ring_buffer_client_discard_rt_exit();
1943 lttng_ring_buffer_client_discard_exit();
1944 lttng_ring_buffer_client_overwrite_rt_exit();
1945 lttng_ring_buffer_client_overwrite_exit();
1946 lttng_ring_buffer_metadata_client_exit();