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"
66 static struct lttng_uri
*live_uri
;
69 * This pipe is used to inform the worker thread that a command is queued and
70 * ready to be processed.
72 static int live_relay_cmd_pipe
[2] = { -1, -1 };
74 /* Shared between threads */
75 static int live_dispatch_thread_exit
;
77 static pthread_t live_listener_thread
;
78 static pthread_t live_dispatcher_thread
;
79 static pthread_t live_worker_thread
;
82 * Relay command queue.
84 * The live_thread_listener and live_thread_dispatcher communicate with this
87 static struct relay_cmd_queue viewer_cmd_queue
;
89 static uint64_t last_relay_viewer_session_id
;
103 * Receive a request buffer using a given socket, destination allocated buffer
106 * Return the size of the received message or else a negative value on error
107 * with errno being set by recvmsg() syscall.
110 ssize_t
recv_request(struct lttcomm_sock
*sock
, void *buf
, size_t size
)
117 ret
= sock
->ops
->recvmsg(sock
, buf
, size
, 0);
118 if (ret
< 0 || ret
!= size
) {
120 /* Orderly shutdown. Not necessary to print an error. */
121 DBG("Socket %d did an orderly shutdown", sock
->fd
);
123 ERR("Relay failed to receive request.");
132 * Send a response buffer using a given socket, source allocated buffer of
135 * Return the size of the sent message or else a negative value on error with
136 * errno being set by sendmsg() syscall.
139 ssize_t
send_response(struct lttcomm_sock
*sock
, void *buf
, size_t size
)
146 ret
= sock
->ops
->sendmsg(sock
, buf
, size
, 0);
148 ERR("Relayd failed to send response.");
155 * Atomically check if new streams got added in the session since the last
156 * check and reset the flag to 0.
158 * Returns 1 if new streams got added, 0 if nothing changed, a negative value
162 int check_new_streams(uint64_t session_id
, struct lttng_ht
*sessions_ht
)
165 unsigned long current_val
;
166 struct relay_session
*session
;
170 session
= session_find_by_id(sessions_ht
, session_id
);
172 DBG("Relay session %" PRIu64
" not found", session_id
);
177 current_val
= uatomic_cmpxchg(&session
->new_streams
, 1, 0);
185 * Send viewer streams to the given socket. The ignore_sent_flag indicates if
186 * this function should ignore the sent flag or not.
188 * Return 0 on success or else a negative value.
191 ssize_t
send_viewer_streams(struct lttcomm_sock
*sock
,
192 struct relay_session
*session
, unsigned int ignore_sent_flag
)
195 struct lttng_viewer_stream send_stream
;
196 struct lttng_ht_iter iter
;
197 struct relay_viewer_stream
*vstream
;
203 cds_lfht_for_each_entry(viewer_streams_ht
->ht
, &iter
.iter
, vstream
,
205 struct ctf_trace
*ctf_trace
;
207 health_code_update();
209 /* Ignore if not the same session. */
210 if (vstream
->session_id
!= session
->id
||
211 (!ignore_sent_flag
&& vstream
->sent_flag
)) {
215 ctf_trace
= ctf_trace_find_by_path(session
->ctf_traces_ht
,
219 send_stream
.id
= htobe64(vstream
->stream_handle
);
220 send_stream
.ctf_trace_id
= htobe64(ctf_trace
->id
);
221 send_stream
.metadata_flag
= htobe32(vstream
->metadata_flag
);
222 strncpy(send_stream
.path_name
, vstream
->path_name
,
223 sizeof(send_stream
.path_name
));
224 strncpy(send_stream
.channel_name
, vstream
->channel_name
,
225 sizeof(send_stream
.channel_name
));
227 DBG("Sending stream %" PRIu64
" to viewer", vstream
->stream_handle
);
228 ret
= send_response(sock
, &send_stream
, sizeof(send_stream
));
232 vstream
->sent_flag
= 1;
243 * Create every viewer stream possible for the given session with the seek
244 * type. Three counters *can* be return which are in order the total amount of
245 * viewer stream of the session, the number of unsent stream and the number of
246 * stream created. Those counters can be NULL and thus will be ignored.
248 * Return 0 on success or else a negative value.
251 int make_viewer_streams(struct relay_session
*session
,
252 enum lttng_viewer_seek seek_t
, uint32_t *nb_total
, uint32_t *nb_unsent
,
253 uint32_t *nb_created
)
256 struct lttng_ht_iter iter
;
257 struct ctf_trace
*ctf_trace
;
262 * This is to make sure we create viewer streams for a full received
263 * channel. For instance, if we have 8 streams for a channel that are
264 * concurrently being flagged ready, we can end up creating just a subset
265 * of the 8 streams (the ones that are flagged). This lock avoids this
268 pthread_mutex_lock(&session
->viewer_ready_lock
);
271 * Create viewer streams for relay streams that are ready to be used for a
272 * the given session id only.
275 cds_lfht_for_each_entry(session
->ctf_traces_ht
->ht
, &iter
.iter
, ctf_trace
,
277 struct relay_stream
*stream
;
279 health_code_update();
281 if (ctf_trace
->invalid_flag
) {
285 cds_list_for_each_entry(stream
, &ctf_trace
->stream_list
, trace_list
) {
286 struct relay_viewer_stream
*vstream
;
288 if (!stream
->viewer_ready
) {
292 vstream
= viewer_stream_find_by_id(stream
->stream_handle
);
294 vstream
= viewer_stream_create(stream
, seek_t
, ctf_trace
);
299 /* Acquire reference to ctf_trace. */
300 ctf_trace_get_ref(ctf_trace
);
303 /* Update number of created stream counter. */
306 } else if (!vstream
->sent_flag
&& nb_unsent
) {
307 /* Update number of unsent stream counter. */
310 /* Update number of total stream counter. */
321 pthread_mutex_unlock(&session
->viewer_ready_lock
);
326 * Write to writable pipe used to notify a thread.
329 int notify_thread_pipe(int wpipe
)
333 ret
= lttng_write(wpipe
, "!", 1);
335 PERROR("write poll pipe");
342 * Stop all threads by closing the thread quit pipe.
345 void stop_threads(void)
349 /* Stopping all threads */
350 DBG("Terminating all live threads");
351 ret
= notify_thread_pipe(live_conn_pipe
[1]);
353 ERR("write error on thread quit pipe");
356 /* Dispatch thread */
357 CMM_STORE_SHARED(live_dispatch_thread_exit
, 1);
358 futex_nto1_wake(&viewer_cmd_queue
.futex
);
362 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
365 int create_thread_poll_set(struct lttng_poll_event
*events
, int size
)
369 if (events
== NULL
|| size
== 0) {
374 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
380 ret
= lttng_poll_add(events
, live_conn_pipe
[0], LPOLLIN
| LPOLLERR
);
392 * Check if the thread quit pipe was triggered.
394 * Return 1 if it was triggered else 0;
397 int check_live_conn_pipe(int fd
, uint32_t events
)
399 if (fd
== live_conn_pipe
[0] && (events
& LPOLLIN
)) {
407 * Create and init socket from uri.
410 struct lttcomm_sock
*init_socket(struct lttng_uri
*uri
)
413 struct lttcomm_sock
*sock
= NULL
;
415 sock
= lttcomm_alloc_sock_from_uri(uri
);
417 ERR("Allocating socket");
421 ret
= lttcomm_create_sock(sock
);
425 DBG("Listening on sock %d for live", sock
->fd
);
427 ret
= sock
->ops
->bind(sock
);
432 ret
= sock
->ops
->listen(sock
, -1);
442 lttcomm_destroy_sock(sock
);
448 * This thread manages the listening for new connections on the network
451 void *thread_listener(void *data
)
453 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.
531 struct relay_command
*relay_cmd
;
532 struct lttcomm_sock
*newsock
;
534 relay_cmd
= zmalloc(sizeof(*relay_cmd
));
536 PERROR("relay command zmalloc");
540 assert(pollfd
== live_control_sock
->fd
);
541 newsock
= live_control_sock
->ops
->accept(live_control_sock
);
543 PERROR("accepting control sock");
547 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
);
556 relay_cmd
->sock
= newsock
;
559 * Lock free enqueue the request.
561 cds_wfq_enqueue(&viewer_cmd_queue
.queue
, &relay_cmd
->node
);
564 * Wake the dispatch queue futex. Implicit memory
565 * barrier with the exchange in cds_wfq_enqueue.
567 futex_nto1_wake(&viewer_cmd_queue
.futex
);
576 lttng_poll_clean(&events
);
578 if (live_control_sock
->fd
>= 0) {
579 ret
= live_control_sock
->ops
->close(live_control_sock
);
584 lttcomm_destroy_sock(live_control_sock
);
588 DBG("Live viewer listener thread exited with error");
590 health_unregister(health_relayd
);
591 DBG("Live viewer listener thread cleanup complete");
597 * This thread manages the dispatching of the requests to worker threads
600 void *thread_dispatcher(void *data
)
604 struct cds_wfq_node
*node
;
605 struct relay_command
*relay_cmd
= NULL
;
607 DBG("[thread] Live viewer relay dispatcher started");
609 health_register(health_relayd
, HEALTH_RELAYD_TYPE_LIVE_DISPATCHER
);
611 if (testpoint(relayd_thread_live_dispatcher
)) {
612 goto error_testpoint
;
615 health_code_update();
617 while (!CMM_LOAD_SHARED(live_dispatch_thread_exit
)) {
618 health_code_update();
620 /* Atomically prepare the queue futex */
621 futex_nto1_prepare(&viewer_cmd_queue
.futex
);
624 health_code_update();
626 /* Dequeue commands */
627 node
= cds_wfq_dequeue_blocking(&viewer_cmd_queue
.queue
);
629 DBG("Woken up but nothing in the live-viewer "
630 "relay command queue");
631 /* Continue thread execution */
635 relay_cmd
= caa_container_of(node
, struct relay_command
, node
);
636 DBG("Dispatching viewer request waiting on sock %d",
637 relay_cmd
->sock
->fd
);
640 * Inform worker thread of the new request. This call is blocking
641 * so we can be assured that the data will be read at some point in
642 * time or wait to the end of the world :)
644 ret
= lttng_write(live_relay_cmd_pipe
[1], relay_cmd
,
647 if (ret
< sizeof(struct relay_command
)) {
648 PERROR("write cmd pipe");
651 } while (node
!= NULL
);
653 /* Futex wait on queue. Blocking call on futex() */
655 futex_nto1_wait(&viewer_cmd_queue
.futex
);
659 /* Normal exit, no error */
666 ERR("Health error occurred in %s", __func__
);
668 health_unregister(health_relayd
);
669 DBG("Live viewer dispatch thread dying");
675 * Establish connection with the viewer and check the versions.
677 * Return 0 on success or else negative value.
680 int viewer_connect(struct relay_command
*cmd
)
683 struct lttng_viewer_connect reply
, msg
;
687 cmd
->version_check_done
= 1;
689 health_code_update();
691 DBG("Viewer is establishing a connection to the relayd.");
693 ret
= recv_request(cmd
->sock
, &msg
, sizeof(msg
));
698 health_code_update();
700 reply
.major
= RELAYD_VERSION_COMM_MAJOR
;
701 reply
.minor
= RELAYD_VERSION_COMM_MINOR
;
703 /* Major versions must be the same */
704 if (reply
.major
!= be32toh(msg
.major
)) {
705 DBG("Incompatible major versions ([relayd] %u vs [client] %u)",
706 reply
.major
, be32toh(msg
.major
));
711 cmd
->major
= reply
.major
;
712 /* We adapt to the lowest compatible version */
713 if (reply
.minor
<= be32toh(msg
.minor
)) {
714 cmd
->minor
= reply
.minor
;
716 cmd
->minor
= be32toh(msg
.minor
);
719 if (be32toh(msg
.type
) == VIEWER_CLIENT_COMMAND
) {
720 cmd
->type
= RELAY_VIEWER_COMMAND
;
721 } else if (be32toh(msg
.type
) == VIEWER_CLIENT_NOTIFICATION
) {
722 cmd
->type
= RELAY_VIEWER_NOTIFICATION
;
724 ERR("Unknown connection type : %u", be32toh(msg
.type
));
729 reply
.major
= htobe32(reply
.major
);
730 reply
.minor
= htobe32(reply
.minor
);
731 if (cmd
->type
== RELAY_VIEWER_COMMAND
) {
732 reply
.viewer_session_id
= htobe64(++last_relay_viewer_session_id
);
735 health_code_update();
737 ret
= send_response(cmd
->sock
, &reply
, sizeof(reply
));
742 health_code_update();
744 DBG("Version check done using protocol %u.%u", cmd
->major
, cmd
->minor
);
752 * Send the viewer the list of current sessions.
754 * Return 0 on success or else a negative value.
757 int viewer_list_sessions(struct relay_command
*cmd
,
758 struct lttng_ht
*sessions_ht
)
761 struct lttng_viewer_list_sessions session_list
;
763 long approx_before
, approx_after
;
764 struct lttng_ht_iter iter
;
765 struct lttng_viewer_session send_session
;
766 struct relay_session
*session
;
768 DBG("List sessions received");
771 cds_lfht_count_nodes(sessions_ht
->ht
, &approx_before
, &count
, &approx_after
);
772 session_list
.sessions_count
= htobe32(count
);
774 health_code_update();
776 ret
= send_response(cmd
->sock
, &session_list
, sizeof(session_list
));
781 health_code_update();
783 cds_lfht_for_each_entry(sessions_ht
->ht
, &iter
.iter
, session
,
785 health_code_update();
787 strncpy(send_session
.session_name
, session
->session_name
,
788 sizeof(send_session
.session_name
));
789 strncpy(send_session
.hostname
, session
->hostname
,
790 sizeof(send_session
.hostname
));
791 send_session
.id
= htobe64(session
->id
);
792 send_session
.live_timer
= htobe32(session
->live_timer
);
793 send_session
.clients
= htobe32(session
->viewer_refcount
);
794 send_session
.streams
= htobe32(session
->stream_count
);
796 health_code_update();
798 ret
= send_response(cmd
->sock
, &send_session
, sizeof(send_session
));
803 health_code_update();
817 * Send the viewer the list of current sessions.
820 int viewer_get_new_streams(struct relay_command
*cmd
,
821 struct lttng_ht
*sessions_ht
)
823 int ret
, send_streams
= 0;
824 uint32_t nb_created
= 0, nb_unsent
= 0, nb_streams
= 0;
825 struct lttng_viewer_new_streams_request request
;
826 struct lttng_viewer_new_streams_response response
;
827 struct relay_session
*session
;
832 DBG("Get new streams received");
834 health_code_update();
836 /* Receive the request from the connected client. */
837 ret
= recv_request(cmd
->sock
, &request
, sizeof(request
));
842 health_code_update();
845 session
= session_find_by_id(sessions_ht
, be64toh(request
.session_id
));
847 DBG("Relay session %" PRIu64
" not found",
848 be64toh(request
.session_id
));
849 response
.status
= htobe32(VIEWER_NEW_STREAMS_ERR
);
853 if (cmd
->session_id
== session
->id
) {
854 /* We confirmed the viewer is asking for the same session. */
856 response
.status
= htobe32(VIEWER_NEW_STREAMS_OK
);
859 response
.status
= htobe32(VIEWER_NEW_STREAMS_ERR
);
867 ret
= make_viewer_streams(session
, VIEWER_SEEK_LAST
, NULL
, &nb_unsent
,
872 /* Only send back the newly created streams with the unsent ones. */
873 nb_streams
= nb_created
+ nb_unsent
;
874 response
.streams_count
= htobe32(nb_streams
);
877 health_code_update();
878 ret
= send_response(cmd
->sock
, &response
, sizeof(response
));
882 health_code_update();
885 * Unknown or empty session, just return gracefully, the viewer knows what
888 if (!send_streams
|| !nb_streams
) {
894 * Send stream and *DON'T* ignore the sent flag so every viewer streams
895 * that were not sent from that point will be sent to the viewer.
897 ret
= send_viewer_streams(cmd
->sock
, session
, 0);
909 * Send the viewer the list of current sessions.
912 int viewer_attach_session(struct relay_command
*cmd
,
913 struct lttng_ht
*sessions_ht
)
915 int send_streams
= 0;
917 uint32_t nb_streams
= 0;
918 enum lttng_viewer_seek seek_type
;
919 struct lttng_viewer_attach_session_request request
;
920 struct lttng_viewer_attach_session_response response
;
921 struct relay_session
*session
;
926 health_code_update();
928 /* Receive the request from the connected client. */
929 ret
= recv_request(cmd
->sock
, &request
, sizeof(request
));
934 health_code_update();
937 session
= session_find_by_id(sessions_ht
, be64toh(request
.session_id
));
939 DBG("Relay session %" PRIu64
" not found",
940 be64toh(request
.session_id
));
941 response
.status
= htobe32(VIEWER_ATTACH_UNK
);
944 session_viewer_attach(session
);
945 DBG("Attach session ID %" PRIu64
" received", be64toh(request
.session_id
));
947 if (uatomic_read(&session
->viewer_refcount
) > 1) {
948 DBG("Already a viewer attached");
949 response
.status
= htobe32(VIEWER_ATTACH_ALREADY
);
950 session_viewer_detach(session
);
952 } else if (session
->live_timer
== 0) {
953 DBG("Not live session");
954 response
.status
= htobe32(VIEWER_ATTACH_NOT_LIVE
);
958 response
.status
= htobe32(VIEWER_ATTACH_OK
);
959 cmd
->session_id
= session
->id
;
960 cmd
->session
= session
;
963 switch (be32toh(request
.seek
)) {
964 case VIEWER_SEEK_BEGINNING
:
965 case VIEWER_SEEK_LAST
:
966 seek_type
= be32toh(request
.seek
);
969 ERR("Wrong seek parameter");
970 response
.status
= htobe32(VIEWER_ATTACH_SEEK_ERR
);
979 ret
= make_viewer_streams(session
, seek_type
, &nb_streams
, NULL
, NULL
);
983 response
.streams_count
= htobe32(nb_streams
);
986 health_code_update();
987 ret
= send_response(cmd
->sock
, &response
, sizeof(response
));
991 health_code_update();
994 * Unknown or empty session, just return gracefully, the viewer knows what
997 if (!send_streams
|| !nb_streams
) {
1002 /* Send stream and ignore the sent flag. */
1003 ret
= send_viewer_streams(cmd
->sock
, session
, 1);
1015 * Send the next index for a stream.
1017 * Return 0 on success or else a negative value.
1020 int viewer_get_next_index(struct relay_command
*cmd
,
1021 struct lttng_ht
*sessions_ht
)
1024 struct lttng_viewer_get_next_index request_index
;
1025 struct lttng_viewer_index viewer_index
;
1026 struct ctf_packet_index packet_index
;
1027 struct relay_viewer_stream
*vstream
;
1028 struct relay_stream
*rstream
;
1029 struct ctf_trace
*ctf_trace
;
1030 struct relay_session
*session
;
1033 assert(sessions_ht
);
1035 DBG("Viewer get next index");
1037 health_code_update();
1039 ret
= recv_request(cmd
->sock
, &request_index
, sizeof(request_index
));
1043 health_code_update();
1046 session
= session_find_by_id(sessions_ht
, cmd
->session_id
);
1052 vstream
= viewer_stream_find_by_id(be64toh(request_index
.stream_id
));
1058 ctf_trace
= ctf_trace_find_by_path(session
->ctf_traces_ht
, vstream
->path_name
);
1061 memset(&viewer_index
, 0, sizeof(viewer_index
));
1064 * The viewer should not ask for index on metadata stream.
1066 if (vstream
->metadata_flag
) {
1067 viewer_index
.status
= htobe32(VIEWER_INDEX_HUP
);
1071 /* First time, we open the index file */
1072 if (vstream
->index_read_fd
< 0) {
1073 ret
= index_open(vstream
->path_name
, vstream
->channel_name
,
1074 vstream
->tracefile_count
, vstream
->tracefile_count_current
);
1075 if (ret
== -ENOENT
) {
1077 * The index is created only when the first data packet arrives, it
1078 * might not be ready at the beginning of the session
1080 viewer_index
.status
= htobe32(VIEWER_INDEX_RETRY
);
1082 } else if (ret
< 0) {
1083 viewer_index
.status
= htobe32(VIEWER_INDEX_ERR
);
1086 vstream
->index_read_fd
= ret
;
1089 rstream
= stream_find_by_id(relay_streams_ht
, vstream
->stream_handle
);
1092 if (!rstream
->close_flag
) {
1093 if (vstream
->abort_flag
) {
1094 /* Rotate on abort (overwrite). */
1095 DBG("Viewer rotate because of overwrite");
1096 ret
= viewer_stream_rotate(vstream
, rstream
);
1099 } else if (ret
== 1) {
1100 viewer_index
.status
= htobe32(VIEWER_INDEX_HUP
);
1101 viewer_stream_delete(vstream
);
1102 viewer_stream_destroy(ctf_trace
, vstream
);
1105 /* ret == 0 means successful so we continue. */
1108 pthread_mutex_lock(&rstream
->viewer_stream_rotation_lock
);
1109 if (rstream
->tracefile_count_current
== vstream
->tracefile_count_current
) {
1110 if (rstream
->beacon_ts_end
!= -1ULL &&
1111 vstream
->last_sent_index
== rstream
->total_index_received
) {
1112 viewer_index
.status
= htobe32(VIEWER_INDEX_INACTIVE
);
1113 viewer_index
.timestamp_end
= htobe64(rstream
->beacon_ts_end
);
1114 pthread_mutex_unlock(&rstream
->viewer_stream_rotation_lock
);
1116 } else if (rstream
->total_index_received
<= vstream
->last_sent_index
1117 && !vstream
->close_write_flag
) {
1119 * Reader and writer are working in the same tracefile, so we care
1120 * about the number of index received and sent. Otherwise, we read
1123 pthread_mutex_unlock(&rstream
->viewer_stream_rotation_lock
);
1124 /* No new index to send, retry later. */
1125 viewer_index
.status
= htobe32(VIEWER_INDEX_RETRY
);
1129 pthread_mutex_unlock(&rstream
->viewer_stream_rotation_lock
);
1130 } else if (rstream
->close_flag
&& vstream
->close_write_flag
&&
1131 vstream
->total_index_received
== vstream
->last_sent_index
) {
1132 /* Last index sent and current tracefile closed in write */
1133 viewer_index
.status
= htobe32(VIEWER_INDEX_HUP
);
1134 viewer_stream_delete(vstream
);
1135 viewer_stream_destroy(ctf_trace
, vstream
);
1138 vstream
->close_write_flag
= 1;
1141 if (!ctf_trace
->metadata_received
||
1142 ctf_trace
->metadata_received
> ctf_trace
->metadata_sent
) {
1143 viewer_index
.flags
|= LTTNG_VIEWER_FLAG_NEW_METADATA
;
1146 ret
= check_new_streams(vstream
->session_id
, sessions_ht
);
1149 } else if (ret
== 1) {
1150 viewer_index
.flags
|= LTTNG_VIEWER_FLAG_NEW_STREAM
;
1153 pthread_mutex_lock(&vstream
->overwrite_lock
);
1154 if (vstream
->abort_flag
) {
1156 * The file is being overwritten by the writer, we cannot * use it.
1158 viewer_index
.status
= htobe32(VIEWER_INDEX_RETRY
);
1159 pthread_mutex_unlock(&vstream
->overwrite_lock
);
1160 ret
= viewer_stream_rotate(vstream
, rstream
);
1163 } else if (ret
== 1) {
1164 viewer_index
.status
= htobe32(VIEWER_INDEX_HUP
);
1165 viewer_stream_delete(vstream
);
1166 viewer_stream_destroy(ctf_trace
, vstream
);
1172 ret
= lttng_read(vstream
->index_read_fd
, &packet_index
,
1173 sizeof(packet_index
));
1174 pthread_mutex_unlock(&vstream
->overwrite_lock
);
1175 if (ret
< sizeof(packet_index
)) {
1177 * The tracefile is closed in write, so we read up to EOF.
1179 if (vstream
->close_write_flag
== 1) {
1180 viewer_index
.status
= htobe32(VIEWER_INDEX_RETRY
);
1181 /* Rotate on normal EOF */
1182 ret
= viewer_stream_rotate(vstream
, rstream
);
1185 } else if (ret
== 1) {
1186 viewer_index
.status
= htobe32(VIEWER_INDEX_HUP
);
1187 viewer_stream_delete(vstream
);
1188 viewer_stream_destroy(ctf_trace
, vstream
);
1192 PERROR("Relay reading index file %d", vstream
->index_read_fd
);
1193 viewer_index
.status
= htobe32(VIEWER_INDEX_ERR
);
1197 viewer_index
.status
= htobe32(VIEWER_INDEX_OK
);
1198 vstream
->last_sent_index
++;
1202 * Indexes are stored in big endian, no need to switch before sending.
1204 viewer_index
.offset
= packet_index
.offset
;
1205 viewer_index
.packet_size
= packet_index
.packet_size
;
1206 viewer_index
.content_size
= packet_index
.content_size
;
1207 viewer_index
.timestamp_begin
= packet_index
.timestamp_begin
;
1208 viewer_index
.timestamp_end
= packet_index
.timestamp_end
;
1209 viewer_index
.events_discarded
= packet_index
.events_discarded
;
1210 viewer_index
.stream_id
= packet_index
.stream_id
;
1213 viewer_index
.flags
= htobe32(viewer_index
.flags
);
1214 health_code_update();
1216 ret
= send_response(cmd
->sock
, &viewer_index
, sizeof(viewer_index
));
1220 health_code_update();
1222 DBG("Index %" PRIu64
" for stream %" PRIu64
" sent",
1223 vstream
->last_sent_index
, vstream
->stream_handle
);
1233 * Send the next index for a stream
1235 * Return 0 on success or else a negative value.
1238 int viewer_get_packet(struct relay_command
*cmd
,
1239 struct lttng_ht
*sessions_ht
)
1241 int ret
, send_data
= 0;
1245 struct lttng_viewer_get_packet get_packet_info
;
1246 struct lttng_viewer_trace_packet reply
;
1247 struct relay_viewer_stream
*stream
;
1248 struct ctf_trace
*ctf_trace
;
1252 DBG2("Relay get data packet");
1254 health_code_update();
1256 ret
= recv_request(cmd
->sock
, &get_packet_info
, sizeof(get_packet_info
));
1260 health_code_update();
1262 /* From this point on, the error label can be reached. */
1263 memset(&reply
, 0, sizeof(reply
));
1266 stream
= viewer_stream_find_by_id(be64toh(get_packet_info
.stream_id
));
1271 ctf_trace
= ctf_trace_find_by_path(cmd
->session
->ctf_traces_ht
,
1276 * First time we read this stream, we need open the tracefile, we should
1277 * only arrive here if an index has already been sent to the viewer, so the
1278 * tracefile must exist, if it does not it is a fatal error.
1280 if (stream
->read_fd
< 0) {
1281 char fullpath
[PATH_MAX
];
1283 if (stream
->tracefile_count
> 0) {
1284 ret
= snprintf(fullpath
, PATH_MAX
, "%s/%s_%" PRIu64
, stream
->path_name
,
1285 stream
->channel_name
,
1286 stream
->tracefile_count_current
);
1288 ret
= snprintf(fullpath
, PATH_MAX
, "%s/%s", stream
->path_name
,
1289 stream
->channel_name
);
1294 ret
= open(fullpath
, O_RDONLY
);
1296 PERROR("Relay opening trace file");
1299 stream
->read_fd
= ret
;
1302 if (!ctf_trace
->metadata_received
||
1303 ctf_trace
->metadata_received
> ctf_trace
->metadata_sent
) {
1304 reply
.status
= htobe32(VIEWER_GET_PACKET_ERR
);
1305 reply
.flags
|= LTTNG_VIEWER_FLAG_NEW_METADATA
;
1309 ret
= check_new_streams(stream
->session_id
, sessions_ht
);
1312 } else if (ret
== 1) {
1313 reply
.status
= htobe32(VIEWER_GET_PACKET_ERR
);
1314 reply
.flags
|= LTTNG_VIEWER_FLAG_NEW_STREAM
;
1318 len
= be32toh(get_packet_info
.len
);
1319 data
= zmalloc(len
);
1321 PERROR("relay data zmalloc");
1325 ret
= lseek(stream
->read_fd
, be64toh(get_packet_info
.offset
), SEEK_SET
);
1328 * If the read fd was closed by the streaming side, the
1329 * abort_flag will be set to 1, otherwise it is an error.
1331 if (stream
->abort_flag
== 0) {
1335 reply
.status
= htobe32(VIEWER_GET_PACKET_EOF
);
1338 read_len
= lttng_read(stream
->read_fd
, data
, len
);
1339 if (read_len
< len
) {
1341 * If the read fd was closed by the streaming side, the
1342 * abort_flag will be set to 1, otherwise it is an error.
1344 if (stream
->abort_flag
== 0) {
1345 PERROR("Relay reading trace file, fd: %d, offset: %" PRIu64
,
1347 be64toh(get_packet_info
.offset
));
1350 reply
.status
= htobe32(VIEWER_GET_PACKET_EOF
);
1354 reply
.status
= htobe32(VIEWER_GET_PACKET_OK
);
1355 reply
.len
= htobe32(len
);
1360 reply
.status
= htobe32(VIEWER_GET_PACKET_ERR
);
1363 reply
.flags
= htobe32(reply
.flags
);
1365 health_code_update();
1367 ret
= send_response(cmd
->sock
, &reply
, sizeof(reply
));
1371 health_code_update();
1374 health_code_update();
1375 ret
= send_response(cmd
->sock
, data
, len
);
1379 health_code_update();
1382 DBG("Sent %u bytes for stream %" PRIu64
, len
,
1383 be64toh(get_packet_info
.stream_id
));
1394 * Send the session's metadata
1396 * Return 0 on success else a negative value.
1399 int viewer_get_metadata(struct relay_command
*cmd
)
1405 struct lttng_viewer_get_metadata request
;
1406 struct lttng_viewer_metadata_packet reply
;
1407 struct relay_viewer_stream
*stream
;
1408 struct ctf_trace
*ctf_trace
;
1412 DBG("Relay get metadata");
1414 health_code_update();
1416 ret
= recv_request(cmd
->sock
, &request
, sizeof(request
));
1420 health_code_update();
1423 stream
= viewer_stream_find_by_id(be64toh(request
.stream_id
));
1424 if (!stream
|| !stream
->metadata_flag
) {
1425 ERR("Invalid metadata stream");
1429 ctf_trace
= ctf_trace_find_by_path(cmd
->session
->ctf_traces_ht
,
1432 assert(ctf_trace
->metadata_sent
<= ctf_trace
->metadata_received
);
1434 len
= ctf_trace
->metadata_received
- ctf_trace
->metadata_sent
;
1436 reply
.status
= htobe32(VIEWER_NO_NEW_METADATA
);
1440 /* first time, we open the metadata file */
1441 if (stream
->read_fd
< 0) {
1442 char fullpath
[PATH_MAX
];
1444 ret
= snprintf(fullpath
, PATH_MAX
, "%s/%s", stream
->path_name
,
1445 stream
->channel_name
);
1449 ret
= open(fullpath
, O_RDONLY
);
1451 PERROR("Relay opening metadata file");
1454 stream
->read_fd
= ret
;
1457 reply
.len
= htobe64(len
);
1458 data
= zmalloc(len
);
1460 PERROR("viewer metadata zmalloc");
1464 read_len
= lttng_read(stream
->read_fd
, data
, len
);
1465 if (read_len
< len
) {
1466 PERROR("Relay reading metadata file");
1469 ctf_trace
->metadata_sent
+= read_len
;
1470 reply
.status
= htobe32(VIEWER_METADATA_OK
);
1474 reply
.status
= htobe32(VIEWER_METADATA_ERR
);
1477 health_code_update();
1478 ret
= send_response(cmd
->sock
, &reply
, sizeof(reply
));
1482 health_code_update();
1485 ret
= send_response(cmd
->sock
, data
, len
);
1491 DBG("Sent %" PRIu64
" bytes of metadata for stream %" PRIu64
, len
,
1492 be64toh(request
.stream_id
));
1494 DBG("Metadata sent");
1504 * live_relay_unknown_command: send -1 if received unknown command
1507 void live_relay_unknown_command(struct relay_command
*cmd
)
1509 struct lttcomm_relayd_generic_reply reply
;
1511 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1512 (void) send_response(cmd
->sock
, &reply
, sizeof(reply
));
1516 * Process the commands received on the control socket
1519 int process_control(struct lttng_viewer_cmd
*recv_hdr
,
1520 struct relay_command
*cmd
, struct lttng_ht
*sessions_ht
)
1527 assert(sessions_ht
);
1529 msg_value
= be32toh(recv_hdr
->cmd
);
1532 * Make sure we've done the version check before any command other then a
1533 * new client connection.
1535 if (msg_value
!= VIEWER_CONNECT
&& !cmd
->version_check_done
) {
1536 ERR("Viewer cmd value %" PRIu32
" before version check", msg_value
);
1541 switch (msg_value
) {
1542 case VIEWER_CONNECT
:
1543 ret
= viewer_connect(cmd
);
1545 case VIEWER_LIST_SESSIONS
:
1546 ret
= viewer_list_sessions(cmd
, sessions_ht
);
1548 case VIEWER_ATTACH_SESSION
:
1549 ret
= viewer_attach_session(cmd
, sessions_ht
);
1551 case VIEWER_GET_NEXT_INDEX
:
1552 ret
= viewer_get_next_index(cmd
, sessions_ht
);
1554 case VIEWER_GET_PACKET
:
1555 ret
= viewer_get_packet(cmd
, sessions_ht
);
1557 case VIEWER_GET_METADATA
:
1558 ret
= viewer_get_metadata(cmd
);
1560 case VIEWER_GET_NEW_STREAMS
:
1561 ret
= viewer_get_new_streams(cmd
, sessions_ht
);
1564 ERR("Received unknown viewer command (%u)", be32toh(recv_hdr
->cmd
));
1565 live_relay_unknown_command(cmd
);
1575 void cleanup_poll_connection(struct lttng_poll_event
*events
, int pollfd
)
1581 lttng_poll_del(events
, pollfd
);
1583 ret
= close(pollfd
);
1585 ERR("Closing pollfd %d", pollfd
);
1590 * Create and add connection to the given hash table.
1592 * Return poll add value or else -1 on error.
1595 int add_connection(int fd
, struct lttng_poll_event
*events
,
1596 struct lttng_ht
*relay_connections_ht
)
1599 struct relay_command
*relay_connection
;
1602 assert(relay_connections_ht
);
1604 relay_connection
= zmalloc(sizeof(struct relay_command
));
1605 if (relay_connection
== NULL
) {
1606 PERROR("Relay command zmalloc");
1610 ret
= lttng_read(fd
, relay_connection
, sizeof(*relay_connection
));
1611 if (ret
< sizeof(*relay_connection
)) {
1612 PERROR("read relay cmd pipe");
1616 lttng_ht_node_init_ulong(&relay_connection
->sock_n
,
1617 (unsigned long) relay_connection
->sock
->fd
);
1619 lttng_ht_add_unique_ulong(relay_connections_ht
,
1620 &relay_connection
->sock_n
);
1623 return lttng_poll_add(events
, relay_connection
->sock
->fd
,
1624 LPOLLIN
| LPOLLRDHUP
);
1627 free(relay_connection
);
1633 void deferred_free_connection(struct rcu_head
*head
)
1635 struct relay_command
*relay_connection
=
1636 caa_container_of(head
, struct relay_command
, rcu_node
);
1638 lttcomm_destroy_sock(relay_connection
->sock
);
1639 free(relay_connection
);
1643 * Delete all streams for a specific session ID.
1645 static void destroy_viewer_streams_by_session(struct relay_session
*session
)
1647 struct relay_viewer_stream
*stream
;
1648 struct lttng_ht_iter iter
;
1653 cds_lfht_for_each_entry(viewer_streams_ht
->ht
, &iter
.iter
, stream
,
1655 struct ctf_trace
*ctf_trace
;
1657 health_code_update();
1658 if (stream
->session_id
!= session
->id
) {
1662 ctf_trace
= ctf_trace_find_by_path(session
->ctf_traces_ht
,
1666 viewer_stream_delete(stream
);
1668 if (stream
->metadata_flag
) {
1669 ctf_trace
->metadata_sent
= 0;
1670 ctf_trace
->viewer_metadata_stream
= NULL
;
1673 viewer_stream_destroy(ctf_trace
, stream
);
1678 static void try_destroy_streams(struct relay_session
*session
)
1680 struct ctf_trace
*ctf_trace
;
1681 struct lttng_ht_iter iter
;
1685 cds_lfht_for_each_entry(session
->ctf_traces_ht
->ht
, &iter
.iter
, ctf_trace
,
1687 /* Attempt to destroy the ctf trace of that session. */
1688 ctf_trace_try_destroy(session
, ctf_trace
);
1693 * Delete and free a connection.
1695 * RCU read side lock MUST be acquired.
1698 void del_connection(struct lttng_ht
*relay_connections_ht
,
1699 struct lttng_ht_iter
*iter
, struct relay_command
*relay_connection
,
1700 struct lttng_ht
*sessions_ht
)
1703 struct relay_session
*session
;
1705 assert(relay_connections_ht
);
1707 assert(relay_connection
);
1708 assert(sessions_ht
);
1710 DBG("Cleaning connection of session ID %" PRIu64
,
1711 relay_connection
->session_id
);
1714 ret
= lttng_ht_del(relay_connections_ht
, iter
);
1717 session
= session_find_by_id(sessions_ht
, relay_connection
->session_id
);
1720 * Very important that this is done before destroying the session so we
1721 * can put back every viewer stream reference from the ctf_trace.
1723 destroy_viewer_streams_by_session(session
);
1724 try_destroy_streams(session
);
1725 session_viewer_try_destroy(sessions_ht
, session
);
1729 call_rcu(&relay_connection
->rcu_node
, deferred_free_connection
);
1733 * This thread does the actual work
1736 void *thread_worker(void *data
)
1740 struct relay_command
*relay_connection
;
1741 struct lttng_poll_event events
;
1742 struct lttng_ht
*relay_connections_ht
;
1743 struct lttng_ht_node_ulong
*node
;
1744 struct lttng_ht_iter iter
;
1745 struct lttng_viewer_cmd recv_hdr
;
1746 struct relay_local_data
*relay_ctx
= (struct relay_local_data
*) data
;
1747 struct lttng_ht
*sessions_ht
= relay_ctx
->sessions_ht
;
1749 DBG("[thread] Live viewer relay worker started");
1751 rcu_register_thread();
1753 health_register(health_relayd
, HEALTH_RELAYD_TYPE_LIVE_WORKER
);
1755 if (testpoint(relayd_thread_live_worker
)) {
1756 goto error_testpoint
;
1759 /* table of connections indexed on socket */
1760 relay_connections_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1761 if (!relay_connections_ht
) {
1762 goto relay_connections_ht_error
;
1765 ret
= create_thread_poll_set(&events
, 2);
1767 goto error_poll_create
;
1770 ret
= lttng_poll_add(&events
, live_relay_cmd_pipe
[0], LPOLLIN
| LPOLLRDHUP
);
1779 health_code_update();
1781 /* Infinite blocking call, waiting for transmission */
1782 DBG3("Relayd live viewer worker thread polling...");
1783 health_poll_entry();
1784 ret
= lttng_poll_wait(&events
, -1);
1788 * Restart interrupted system call.
1790 if (errno
== EINTR
) {
1799 * Process control. The control connection is prioritised so we don't
1800 * starve it with high throughput tracing data on the data
1803 for (i
= 0; i
< nb_fd
; i
++) {
1804 /* Fetch once the poll data */
1805 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
1806 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
1808 health_code_update();
1810 /* Thread quit pipe has been closed. Killing thread. */
1811 ret
= check_live_conn_pipe(pollfd
, revents
);
1817 /* Inspect the relay cmd pipe for new connection */
1818 if (pollfd
== live_relay_cmd_pipe
[0]) {
1819 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
1820 ERR("Relay live pipe error");
1822 } else if (revents
& LPOLLIN
) {
1823 DBG("Relay live viewer command received");
1824 ret
= add_connection(live_relay_cmd_pipe
[0],
1825 &events
, relay_connections_ht
);
1830 } else if (revents
) {
1832 lttng_ht_lookup(relay_connections_ht
,
1833 (void *)((unsigned long) pollfd
), &iter
);
1834 node
= lttng_ht_iter_get_node_ulong(&iter
);
1836 DBG2("Relay viewer sock %d not found", pollfd
);
1840 relay_connection
= caa_container_of(node
, struct relay_command
,
1843 if (revents
& (LPOLLERR
)) {
1844 cleanup_poll_connection(&events
, pollfd
);
1845 del_connection(relay_connections_ht
, &iter
,
1846 relay_connection
, relay_ctx
->sessions_ht
);
1847 } else if (revents
& (LPOLLHUP
| LPOLLRDHUP
)) {
1848 DBG("Viewer socket %d hung up", pollfd
);
1849 cleanup_poll_connection(&events
, pollfd
);
1850 del_connection(relay_connections_ht
, &iter
,
1851 relay_connection
, relay_ctx
->sessions_ht
);
1852 } else if (revents
& LPOLLIN
) {
1853 ret
= relay_connection
->sock
->ops
->recvmsg(
1854 relay_connection
->sock
, &recv_hdr
,
1855 sizeof(struct lttng_viewer_cmd
),
1857 /* connection closed */
1859 cleanup_poll_connection(&events
, pollfd
);
1860 del_connection(relay_connections_ht
, &iter
,
1861 relay_connection
, relay_ctx
->sessions_ht
);
1862 DBG("Viewer control connection closed with %d",
1865 if (relay_connection
->session
) {
1866 DBG2("Relay viewer worker receiving data for "
1867 "session: %" PRIu64
,
1868 relay_connection
->session
->id
);
1870 ret
= process_control(&recv_hdr
, relay_connection
,
1873 /* Clear the session on error. */
1874 cleanup_poll_connection(&events
, pollfd
);
1875 del_connection(relay_connections_ht
, &iter
,
1876 relay_connection
, relay_ctx
->sessions_ht
);
1877 DBG("Viewer connection closed with %d", pollfd
);
1888 lttng_poll_clean(&events
);
1890 /* empty the hash table and free the memory */
1892 cds_lfht_for_each_entry(relay_connections_ht
->ht
, &iter
.iter
, node
, node
) {
1893 health_code_update();
1895 node
= lttng_ht_iter_get_node_ulong(&iter
);
1900 relay_connection
= caa_container_of(node
, struct relay_command
,
1902 del_connection(relay_connections_ht
, &iter
, relay_connection
,
1903 relay_ctx
->sessions_ht
);
1907 lttng_ht_destroy(relay_connections_ht
);
1908 relay_connections_ht_error
:
1909 /* Close relay cmd pipes */
1910 utils_close_pipe(live_relay_cmd_pipe
);
1912 DBG("Viewer worker thread exited with error");
1914 DBG("Viewer worker thread cleanup complete");
1918 ERR("Health error occurred in %s", __func__
);
1920 health_unregister(health_relayd
);
1922 rcu_unregister_thread();
1927 * Create the relay command pipe to wake thread_manage_apps.
1928 * Closed in cleanup().
1930 static int create_relay_cmd_pipe(void)
1934 ret
= utils_create_pipe_cloexec(live_relay_cmd_pipe
);
1939 void live_stop_threads(void)
1946 ret
= pthread_join(live_listener_thread
, &status
);
1948 PERROR("pthread_join live listener");
1949 goto error
; /* join error, exit without cleanup */
1952 ret
= pthread_join(live_worker_thread
, &status
);
1954 PERROR("pthread_join live worker");
1955 goto error
; /* join error, exit without cleanup */
1958 ret
= pthread_join(live_dispatcher_thread
, &status
);
1960 PERROR("pthread_join live dispatcher");
1961 goto error
; /* join error, exit without cleanup */
1973 int live_start_threads(struct lttng_uri
*uri
,
1974 struct relay_local_data
*relay_ctx
)
1983 /* Check if daemon is UID = 0 */
1984 is_root
= !getuid();
1987 if (live_uri
->port
< 1024) {
1988 ERR("Need to be root to use ports < 1024");
1994 /* Setup the thread apps communication pipe. */
1995 if ((ret
= create_relay_cmd_pipe()) < 0) {
1999 /* Init relay command queue. */
2000 cds_wfq_init(&viewer_cmd_queue
.queue
);
2002 /* Set up max poll set size */
2003 lttng_poll_set_max_size();
2005 /* Setup the dispatcher thread */
2006 ret
= pthread_create(&live_dispatcher_thread
, NULL
,
2007 thread_dispatcher
, (void *) NULL
);
2009 PERROR("pthread_create viewer dispatcher");
2010 goto exit_dispatcher
;
2013 /* Setup the worker thread */
2014 ret
= pthread_create(&live_worker_thread
, NULL
,
2015 thread_worker
, relay_ctx
);
2017 PERROR("pthread_create viewer worker");
2021 /* Setup the listener thread */
2022 ret
= pthread_create(&live_listener_thread
, NULL
,
2023 thread_listener
, (void *) NULL
);
2025 PERROR("pthread_create viewer listener");
2033 ret
= pthread_join(live_listener_thread
, &status
);
2035 PERROR("pthread_join live listener");
2036 goto error
; /* join error, exit without cleanup */
2040 ret
= pthread_join(live_worker_thread
, &status
);
2042 PERROR("pthread_join live worker");
2043 goto error
; /* join error, exit without cleanup */
2047 ret
= pthread_join(live_dispatcher_thread
, &status
);
2049 PERROR("pthread_join live dispatcher");
2050 goto error
; /* join error, exit without cleanup */