2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@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, version 2 only,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
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.
29 #include <sys/mount.h>
30 #include <sys/resource.h>
31 #include <sys/socket.h>
33 #include <sys/types.h>
36 #include <urcu/futex.h>
37 #include <urcu/uatomic.h>
42 #include <lttng/lttng.h>
43 #include <common/common.h>
44 #include <common/compat/poll.h>
45 #include <common/compat/socket.h>
46 #include <common/defaults.h>
47 #include <common/futex.h>
48 #include <common/index/index.h>
49 #include <common/sessiond-comm/sessiond-comm.h>
50 #include <common/sessiond-comm/inet.h>
51 #include <common/sessiond-comm/relayd.h>
52 #include <common/uri.h>
53 #include <common/utils.h>
57 #include "lttng-relayd.h"
59 #include "health-relayd.h"
60 #include "testpoint.h"
61 #include "viewer-stream.h"
64 #include "ctf-trace.h"
65 #include "connection.h"
67 static struct lttng_uri
*live_uri
;
70 * This pipe is used to inform the worker thread that a command is queued and
71 * ready to be processed.
73 static int live_conn_pipe
[2] = { -1, -1 };
75 /* Shared between threads */
76 static int live_dispatch_thread_exit
;
78 static pthread_t live_listener_thread
;
79 static pthread_t live_dispatcher_thread
;
80 static pthread_t live_worker_thread
;
83 * Relay command queue.
85 * The live_thread_listener and live_thread_dispatcher communicate with this
88 static struct relay_conn_queue viewer_conn_queue
;
90 static uint64_t last_relay_viewer_session_id
;
104 * Receive a request buffer using a given socket, destination allocated buffer
107 * Return the size of the received message or else a negative value on error
108 * with errno being set by recvmsg() syscall.
111 ssize_t
recv_request(struct lttcomm_sock
*sock
, void *buf
, size_t size
)
118 ret
= sock
->ops
->recvmsg(sock
, buf
, size
, 0);
119 if (ret
< 0 || ret
!= size
) {
121 /* Orderly shutdown. Not necessary to print an error. */
122 DBG("Socket %d did an orderly shutdown", sock
->fd
);
124 ERR("Relay failed to receive request.");
133 * Send a response buffer using a given socket, source allocated buffer of
136 * Return the size of the sent message or else a negative value on error with
137 * errno being set by sendmsg() syscall.
140 ssize_t
send_response(struct lttcomm_sock
*sock
, void *buf
, size_t size
)
147 ret
= sock
->ops
->sendmsg(sock
, buf
, size
, 0);
149 ERR("Relayd failed to send response.");
156 * Atomically check if new streams got added in the session since the last
157 * check and reset the flag to 0.
159 * Returns 1 if new streams got added, 0 if nothing changed, a negative value
163 int check_new_streams(uint64_t session_id
, struct lttng_ht
*sessions_ht
)
166 unsigned long current_val
;
167 struct relay_session
*session
;
171 session
= session_find_by_id(sessions_ht
, session_id
);
173 DBG("Relay session %" PRIu64
" not found", session_id
);
178 current_val
= uatomic_cmpxchg(&session
->new_streams
, 1, 0);
186 * Send viewer streams to the given socket. The ignore_sent_flag indicates if
187 * this function should ignore the sent flag or not.
189 * Return 0 on success or else a negative value.
192 ssize_t
send_viewer_streams(struct lttcomm_sock
*sock
,
193 struct relay_session
*session
, unsigned int ignore_sent_flag
)
196 struct lttng_viewer_stream send_stream
;
197 struct lttng_ht_iter iter
;
198 struct relay_viewer_stream
*vstream
;
204 cds_lfht_for_each_entry(viewer_streams_ht
->ht
, &iter
.iter
, vstream
,
206 struct ctf_trace
*ctf_trace
;
208 health_code_update();
210 /* Ignore if not the same session. */
211 if (vstream
->session_id
!= session
->id
||
212 (!ignore_sent_flag
&& vstream
->sent_flag
)) {
216 ctf_trace
= ctf_trace_find_by_path(session
->ctf_traces_ht
,
220 send_stream
.id
= htobe64(vstream
->stream_handle
);
221 send_stream
.ctf_trace_id
= htobe64(ctf_trace
->id
);
222 send_stream
.metadata_flag
= htobe32(vstream
->metadata_flag
);
223 strncpy(send_stream
.path_name
, vstream
->path_name
,
224 sizeof(send_stream
.path_name
));
225 strncpy(send_stream
.channel_name
, vstream
->channel_name
,
226 sizeof(send_stream
.channel_name
));
228 DBG("Sending stream %" PRIu64
" to viewer", vstream
->stream_handle
);
229 ret
= send_response(sock
, &send_stream
, sizeof(send_stream
));
233 vstream
->sent_flag
= 1;
244 * Create every viewer stream possible for the given session with the seek
245 * type. Three counters *can* be return which are in order the total amount of
246 * viewer stream of the session, the number of unsent stream and the number of
247 * stream created. Those counters can be NULL and thus will be ignored.
249 * Return 0 on success or else a negative value.
252 int make_viewer_streams(struct relay_session
*session
,
253 enum lttng_viewer_seek seek_t
, uint32_t *nb_total
, uint32_t *nb_unsent
,
254 uint32_t *nb_created
)
257 struct lttng_ht_iter iter
;
258 struct ctf_trace
*ctf_trace
;
263 * This is to make sure we create viewer streams for a full received
264 * channel. For instance, if we have 8 streams for a channel that are
265 * concurrently being flagged ready, we can end up creating just a subset
266 * of the 8 streams (the ones that are flagged). This lock avoids this
269 pthread_mutex_lock(&session
->viewer_ready_lock
);
272 * Create viewer streams for relay streams that are ready to be used for a
273 * the given session id only.
276 cds_lfht_for_each_entry(session
->ctf_traces_ht
->ht
, &iter
.iter
, ctf_trace
,
278 struct relay_stream
*stream
;
280 health_code_update();
282 if (ctf_trace
->invalid_flag
) {
286 cds_list_for_each_entry(stream
, &ctf_trace
->stream_list
, trace_list
) {
287 struct relay_viewer_stream
*vstream
;
289 if (!stream
->viewer_ready
) {
293 vstream
= viewer_stream_find_by_id(stream
->stream_handle
);
295 vstream
= viewer_stream_create(stream
, seek_t
, ctf_trace
);
300 /* Acquire reference to ctf_trace. */
301 ctf_trace_get_ref(ctf_trace
);
304 /* Update number of created stream counter. */
307 } else if (!vstream
->sent_flag
&& nb_unsent
) {
308 /* Update number of unsent stream counter. */
311 /* Update number of total stream counter. */
322 pthread_mutex_unlock(&session
->viewer_ready_lock
);
327 * Write to writable pipe used to notify a thread.
330 int notify_thread_pipe(int wpipe
)
334 ret
= lttng_write(wpipe
, "!", 1);
336 PERROR("write poll pipe");
343 * Stop all threads by closing the thread quit pipe.
346 void stop_threads(void)
350 /* Stopping all threads */
351 DBG("Terminating all live threads");
352 ret
= notify_thread_pipe(live_conn_pipe
[1]);
354 ERR("write error on thread quit pipe");
357 /* Dispatch thread */
358 CMM_STORE_SHARED(live_dispatch_thread_exit
, 1);
359 futex_nto1_wake(&viewer_conn_queue
.futex
);
363 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
366 int create_thread_poll_set(struct lttng_poll_event
*events
, int size
)
370 if (events
== NULL
|| size
== 0) {
375 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
381 ret
= lttng_poll_add(events
, live_conn_pipe
[0], LPOLLIN
| LPOLLERR
);
393 * Check if the thread quit pipe was triggered.
395 * Return 1 if it was triggered else 0;
398 int check_live_conn_pipe(int fd
, uint32_t events
)
400 if (fd
== live_conn_pipe
[0] && (events
& LPOLLIN
)) {
408 * Create and init socket from uri.
411 struct lttcomm_sock
*init_socket(struct lttng_uri
*uri
)
414 struct lttcomm_sock
*sock
= NULL
;
416 sock
= lttcomm_alloc_sock_from_uri(uri
);
418 ERR("Allocating socket");
422 ret
= lttcomm_create_sock(sock
);
426 DBG("Listening on sock %d for live", sock
->fd
);
428 ret
= sock
->ops
->bind(sock
);
433 ret
= sock
->ops
->listen(sock
, -1);
443 lttcomm_destroy_sock(sock
);
449 * This thread manages the listening for new connections on the network
452 void *thread_listener(void *data
)
454 int i
, ret
, pollfd
, err
= -1;
455 uint32_t revents
, nb_fd
;
456 struct lttng_poll_event events
;
457 struct lttcomm_sock
*live_control_sock
;
459 DBG("[thread] Relay live listener started");
461 health_register(health_relayd
, HEALTH_RELAYD_TYPE_LIVE_LISTENER
);
463 health_code_update();
465 live_control_sock
= init_socket(live_uri
);
466 if (!live_control_sock
) {
467 goto error_sock_control
;
470 /* Pass 2 as size here for the thread quit pipe and control sockets. */
471 ret
= create_thread_poll_set(&events
, 2);
473 goto error_create_poll
;
476 /* Add the control socket */
477 ret
= lttng_poll_add(&events
, live_control_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
482 lttng_relay_notify_ready();
484 if (testpoint(relayd_thread_live_listener
)) {
485 goto error_testpoint
;
489 health_code_update();
491 DBG("Listener accepting live viewers connections");
495 ret
= lttng_poll_wait(&events
, -1);
499 * Restart interrupted system call.
501 if (errno
== EINTR
) {
508 DBG("Relay new viewer connection received");
509 for (i
= 0; i
< nb_fd
; i
++) {
510 health_code_update();
512 /* Fetch once the poll data */
513 revents
= LTTNG_POLL_GETEV(&events
, i
);
514 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
516 /* Thread quit pipe has been closed. Killing thread. */
517 ret
= check_live_conn_pipe(pollfd
, revents
);
523 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
524 ERR("socket poll error");
526 } else if (revents
& LPOLLIN
) {
528 * Get allocated in this thread, enqueued to a global queue,
529 * dequeued and freed in the worker thread.
532 struct relay_connection
*new_conn
;
533 struct lttcomm_sock
*newsock
;
535 new_conn
= connection_create();
540 newsock
= live_control_sock
->ops
->accept(live_control_sock
);
542 PERROR("accepting control sock");
543 connection_free(new_conn
);
546 DBG("Relay viewer connection accepted socket %d", newsock
->fd
);
548 ret
= setsockopt(newsock
->fd
, SOL_SOCKET
, SO_REUSEADDR
, &val
,
551 PERROR("setsockopt inet");
552 lttcomm_destroy_sock(newsock
);
553 connection_free(new_conn
);
556 new_conn
->sock
= newsock
;
558 /* Enqueue request for the dispatcher thread. */
559 cds_wfq_enqueue(&viewer_conn_queue
.queue
, &new_conn
->qnode
);
562 * Wake the dispatch queue futex. Implicit memory barrier with
563 * the exchange in cds_wfq_enqueue.
565 futex_nto1_wake(&viewer_conn_queue
.futex
);
574 lttng_poll_clean(&events
);
576 if (live_control_sock
->fd
>= 0) {
577 ret
= live_control_sock
->ops
->close(live_control_sock
);
582 lttcomm_destroy_sock(live_control_sock
);
586 DBG("Live viewer listener thread exited with error");
588 health_unregister(health_relayd
);
589 DBG("Live viewer listener thread cleanup complete");
595 * This thread manages the dispatching of the requests to worker threads
598 void *thread_dispatcher(void *data
)
602 struct cds_wfq_node
*node
;
603 struct relay_connection
*conn
= NULL
;
605 DBG("[thread] Live viewer relay dispatcher started");
607 health_register(health_relayd
, HEALTH_RELAYD_TYPE_LIVE_DISPATCHER
);
609 if (testpoint(relayd_thread_live_dispatcher
)) {
610 goto error_testpoint
;
613 health_code_update();
615 while (!CMM_LOAD_SHARED(live_dispatch_thread_exit
)) {
616 health_code_update();
618 /* Atomically prepare the queue futex */
619 futex_nto1_prepare(&viewer_conn_queue
.futex
);
622 health_code_update();
624 /* Dequeue commands */
625 node
= cds_wfq_dequeue_blocking(&viewer_conn_queue
.queue
);
627 DBG("Woken up but nothing in the live-viewer "
628 "relay command queue");
629 /* Continue thread execution */
632 conn
= caa_container_of(node
, struct relay_connection
, qnode
);
633 DBG("Dispatching viewer request waiting on sock %d",
637 * Inform worker thread of the new request. This call is blocking
638 * so we can be assured that the data will be read at some point in
639 * time or wait to the end of the world :)
641 ret
= lttng_write(live_conn_pipe
[1], &conn
, sizeof(conn
));
643 PERROR("write conn pipe");
644 connection_destroy(conn
);
647 } while (node
!= NULL
);
649 /* Futex wait on queue. Blocking call on futex() */
651 futex_nto1_wait(&viewer_conn_queue
.futex
);
655 /* Normal exit, no error */
662 ERR("Health error occurred in %s", __func__
);
664 health_unregister(health_relayd
);
665 DBG("Live viewer dispatch thread dying");
671 * Establish connection with the viewer and check the versions.
673 * Return 0 on success or else negative value.
676 int viewer_connect(struct relay_connection
*conn
)
679 struct lttng_viewer_connect reply
, msg
;
683 conn
->version_check_done
= 1;
685 health_code_update();
687 DBG("Viewer is establishing a connection to the relayd.");
689 ret
= recv_request(conn
->sock
, &msg
, sizeof(msg
));
694 health_code_update();
696 reply
.major
= RELAYD_VERSION_COMM_MAJOR
;
697 reply
.minor
= RELAYD_VERSION_COMM_MINOR
;
699 /* Major versions must be the same */
700 if (reply
.major
!= be32toh(msg
.major
)) {
701 DBG("Incompatible major versions ([relayd] %u vs [client] %u)",
702 reply
.major
, be32toh(msg
.major
));
707 conn
->major
= reply
.major
;
708 /* We adapt to the lowest compatible version */
709 if (reply
.minor
<= be32toh(msg
.minor
)) {
710 conn
->minor
= reply
.minor
;
712 conn
->minor
= be32toh(msg
.minor
);
715 if (be32toh(msg
.type
) == LTTNG_VIEWER_CLIENT_COMMAND
) {
716 conn
->type
= RELAY_VIEWER_COMMAND
;
717 } else if (be32toh(msg
.type
) == LTTNG_VIEWER_CLIENT_NOTIFICATION
) {
718 conn
->type
= RELAY_VIEWER_NOTIFICATION
;
720 ERR("Unknown connection type : %u", be32toh(msg
.type
));
725 reply
.major
= htobe32(reply
.major
);
726 reply
.minor
= htobe32(reply
.minor
);
727 if (conn
->type
== RELAY_VIEWER_COMMAND
) {
728 reply
.viewer_session_id
= htobe64(++last_relay_viewer_session_id
);
731 health_code_update();
733 ret
= send_response(conn
->sock
, &reply
, sizeof(reply
));
738 health_code_update();
740 DBG("Version check done using protocol %u.%u", conn
->major
, conn
->minor
);
748 * Send the viewer the list of current sessions.
750 * Return 0 on success or else a negative value.
753 int viewer_list_sessions(struct relay_connection
*conn
)
756 struct lttng_viewer_list_sessions session_list
;
758 long approx_before
, approx_after
;
759 struct lttng_ht_iter iter
;
760 struct lttng_viewer_session send_session
;
761 struct relay_session
*session
;
763 DBG("List sessions received");
766 cds_lfht_count_nodes(conn
->sessions_ht
->ht
, &approx_before
, &count
,
768 session_list
.sessions_count
= htobe32(count
);
770 health_code_update();
772 ret
= send_response(conn
->sock
, &session_list
, sizeof(session_list
));
777 health_code_update();
779 cds_lfht_for_each_entry(conn
->sessions_ht
->ht
, &iter
.iter
, session
,
781 health_code_update();
783 strncpy(send_session
.session_name
, session
->session_name
,
784 sizeof(send_session
.session_name
));
785 strncpy(send_session
.hostname
, session
->hostname
,
786 sizeof(send_session
.hostname
));
787 send_session
.id
= htobe64(session
->id
);
788 send_session
.live_timer
= htobe32(session
->live_timer
);
789 send_session
.clients
= htobe32(session
->viewer_refcount
);
790 send_session
.streams
= htobe32(session
->stream_count
);
792 health_code_update();
794 ret
= send_response(conn
->sock
, &send_session
, sizeof(send_session
));
799 health_code_update();
813 * Check if a connection is attached to a session.
814 * Return 1 if attached, 0 if not attached, a negative value on error.
817 int session_attached(struct relay_connection
*conn
, uint64_t session_id
)
819 struct relay_session
*session
;
822 if (!conn
->viewer_session
) {
825 cds_list_for_each_entry(session
,
826 &conn
->viewer_session
->sessions_head
,
827 viewer_session_list
) {
828 if (session
->id
== session_id
) {
839 * Send the viewer the list of current sessions.
842 int viewer_get_new_streams(struct relay_connection
*conn
)
844 int ret
, send_streams
= 0;
845 uint32_t nb_created
= 0, nb_unsent
= 0, nb_streams
= 0;
846 struct lttng_viewer_new_streams_request request
;
847 struct lttng_viewer_new_streams_response response
;
848 struct relay_session
*session
;
853 DBG("Get new streams received");
855 health_code_update();
857 /* Receive the request from the connected client. */
858 ret
= recv_request(conn
->sock
, &request
, sizeof(request
));
862 session_id
= be64toh(request
.session_id
);
864 health_code_update();
867 session
= session_find_by_id(conn
->sessions_ht
, session_id
);
869 DBG("Relay session %" PRIu64
" not found", session_id
);
870 response
.status
= htobe32(LTTNG_VIEWER_NEW_STREAMS_ERR
);
874 if (!session_attached(conn
, session_id
)) {
876 response
.status
= htobe32(LTTNG_VIEWER_NEW_STREAMS_ERR
);
881 response
.status
= htobe32(LTTNG_VIEWER_NEW_STREAMS_OK
);
887 ret
= make_viewer_streams(session
, LTTNG_VIEWER_SEEK_LAST
, NULL
, &nb_unsent
,
892 /* Only send back the newly created streams with the unsent ones. */
893 nb_streams
= nb_created
+ nb_unsent
;
894 response
.streams_count
= htobe32(nb_streams
);
897 * If the session is closed and we have no new streams to send,
898 * it means that the viewer has already received the whole trace
899 * for this session and should now close it.
901 if (nb_streams
== 0 && session
->close_flag
) {
903 response
.status
= htobe32(LTTNG_VIEWER_NEW_STREAMS_HUP
);
905 * Remove the session from the attached list of the connection
906 * and try to destroy it.
908 cds_list_del(&session
->viewer_session_list
);
909 session_viewer_try_destroy(conn
->sessions_ht
, session
);
914 health_code_update();
915 ret
= send_response(conn
->sock
, &response
, sizeof(response
));
919 health_code_update();
922 * Unknown or empty session, just return gracefully, the viewer knows what
925 if (!send_streams
|| !nb_streams
) {
931 * Send stream and *DON'T* ignore the sent flag so every viewer streams
932 * that were not sent from that point will be sent to the viewer.
934 ret
= send_viewer_streams(conn
->sock
, session
, 0);
946 * Send the viewer the list of current sessions.
949 int viewer_attach_session(struct relay_connection
*conn
)
951 int send_streams
= 0;
953 uint32_t nb_streams
= 0;
954 enum lttng_viewer_seek seek_type
;
955 struct lttng_viewer_attach_session_request request
;
956 struct lttng_viewer_attach_session_response response
;
957 struct relay_session
*session
;
961 health_code_update();
963 /* Receive the request from the connected client. */
964 ret
= recv_request(conn
->sock
, &request
, sizeof(request
));
969 health_code_update();
971 if (!conn
->viewer_session
) {
972 DBG("Client trying to attach before creating a live viewer session");
973 response
.status
= htobe32(LTTNG_VIEWER_ATTACH_NO_SESSION
);
978 session
= session_find_by_id(conn
->sessions_ht
,
979 be64toh(request
.session_id
));
981 DBG("Relay session %" PRIu64
" not found",
982 be64toh(request
.session_id
));
983 response
.status
= htobe32(LTTNG_VIEWER_ATTACH_UNK
);
986 session_viewer_attach(session
);
987 DBG("Attach session ID %" PRIu64
" received", be64toh(request
.session_id
));
989 if (uatomic_read(&session
->viewer_refcount
) > 1) {
990 DBG("Already a viewer attached");
991 response
.status
= htobe32(LTTNG_VIEWER_ATTACH_ALREADY
);
992 session_viewer_detach(session
);
994 } else if (session
->live_timer
== 0) {
995 DBG("Not live session");
996 response
.status
= htobe32(LTTNG_VIEWER_ATTACH_NOT_LIVE
);
1000 response
.status
= htobe32(LTTNG_VIEWER_ATTACH_OK
);
1001 cds_list_add(&session
->viewer_session_list
,
1002 &conn
->viewer_session
->sessions_head
);
1005 switch (be32toh(request
.seek
)) {
1006 case LTTNG_VIEWER_SEEK_BEGINNING
:
1007 case LTTNG_VIEWER_SEEK_LAST
:
1008 seek_type
= be32toh(request
.seek
);
1011 ERR("Wrong seek parameter");
1012 response
.status
= htobe32(LTTNG_VIEWER_ATTACH_SEEK_ERR
);
1017 if (!send_streams
) {
1021 ret
= make_viewer_streams(session
, seek_type
, &nb_streams
, NULL
, NULL
);
1025 response
.streams_count
= htobe32(nb_streams
);
1028 health_code_update();
1029 ret
= send_response(conn
->sock
, &response
, sizeof(response
));
1033 health_code_update();
1036 * Unknown or empty session, just return gracefully, the viewer knows what
1039 if (!send_streams
|| !nb_streams
) {
1044 /* Send stream and ignore the sent flag. */
1045 ret
= send_viewer_streams(conn
->sock
, session
, 1);
1057 * Send the next index for a stream.
1059 * Return 0 on success or else a negative value.
1062 int viewer_get_next_index(struct relay_connection
*conn
)
1065 struct lttng_viewer_get_next_index request_index
;
1066 struct lttng_viewer_index viewer_index
;
1067 struct ctf_packet_index packet_index
;
1068 struct relay_viewer_stream
*vstream
;
1069 struct relay_stream
*rstream
;
1070 struct ctf_trace
*ctf_trace
;
1071 struct relay_session
*session
;
1075 DBG("Viewer get next index");
1077 health_code_update();
1079 ret
= recv_request(conn
->sock
, &request_index
, sizeof(request_index
));
1083 health_code_update();
1086 vstream
= viewer_stream_find_by_id(be64toh(request_index
.stream_id
));
1092 session
= session_find_by_id(conn
->sessions_ht
, vstream
->session_id
);
1098 ctf_trace
= ctf_trace_find_by_path(session
->ctf_traces_ht
, vstream
->path_name
);
1101 memset(&viewer_index
, 0, sizeof(viewer_index
));
1104 * The viewer should not ask for index on metadata stream.
1106 if (vstream
->metadata_flag
) {
1107 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_HUP
);
1111 /* First time, we open the index file */
1112 if (vstream
->index_read_fd
< 0) {
1113 ret
= index_open(vstream
->path_name
, vstream
->channel_name
,
1114 vstream
->tracefile_count
, vstream
->tracefile_count_current
);
1115 if (ret
== -ENOENT
) {
1117 * The index is created only when the first data packet arrives, it
1118 * might not be ready at the beginning of the session
1120 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_RETRY
);
1122 } else if (ret
< 0) {
1123 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_ERR
);
1126 vstream
->index_read_fd
= ret
;
1129 rstream
= stream_find_by_id(relay_streams_ht
, vstream
->stream_handle
);
1132 if (!rstream
->close_flag
) {
1133 if (vstream
->abort_flag
) {
1134 /* Rotate on abort (overwrite). */
1135 DBG("Viewer rotate because of overwrite");
1136 ret
= viewer_stream_rotate(vstream
, rstream
);
1139 } else if (ret
== 1) {
1140 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_HUP
);
1141 viewer_stream_delete(vstream
);
1142 viewer_stream_destroy(ctf_trace
, vstream
);
1145 /* ret == 0 means successful so we continue. */
1148 pthread_mutex_lock(&rstream
->viewer_stream_rotation_lock
);
1149 if (rstream
->tracefile_count_current
== vstream
->tracefile_count_current
) {
1150 if (rstream
->beacon_ts_end
!= -1ULL &&
1151 vstream
->last_sent_index
== rstream
->total_index_received
) {
1152 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_INACTIVE
);
1153 viewer_index
.timestamp_end
= htobe64(rstream
->beacon_ts_end
);
1154 pthread_mutex_unlock(&rstream
->viewer_stream_rotation_lock
);
1156 } else if (rstream
->total_index_received
<= vstream
->last_sent_index
1157 && !vstream
->close_write_flag
) {
1159 * Reader and writer are working in the same tracefile, so we care
1160 * about the number of index received and sent. Otherwise, we read
1163 pthread_mutex_unlock(&rstream
->viewer_stream_rotation_lock
);
1164 /* No new index to send, retry later. */
1165 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_RETRY
);
1169 pthread_mutex_unlock(&rstream
->viewer_stream_rotation_lock
);
1170 } else if (rstream
->close_flag
&& vstream
->close_write_flag
&&
1171 vstream
->total_index_received
== vstream
->last_sent_index
) {
1172 /* Last index sent and current tracefile closed in write */
1173 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_HUP
);
1174 viewer_stream_delete(vstream
);
1175 viewer_stream_destroy(ctf_trace
, vstream
);
1178 vstream
->close_write_flag
= 1;
1181 if (!ctf_trace
->metadata_received
||
1182 ctf_trace
->metadata_received
> ctf_trace
->metadata_sent
) {
1183 viewer_index
.flags
|= LTTNG_VIEWER_FLAG_NEW_METADATA
;
1186 ret
= check_new_streams(vstream
->session_id
, conn
->sessions_ht
);
1189 } else if (ret
== 1) {
1190 viewer_index
.flags
|= LTTNG_VIEWER_FLAG_NEW_STREAM
;
1193 pthread_mutex_lock(&vstream
->overwrite_lock
);
1194 if (vstream
->abort_flag
) {
1196 * The file is being overwritten by the writer, we cannot * use it.
1198 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_RETRY
);
1199 pthread_mutex_unlock(&vstream
->overwrite_lock
);
1200 ret
= viewer_stream_rotate(vstream
, rstream
);
1203 } else if (ret
== 1) {
1204 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_HUP
);
1205 viewer_stream_delete(vstream
);
1206 viewer_stream_destroy(ctf_trace
, vstream
);
1212 ret
= lttng_read(vstream
->index_read_fd
, &packet_index
,
1213 sizeof(packet_index
));
1214 pthread_mutex_unlock(&vstream
->overwrite_lock
);
1215 if (ret
< sizeof(packet_index
)) {
1217 * The tracefile is closed in write, so we read up to EOF.
1219 if (vstream
->close_write_flag
== 1) {
1220 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_RETRY
);
1221 /* Rotate on normal EOF */
1222 ret
= viewer_stream_rotate(vstream
, rstream
);
1225 } else if (ret
== 1) {
1226 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_HUP
);
1227 viewer_stream_delete(vstream
);
1228 viewer_stream_destroy(ctf_trace
, vstream
);
1232 PERROR("Relay reading index file %d", vstream
->index_read_fd
);
1233 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_ERR
);
1237 viewer_index
.status
= htobe32(LTTNG_VIEWER_INDEX_OK
);
1238 vstream
->last_sent_index
++;
1242 * Indexes are stored in big endian, no need to switch before sending.
1244 viewer_index
.offset
= packet_index
.offset
;
1245 viewer_index
.packet_size
= packet_index
.packet_size
;
1246 viewer_index
.content_size
= packet_index
.content_size
;
1247 viewer_index
.timestamp_begin
= packet_index
.timestamp_begin
;
1248 viewer_index
.timestamp_end
= packet_index
.timestamp_end
;
1249 viewer_index
.events_discarded
= packet_index
.events_discarded
;
1250 viewer_index
.stream_id
= packet_index
.stream_id
;
1253 viewer_index
.flags
= htobe32(viewer_index
.flags
);
1254 health_code_update();
1256 ret
= send_response(conn
->sock
, &viewer_index
, sizeof(viewer_index
));
1260 health_code_update();
1262 DBG("Index %" PRIu64
" for stream %" PRIu64
" sent",
1263 vstream
->last_sent_index
, vstream
->stream_handle
);
1273 * Send the next index for a stream
1275 * Return 0 on success or else a negative value.
1278 int viewer_get_packet(struct relay_connection
*conn
)
1280 int ret
, send_data
= 0;
1284 struct lttng_viewer_get_packet get_packet_info
;
1285 struct lttng_viewer_trace_packet reply
;
1286 struct relay_viewer_stream
*stream
;
1287 struct relay_session
*session
;
1288 struct ctf_trace
*ctf_trace
;
1292 DBG2("Relay get data packet");
1294 health_code_update();
1296 ret
= recv_request(conn
->sock
, &get_packet_info
, sizeof(get_packet_info
));
1300 health_code_update();
1302 /* From this point on, the error label can be reached. */
1303 memset(&reply
, 0, sizeof(reply
));
1306 stream
= viewer_stream_find_by_id(be64toh(get_packet_info
.stream_id
));
1311 session
= session_find_by_id(conn
->sessions_ht
, stream
->session_id
);
1317 ctf_trace
= ctf_trace_find_by_path(session
->ctf_traces_ht
,
1322 * First time we read this stream, we need open the tracefile, we should
1323 * only arrive here if an index has already been sent to the viewer, so the
1324 * tracefile must exist, if it does not it is a fatal error.
1326 if (stream
->read_fd
< 0) {
1327 char fullpath
[PATH_MAX
];
1329 if (stream
->tracefile_count
> 0) {
1330 ret
= snprintf(fullpath
, PATH_MAX
, "%s/%s_%" PRIu64
, stream
->path_name
,
1331 stream
->channel_name
,
1332 stream
->tracefile_count_current
);
1334 ret
= snprintf(fullpath
, PATH_MAX
, "%s/%s", stream
->path_name
,
1335 stream
->channel_name
);
1340 ret
= open(fullpath
, O_RDONLY
);
1342 PERROR("Relay opening trace file");
1345 stream
->read_fd
= ret
;
1348 if (!ctf_trace
->metadata_received
||
1349 ctf_trace
->metadata_received
> ctf_trace
->metadata_sent
) {
1350 reply
.status
= htobe32(LTTNG_VIEWER_GET_PACKET_ERR
);
1351 reply
.flags
|= LTTNG_VIEWER_FLAG_NEW_METADATA
;
1355 ret
= check_new_streams(stream
->session_id
, conn
->sessions_ht
);
1358 } else if (ret
== 1) {
1359 reply
.status
= htobe32(LTTNG_VIEWER_GET_PACKET_ERR
);
1360 reply
.flags
|= LTTNG_VIEWER_FLAG_NEW_STREAM
;
1364 len
= be32toh(get_packet_info
.len
);
1365 data
= zmalloc(len
);
1367 PERROR("relay data zmalloc");
1371 ret
= lseek(stream
->read_fd
, be64toh(get_packet_info
.offset
), SEEK_SET
);
1374 * If the read fd was closed by the streaming side, the
1375 * abort_flag will be set to 1, otherwise it is an error.
1377 if (stream
->abort_flag
== 0) {
1381 reply
.status
= htobe32(LTTNG_VIEWER_GET_PACKET_EOF
);
1384 read_len
= lttng_read(stream
->read_fd
, data
, len
);
1385 if (read_len
< len
) {
1387 * If the read fd was closed by the streaming side, the
1388 * abort_flag will be set to 1, otherwise it is an error.
1390 if (stream
->abort_flag
== 0) {
1391 PERROR("Relay reading trace file, fd: %d, offset: %" PRIu64
,
1393 be64toh(get_packet_info
.offset
));
1396 reply
.status
= htobe32(LTTNG_VIEWER_GET_PACKET_EOF
);
1400 reply
.status
= htobe32(LTTNG_VIEWER_GET_PACKET_OK
);
1401 reply
.len
= htobe32(len
);
1406 reply
.status
= htobe32(LTTNG_VIEWER_GET_PACKET_ERR
);
1409 reply
.flags
= htobe32(reply
.flags
);
1411 health_code_update();
1413 ret
= send_response(conn
->sock
, &reply
, sizeof(reply
));
1417 health_code_update();
1420 health_code_update();
1421 ret
= send_response(conn
->sock
, data
, len
);
1425 health_code_update();
1428 DBG("Sent %u bytes for stream %" PRIu64
, len
,
1429 be64toh(get_packet_info
.stream_id
));
1440 * Send the session's metadata
1442 * Return 0 on success else a negative value.
1445 int viewer_get_metadata(struct relay_connection
*conn
)
1451 struct lttng_viewer_get_metadata request
;
1452 struct lttng_viewer_metadata_packet reply
;
1453 struct relay_viewer_stream
*stream
;
1454 struct ctf_trace
*ctf_trace
;
1455 struct relay_session
*session
;
1459 DBG("Relay get metadata");
1461 health_code_update();
1463 ret
= recv_request(conn
->sock
, &request
, sizeof(request
));
1467 health_code_update();
1470 stream
= viewer_stream_find_by_id(be64toh(request
.stream_id
));
1471 if (!stream
|| !stream
->metadata_flag
) {
1472 ERR("Invalid metadata stream");
1476 session
= session_find_by_id(conn
->sessions_ht
, stream
->session_id
);
1482 ctf_trace
= ctf_trace_find_by_path(session
->ctf_traces_ht
,
1485 assert(ctf_trace
->metadata_sent
<= ctf_trace
->metadata_received
);
1487 len
= ctf_trace
->metadata_received
- ctf_trace
->metadata_sent
;
1489 reply
.status
= htobe32(LTTNG_VIEWER_NO_NEW_METADATA
);
1493 /* first time, we open the metadata file */
1494 if (stream
->read_fd
< 0) {
1495 char fullpath
[PATH_MAX
];
1497 ret
= snprintf(fullpath
, PATH_MAX
, "%s/%s", stream
->path_name
,
1498 stream
->channel_name
);
1502 ret
= open(fullpath
, O_RDONLY
);
1504 PERROR("Relay opening metadata file");
1507 stream
->read_fd
= ret
;
1510 reply
.len
= htobe64(len
);
1511 data
= zmalloc(len
);
1513 PERROR("viewer metadata zmalloc");
1517 read_len
= lttng_read(stream
->read_fd
, data
, len
);
1518 if (read_len
< len
) {
1519 PERROR("Relay reading metadata file");
1522 ctf_trace
->metadata_sent
+= read_len
;
1523 reply
.status
= htobe32(LTTNG_VIEWER_METADATA_OK
);
1527 reply
.status
= htobe32(LTTNG_VIEWER_METADATA_ERR
);
1530 health_code_update();
1531 ret
= send_response(conn
->sock
, &reply
, sizeof(reply
));
1535 health_code_update();
1538 ret
= send_response(conn
->sock
, data
, len
);
1544 DBG("Sent %" PRIu64
" bytes of metadata for stream %" PRIu64
, len
,
1545 be64toh(request
.stream_id
));
1547 DBG("Metadata sent");
1557 * Create a viewer session.
1559 * Return 0 on success or else a negative value.
1562 int viewer_create_session(struct relay_connection
*conn
)
1565 struct lttng_viewer_create_session_response resp
;
1567 DBG("Viewer create session received");
1569 resp
.status
= htobe32(LTTNG_VIEWER_CREATE_SESSION_OK
);
1570 conn
->viewer_session
= zmalloc(sizeof(conn
->viewer_session
));
1571 if (!conn
->viewer_session
) {
1572 ERR("Allocation viewer session");
1573 resp
.status
= htobe32(LTTNG_VIEWER_CREATE_SESSION_ERR
);
1576 CDS_INIT_LIST_HEAD(&conn
->viewer_session
->sessions_head
);
1579 health_code_update();
1580 ret
= send_response(conn
->sock
, &resp
, sizeof(resp
));
1584 health_code_update();
1593 * live_relay_unknown_command: send -1 if received unknown command
1596 void live_relay_unknown_command(struct relay_connection
*conn
)
1598 struct lttcomm_relayd_generic_reply reply
;
1600 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1601 (void) send_response(conn
->sock
, &reply
, sizeof(reply
));
1605 * Process the commands received on the control socket
1608 int process_control(struct lttng_viewer_cmd
*recv_hdr
,
1609 struct relay_connection
*conn
)
1617 msg_value
= be32toh(recv_hdr
->cmd
);
1620 * Make sure we've done the version check before any command other then a
1621 * new client connection.
1623 if (msg_value
!= LTTNG_VIEWER_CONNECT
&& !conn
->version_check_done
) {
1624 ERR("Viewer conn value %" PRIu32
" before version check", msg_value
);
1629 switch (msg_value
) {
1630 case LTTNG_VIEWER_CONNECT
:
1631 ret
= viewer_connect(conn
);
1633 case LTTNG_VIEWER_LIST_SESSIONS
:
1634 ret
= viewer_list_sessions(conn
);
1636 case LTTNG_VIEWER_ATTACH_SESSION
:
1637 ret
= viewer_attach_session(conn
);
1639 case LTTNG_VIEWER_GET_NEXT_INDEX
:
1640 ret
= viewer_get_next_index(conn
);
1642 case LTTNG_VIEWER_GET_PACKET
:
1643 ret
= viewer_get_packet(conn
);
1645 case LTTNG_VIEWER_GET_METADATA
:
1646 ret
= viewer_get_metadata(conn
);
1648 case LTTNG_VIEWER_GET_NEW_STREAMS
:
1649 ret
= viewer_get_new_streams(conn
);
1651 case LTTNG_VIEWER_CREATE_SESSION
:
1652 ret
= viewer_create_session(conn
);
1655 ERR("Received unknown viewer command (%u)", be32toh(recv_hdr
->cmd
));
1656 live_relay_unknown_command(conn
);
1666 void cleanup_connection_pollfd(struct lttng_poll_event
*events
, int pollfd
)
1672 (void) lttng_poll_del(events
, pollfd
);
1674 ret
= close(pollfd
);
1676 ERR("Closing pollfd %d", pollfd
);
1681 * Delete all streams for a specific session ID.
1683 static void destroy_viewer_streams_by_session(struct relay_session
*session
)
1685 struct relay_viewer_stream
*stream
;
1686 struct lttng_ht_iter iter
;
1691 cds_lfht_for_each_entry(viewer_streams_ht
->ht
, &iter
.iter
, stream
,
1693 struct ctf_trace
*ctf_trace
;
1695 health_code_update();
1696 if (stream
->session_id
!= session
->id
) {
1700 ctf_trace
= ctf_trace_find_by_path(session
->ctf_traces_ht
,
1704 viewer_stream_delete(stream
);
1706 if (stream
->metadata_flag
) {
1707 ctf_trace
->metadata_sent
= 0;
1708 ctf_trace
->viewer_metadata_stream
= NULL
;
1711 viewer_stream_destroy(ctf_trace
, stream
);
1716 static void try_destroy_streams(struct relay_session
*session
)
1718 struct ctf_trace
*ctf_trace
;
1719 struct lttng_ht_iter iter
;
1723 cds_lfht_for_each_entry(session
->ctf_traces_ht
->ht
, &iter
.iter
, ctf_trace
,
1725 /* Attempt to destroy the ctf trace of that session. */
1726 ctf_trace_try_destroy(session
, ctf_trace
);
1731 * Delete and destroy a connection.
1733 * RCU read side lock MUST be acquired.
1735 static void destroy_connection(struct lttng_ht
*relay_connections_ht
,
1736 struct relay_connection
*conn
)
1738 struct relay_session
*session
, *tmp_session
;
1740 assert(relay_connections_ht
);
1743 connection_delete(relay_connections_ht
, conn
);
1745 if (!conn
->viewer_session
) {
1750 cds_list_for_each_entry_safe(session
, tmp_session
,
1751 &conn
->viewer_session
->sessions_head
,
1752 viewer_session_list
) {
1753 DBG("Cleaning connection of session ID %" PRIu64
, session
->id
);
1755 * Very important that this is done before destroying the session so we
1756 * can put back every viewer stream reference from the ctf_trace.
1758 destroy_viewer_streams_by_session(session
);
1759 try_destroy_streams(session
);
1760 cds_list_del(&session
->viewer_session_list
);
1761 session_viewer_try_destroy(conn
->sessions_ht
, session
);
1766 connection_destroy(conn
);
1770 * This thread does the actual work
1773 void *thread_worker(void *data
)
1777 struct relay_connection
*conn
;
1778 struct lttng_poll_event events
;
1779 struct lttng_ht
*relay_connections_ht
;
1780 struct lttng_ht_iter iter
;
1781 struct lttng_viewer_cmd recv_hdr
;
1782 struct relay_local_data
*relay_ctx
= (struct relay_local_data
*) data
;
1783 struct lttng_ht
*sessions_ht
= relay_ctx
->sessions_ht
;
1785 DBG("[thread] Live viewer relay worker started");
1787 rcu_register_thread();
1789 health_register(health_relayd
, HEALTH_RELAYD_TYPE_LIVE_WORKER
);
1791 if (testpoint(relayd_thread_live_worker
)) {
1792 goto error_testpoint
;
1795 /* table of connections indexed on socket */
1796 relay_connections_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1797 if (!relay_connections_ht
) {
1798 goto relay_connections_ht_error
;
1801 ret
= create_thread_poll_set(&events
, 2);
1803 goto error_poll_create
;
1806 ret
= lttng_poll_add(&events
, live_conn_pipe
[0], LPOLLIN
| LPOLLRDHUP
);
1815 health_code_update();
1817 /* Infinite blocking call, waiting for transmission */
1818 DBG3("Relayd live viewer worker thread polling...");
1819 health_poll_entry();
1820 ret
= lttng_poll_wait(&events
, -1);
1824 * Restart interrupted system call.
1826 if (errno
== EINTR
) {
1835 * Process control. The control connection is prioritised so we don't
1836 * starve it with high throughput tracing data on the data
1839 for (i
= 0; i
< nb_fd
; i
++) {
1840 /* Fetch once the poll data */
1841 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
1842 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
1844 health_code_update();
1846 /* Thread quit pipe has been closed. Killing thread. */
1847 ret
= check_live_conn_pipe(pollfd
, revents
);
1853 /* Inspect the relay conn pipe for new connection */
1854 if (pollfd
== live_conn_pipe
[0]) {
1855 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
1856 ERR("Relay live pipe error");
1858 } else if (revents
& LPOLLIN
) {
1859 ret
= lttng_read(live_conn_pipe
[0], &conn
, sizeof(conn
));
1863 conn
->sessions_ht
= sessions_ht
;
1864 connection_init(conn
);
1865 lttng_poll_add(&events
, conn
->sock
->fd
,
1866 LPOLLIN
| LPOLLRDHUP
);
1868 lttng_ht_add_unique_ulong(relay_connections_ht
,
1871 DBG("Connection socket %d added", conn
->sock
->fd
);
1875 conn
= connection_find_by_sock(relay_connections_ht
, pollfd
);
1876 /* If not found, there is a synchronization issue. */
1879 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
1880 cleanup_connection_pollfd(&events
, pollfd
);
1881 destroy_connection(relay_connections_ht
, conn
);
1882 } else if (revents
& LPOLLIN
) {
1883 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &recv_hdr
,
1884 sizeof(recv_hdr
), 0);
1886 /* Connection closed */
1887 cleanup_connection_pollfd(&events
, pollfd
);
1888 destroy_connection(relay_connections_ht
, conn
);
1889 DBG("Viewer control conn closed with %d", pollfd
);
1891 ret
= process_control(&recv_hdr
, conn
);
1893 /* Clear the session on error. */
1894 cleanup_connection_pollfd(&events
, pollfd
);
1895 destroy_connection(relay_connections_ht
, conn
);
1896 DBG("Viewer connection closed with %d", pollfd
);
1907 lttng_poll_clean(&events
);
1909 /* Cleanup reamaining connection object. */
1911 cds_lfht_for_each_entry(relay_connections_ht
->ht
, &iter
.iter
, conn
,
1913 health_code_update();
1914 destroy_connection(relay_connections_ht
, conn
);
1918 lttng_ht_destroy(relay_connections_ht
);
1919 relay_connections_ht_error
:
1920 /* Close relay conn pipes */
1921 utils_close_pipe(live_conn_pipe
);
1923 DBG("Viewer worker thread exited with error");
1925 DBG("Viewer worker thread cleanup complete");
1929 ERR("Health error occurred in %s", __func__
);
1931 health_unregister(health_relayd
);
1933 rcu_unregister_thread();
1938 * Create the relay command pipe to wake thread_manage_apps.
1939 * Closed in cleanup().
1941 static int create_conn_pipe(void)
1945 ret
= utils_create_pipe_cloexec(live_conn_pipe
);
1950 void live_stop_threads(void)
1957 ret
= pthread_join(live_listener_thread
, &status
);
1959 PERROR("pthread_join live listener");
1960 goto error
; /* join error, exit without cleanup */
1963 ret
= pthread_join(live_worker_thread
, &status
);
1965 PERROR("pthread_join live worker");
1966 goto error
; /* join error, exit without cleanup */
1969 ret
= pthread_join(live_dispatcher_thread
, &status
);
1971 PERROR("pthread_join live dispatcher");
1972 goto error
; /* join error, exit without cleanup */
1984 int live_start_threads(struct lttng_uri
*uri
,
1985 struct relay_local_data
*relay_ctx
)
1994 /* Check if daemon is UID = 0 */
1995 is_root
= !getuid();
1998 if (live_uri
->port
< 1024) {
1999 ERR("Need to be root to use ports < 1024");
2005 /* Setup the thread apps communication pipe. */
2006 if ((ret
= create_conn_pipe()) < 0) {
2010 /* Init relay command queue. */
2011 cds_wfq_init(&viewer_conn_queue
.queue
);
2013 /* Set up max poll set size */
2014 lttng_poll_set_max_size();
2016 /* Setup the dispatcher thread */
2017 ret
= pthread_create(&live_dispatcher_thread
, NULL
,
2018 thread_dispatcher
, (void *) NULL
);
2020 PERROR("pthread_create viewer dispatcher");
2021 goto exit_dispatcher
;
2024 /* Setup the worker thread */
2025 ret
= pthread_create(&live_worker_thread
, NULL
,
2026 thread_worker
, relay_ctx
);
2028 PERROR("pthread_create viewer worker");
2032 /* Setup the listener thread */
2033 ret
= pthread_create(&live_listener_thread
, NULL
,
2034 thread_listener
, (void *) NULL
);
2036 PERROR("pthread_create viewer listener");
2044 ret
= pthread_join(live_listener_thread
, &status
);
2046 PERROR("pthread_join live listener");
2047 goto error
; /* join error, exit without cleanup */
2051 ret
= pthread_join(live_worker_thread
, &status
);
2053 PERROR("pthread_join live worker");
2054 goto error
; /* join error, exit without cleanup */
2058 ret
= pthread_join(live_dispatcher_thread
, &status
);
2060 PERROR("pthread_join live dispatcher");
2061 goto error
; /* join error, exit without cleanup */