2 * Copyright (C) 2012 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
4 * 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2 only,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <sys/mount.h>
32 #include <sys/resource.h>
33 #include <sys/socket.h>
35 #include <sys/types.h>
38 #include <urcu/futex.h>
39 #include <urcu/uatomic.h>
43 #include <lttng/lttng.h>
44 #include <common/common.h>
45 #include <common/compat/poll.h>
46 #include <common/compat/socket.h>
47 #include <common/compat/endian.h>
48 #include <common/compat/getenv.h>
49 #include <common/defaults.h>
50 #include <common/daemonize.h>
51 #include <common/futex.h>
52 #include <common/sessiond-comm/sessiond-comm.h>
53 #include <common/sessiond-comm/inet.h>
54 #include <common/sessiond-comm/relayd.h>
55 #include <common/uri.h>
56 #include <common/utils.h>
57 #include <common/config/session-config.h>
58 #include <urcu/rculist.h>
61 #include "ctf-trace.h"
64 #include "lttng-relayd.h"
66 #include "health-relayd.h"
67 #include "testpoint.h"
68 #include "viewer-stream.h"
71 #include "connection.h"
72 #include "tracefile-array.h"
73 #include "tcp_keep_alive.h"
75 static const char *help_msg
=
76 #ifdef LTTNG_EMBED_HELP
77 #include <lttng-relayd.8.h>
83 /* command line options */
84 char *opt_output_path
;
85 static int opt_daemon
, opt_background
;
88 * We need to wait for listener and live listener threads, as well as
89 * health check thread, before being ready to signal readiness.
91 #define NR_LTTNG_RELAY_READY 3
92 static int lttng_relay_ready
= NR_LTTNG_RELAY_READY
;
94 /* Size of receive buffer. */
95 #define RECV_DATA_BUFFER_SIZE 65536
97 static int recv_child_signal
; /* Set to 1 when a SIGUSR1 signal is received. */
98 static pid_t child_ppid
; /* Internal parent PID use with daemonize. */
100 static struct lttng_uri
*control_uri
;
101 static struct lttng_uri
*data_uri
;
102 static struct lttng_uri
*live_uri
;
104 const char *progname
;
106 const char *tracing_group_name
= DEFAULT_TRACING_GROUP
;
107 static int tracing_group_name_override
;
109 const char * const config_section_name
= "relayd";
112 * Quit pipe for all threads. This permits a single cancellation point
113 * for all threads when receiving an event on the pipe.
115 int thread_quit_pipe
[2] = { -1, -1 };
118 * This pipe is used to inform the worker thread that a command is queued and
119 * ready to be processed.
121 static int relay_conn_pipe
[2] = { -1, -1 };
123 /* Shared between threads */
124 static int dispatch_thread_exit
;
126 static pthread_t listener_thread
;
127 static pthread_t dispatcher_thread
;
128 static pthread_t worker_thread
;
129 static pthread_t health_thread
;
132 * last_relay_stream_id_lock protects last_relay_stream_id increment
133 * atomicity on 32-bit architectures.
135 static pthread_mutex_t last_relay_stream_id_lock
= PTHREAD_MUTEX_INITIALIZER
;
136 static uint64_t last_relay_stream_id
;
139 * Relay command queue.
141 * The relay_thread_listener and relay_thread_dispatcher communicate with this
144 static struct relay_conn_queue relay_conn_queue
;
146 /* buffer allocated at startup, used to store the trace data */
147 static char *data_buffer
;
148 static unsigned int data_buffer_size
;
150 /* Global relay stream hash table. */
151 struct lttng_ht
*relay_streams_ht
;
153 /* Global relay viewer stream hash table. */
154 struct lttng_ht
*viewer_streams_ht
;
156 /* Global relay sessions hash table. */
157 struct lttng_ht
*sessions_ht
;
159 /* Relayd health monitoring */
160 struct health_app
*health_relayd
;
162 static struct option long_options
[] = {
163 { "control-port", 1, 0, 'C', },
164 { "data-port", 1, 0, 'D', },
165 { "live-port", 1, 0, 'L', },
166 { "daemonize", 0, 0, 'd', },
167 { "background", 0, 0, 'b', },
168 { "group", 1, 0, 'g', },
169 { "help", 0, 0, 'h', },
170 { "output", 1, 0, 'o', },
171 { "verbose", 0, 0, 'v', },
172 { "config", 1, 0, 'f' },
173 { "version", 0, 0, 'V' },
177 static const char *config_ignore_options
[] = { "help", "config", "version" };
180 * Take an option from the getopt output and set it in the right variable to be
183 * Return 0 on success else a negative value.
185 static int set_option(int opt
, const char *arg
, const char *optname
)
191 fprintf(stderr
, "option %s", optname
);
193 fprintf(stderr
, " with arg %s\n", arg
);
197 if (lttng_is_setuid_setgid()) {
198 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
199 "-C, --control-port");
201 ret
= uri_parse(arg
, &control_uri
);
203 ERR("Invalid control URI specified");
206 if (control_uri
->port
== 0) {
207 control_uri
->port
= DEFAULT_NETWORK_CONTROL_PORT
;
212 if (lttng_is_setuid_setgid()) {
213 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
216 ret
= uri_parse(arg
, &data_uri
);
218 ERR("Invalid data URI specified");
221 if (data_uri
->port
== 0) {
222 data_uri
->port
= DEFAULT_NETWORK_DATA_PORT
;
227 if (lttng_is_setuid_setgid()) {
228 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
231 ret
= uri_parse(arg
, &live_uri
);
233 ERR("Invalid live URI specified");
236 if (live_uri
->port
== 0) {
237 live_uri
->port
= DEFAULT_NETWORK_VIEWER_PORT
;
248 if (lttng_is_setuid_setgid()) {
249 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
252 tracing_group_name
= strdup(arg
);
253 if (tracing_group_name
== NULL
) {
258 tracing_group_name_override
= 1;
262 ret
= utils_show_help(8, "lttng-relayd", help_msg
);
264 ERR("Cannot show --help for `lttng-relayd`");
269 fprintf(stdout
, "%s\n", VERSION
);
272 if (lttng_is_setuid_setgid()) {
273 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
276 ret
= asprintf(&opt_output_path
, "%s", arg
);
279 PERROR("asprintf opt_output_path");
285 /* Verbose level can increase using multiple -v */
287 lttng_opt_verbose
= config_parse_value(arg
);
289 /* Only 3 level of verbosity (-vvv). */
290 if (lttng_opt_verbose
< 3) {
291 lttng_opt_verbose
+= 1;
296 /* Unknown option or other error.
297 * Error is printed by getopt, just return */
310 * config_entry_handler_cb used to handle options read from a config file.
311 * See config_entry_handler_cb comment in common/config/session-config.h for the
312 * return value conventions.
314 static int config_entry_handler(const struct config_entry
*entry
, void *unused
)
318 if (!entry
|| !entry
->name
|| !entry
->value
) {
323 /* Check if the option is to be ignored */
324 for (i
= 0; i
< sizeof(config_ignore_options
) / sizeof(char *); i
++) {
325 if (!strcmp(entry
->name
, config_ignore_options
[i
])) {
330 for (i
= 0; i
< (sizeof(long_options
) / sizeof(struct option
)) - 1; i
++) {
331 /* Ignore if entry name is not fully matched. */
332 if (strcmp(entry
->name
, long_options
[i
].name
)) {
337 * If the option takes no argument on the command line,
338 * we have to check if the value is "true". We support
339 * non-zero numeric values, true, on and yes.
341 if (!long_options
[i
].has_arg
) {
342 ret
= config_parse_value(entry
->value
);
345 WARN("Invalid configuration value \"%s\" for option %s",
346 entry
->value
, entry
->name
);
348 /* False, skip boolean config option. */
353 ret
= set_option(long_options
[i
].val
, entry
->value
, entry
->name
);
357 WARN("Unrecognized option \"%s\" in daemon configuration file.",
364 static int set_options(int argc
, char **argv
)
366 int c
, ret
= 0, option_index
= 0, retval
= 0;
367 int orig_optopt
= optopt
, orig_optind
= optind
;
368 char *default_address
, *optstring
;
369 const char *config_path
= NULL
;
371 optstring
= utils_generate_optstring(long_options
,
372 sizeof(long_options
) / sizeof(struct option
));
378 /* Check for the --config option */
380 while ((c
= getopt_long(argc
, argv
, optstring
, long_options
,
381 &option_index
)) != -1) {
385 } else if (c
!= 'f') {
389 if (lttng_is_setuid_setgid()) {
390 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
393 config_path
= utils_expand_path(optarg
);
395 ERR("Failed to resolve path: %s", optarg
);
400 ret
= config_get_section_entries(config_path
, config_section_name
,
401 config_entry_handler
, NULL
);
404 ERR("Invalid configuration option at line %i", ret
);
410 /* Reset getopt's global state */
411 optopt
= orig_optopt
;
412 optind
= orig_optind
;
414 c
= getopt_long(argc
, argv
, optstring
, long_options
, &option_index
);
419 ret
= set_option(c
, optarg
, long_options
[option_index
].name
);
426 /* assign default values */
427 if (control_uri
== NULL
) {
428 ret
= asprintf(&default_address
,
429 "tcp://" DEFAULT_NETWORK_CONTROL_BIND_ADDRESS
":%d",
430 DEFAULT_NETWORK_CONTROL_PORT
);
432 PERROR("asprintf default data address");
437 ret
= uri_parse(default_address
, &control_uri
);
438 free(default_address
);
440 ERR("Invalid control URI specified");
445 if (data_uri
== NULL
) {
446 ret
= asprintf(&default_address
,
447 "tcp://" DEFAULT_NETWORK_DATA_BIND_ADDRESS
":%d",
448 DEFAULT_NETWORK_DATA_PORT
);
450 PERROR("asprintf default data address");
455 ret
= uri_parse(default_address
, &data_uri
);
456 free(default_address
);
458 ERR("Invalid data URI specified");
463 if (live_uri
== NULL
) {
464 ret
= asprintf(&default_address
,
465 "tcp://" DEFAULT_NETWORK_VIEWER_BIND_ADDRESS
":%d",
466 DEFAULT_NETWORK_VIEWER_PORT
);
468 PERROR("asprintf default viewer control address");
473 ret
= uri_parse(default_address
, &live_uri
);
474 free(default_address
);
476 ERR("Invalid viewer control URI specified");
487 static void print_global_objects(void)
489 rcu_register_thread();
491 print_viewer_streams();
492 print_relay_streams();
495 rcu_unregister_thread();
501 static void relayd_cleanup(void)
503 print_global_objects();
507 if (viewer_streams_ht
)
508 lttng_ht_destroy(viewer_streams_ht
);
509 if (relay_streams_ht
)
510 lttng_ht_destroy(relay_streams_ht
);
512 lttng_ht_destroy(sessions_ht
);
514 /* free the dynamically allocated opt_output_path */
515 free(opt_output_path
);
517 /* Close thread quit pipes */
518 utils_close_pipe(thread_quit_pipe
);
520 uri_free(control_uri
);
522 /* Live URI is freed in the live thread. */
524 if (tracing_group_name_override
) {
525 free((void *) tracing_group_name
);
530 * Write to writable pipe used to notify a thread.
532 static int notify_thread_pipe(int wpipe
)
536 ret
= lttng_write(wpipe
, "!", 1);
538 PERROR("write poll pipe");
546 static int notify_health_quit_pipe(int *pipe
)
550 ret
= lttng_write(pipe
[1], "4", 1);
552 PERROR("write relay health quit");
561 * Stop all relayd and relayd-live threads.
563 int lttng_relay_stop_threads(void)
567 /* Stopping all threads */
568 DBG("Terminating all threads");
569 if (notify_thread_pipe(thread_quit_pipe
[1])) {
570 ERR("write error on thread quit pipe");
574 if (notify_health_quit_pipe(health_quit_pipe
)) {
575 ERR("write error on health quit pipe");
578 /* Dispatch thread */
579 CMM_STORE_SHARED(dispatch_thread_exit
, 1);
580 futex_nto1_wake(&relay_conn_queue
.futex
);
582 if (relayd_live_stop()) {
583 ERR("Error stopping live threads");
590 * Signal handler for the daemon
592 * Simply stop all worker threads, leaving main() return gracefully after
593 * joining all threads and calling cleanup().
595 static void sighandler(int sig
)
599 DBG("SIGINT caught");
600 if (lttng_relay_stop_threads()) {
601 ERR("Error stopping threads");
605 DBG("SIGTERM caught");
606 if (lttng_relay_stop_threads()) {
607 ERR("Error stopping threads");
611 CMM_STORE_SHARED(recv_child_signal
, 1);
619 * Setup signal handler for :
620 * SIGINT, SIGTERM, SIGPIPE
622 static int set_signal_handler(void)
628 if ((ret
= sigemptyset(&sigset
)) < 0) {
629 PERROR("sigemptyset");
636 sa
.sa_handler
= sighandler
;
637 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
642 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
647 if ((ret
= sigaction(SIGUSR1
, &sa
, NULL
)) < 0) {
652 sa
.sa_handler
= SIG_IGN
;
653 if ((ret
= sigaction(SIGPIPE
, &sa
, NULL
)) < 0) {
658 DBG("Signal handler set for SIGTERM, SIGUSR1, SIGPIPE and SIGINT");
663 void lttng_relay_notify_ready(void)
665 /* Notify the parent of the fork() process that we are ready. */
666 if (opt_daemon
|| opt_background
) {
667 if (uatomic_sub_return(<tng_relay_ready
, 1) == 0) {
668 kill(child_ppid
, SIGUSR1
);
674 * Init thread quit pipe.
676 * Return -1 on error or 0 if all pipes are created.
678 static int init_thread_quit_pipe(void)
682 ret
= utils_create_pipe_cloexec(thread_quit_pipe
);
688 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
690 static int create_thread_poll_set(struct lttng_poll_event
*events
, int size
)
694 if (events
== NULL
|| size
== 0) {
699 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
705 ret
= lttng_poll_add(events
, thread_quit_pipe
[0], LPOLLIN
| LPOLLERR
);
717 * Check if the thread quit pipe was triggered.
719 * Return 1 if it was triggered else 0;
721 static int check_thread_quit_pipe(int fd
, uint32_t events
)
723 if (fd
== thread_quit_pipe
[0] && (events
& LPOLLIN
)) {
731 * Create and init socket from uri.
733 static struct lttcomm_sock
*relay_socket_create(struct lttng_uri
*uri
)
736 struct lttcomm_sock
*sock
= NULL
;
738 sock
= lttcomm_alloc_sock_from_uri(uri
);
740 ERR("Allocating socket");
744 ret
= lttcomm_create_sock(sock
);
748 DBG("Listening on sock %d", sock
->fd
);
750 ret
= sock
->ops
->bind(sock
);
752 PERROR("Failed to bind socket");
756 ret
= sock
->ops
->listen(sock
, -1);
766 lttcomm_destroy_sock(sock
);
772 * This thread manages the listening for new connections on the network
774 static void *relay_thread_listener(void *data
)
776 int i
, ret
, pollfd
, err
= -1;
777 uint32_t revents
, nb_fd
;
778 struct lttng_poll_event events
;
779 struct lttcomm_sock
*control_sock
, *data_sock
;
781 DBG("[thread] Relay listener started");
783 health_register(health_relayd
, HEALTH_RELAYD_TYPE_LISTENER
);
785 health_code_update();
787 control_sock
= relay_socket_create(control_uri
);
789 goto error_sock_control
;
792 data_sock
= relay_socket_create(data_uri
);
794 goto error_sock_relay
;
798 * Pass 3 as size here for the thread quit pipe, control and
801 ret
= create_thread_poll_set(&events
, 3);
803 goto error_create_poll
;
806 /* Add the control socket */
807 ret
= lttng_poll_add(&events
, control_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
812 /* Add the data socket */
813 ret
= lttng_poll_add(&events
, data_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
818 lttng_relay_notify_ready();
820 if (testpoint(relayd_thread_listener
)) {
821 goto error_testpoint
;
825 health_code_update();
827 DBG("Listener accepting connections");
831 ret
= lttng_poll_wait(&events
, -1);
835 * Restart interrupted system call.
837 if (errno
== EINTR
) {
845 DBG("Relay new connection received");
846 for (i
= 0; i
< nb_fd
; i
++) {
847 health_code_update();
849 /* Fetch once the poll data */
850 revents
= LTTNG_POLL_GETEV(&events
, i
);
851 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
855 * No activity for this FD (poll
861 /* Thread quit pipe has been closed. Killing thread. */
862 ret
= check_thread_quit_pipe(pollfd
, revents
);
868 if (revents
& LPOLLIN
) {
870 * A new connection is requested, therefore a
871 * sessiond/consumerd connection is allocated in
872 * this thread, enqueued to a global queue and
873 * dequeued (and freed) in the worker thread.
876 struct relay_connection
*new_conn
;
877 struct lttcomm_sock
*newsock
;
878 enum connection_type type
;
880 if (pollfd
== data_sock
->fd
) {
882 newsock
= data_sock
->ops
->accept(data_sock
);
883 DBG("Relay data connection accepted, socket %d",
886 assert(pollfd
== control_sock
->fd
);
887 type
= RELAY_CONTROL
;
888 newsock
= control_sock
->ops
->accept(control_sock
);
889 DBG("Relay control connection accepted, socket %d",
893 PERROR("accepting sock");
897 ret
= setsockopt(newsock
->fd
, SOL_SOCKET
, SO_REUSEADDR
, &val
,
900 PERROR("setsockopt inet");
901 lttcomm_destroy_sock(newsock
);
905 ret
= socket_apply_keep_alive_config(newsock
->fd
);
907 ERR("Failed to apply TCP keep-alive configuration on socket (%i)",
909 lttcomm_destroy_sock(newsock
);
913 new_conn
= connection_create(newsock
, type
);
915 lttcomm_destroy_sock(newsock
);
919 /* Enqueue request for the dispatcher thread. */
920 cds_wfcq_enqueue(&relay_conn_queue
.head
, &relay_conn_queue
.tail
,
924 * Wake the dispatch queue futex.
925 * Implicit memory barrier with the
926 * exchange in cds_wfcq_enqueue.
928 futex_nto1_wake(&relay_conn_queue
.futex
);
929 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
930 ERR("socket poll error");
933 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
943 lttng_poll_clean(&events
);
945 if (data_sock
->fd
>= 0) {
946 ret
= data_sock
->ops
->close(data_sock
);
951 lttcomm_destroy_sock(data_sock
);
953 if (control_sock
->fd
>= 0) {
954 ret
= control_sock
->ops
->close(control_sock
);
959 lttcomm_destroy_sock(control_sock
);
963 ERR("Health error occurred in %s", __func__
);
965 health_unregister(health_relayd
);
966 DBG("Relay listener thread cleanup complete");
967 lttng_relay_stop_threads();
972 * This thread manages the dispatching of the requests to worker threads
974 static void *relay_thread_dispatcher(void *data
)
978 struct cds_wfcq_node
*node
;
979 struct relay_connection
*new_conn
= NULL
;
981 DBG("[thread] Relay dispatcher started");
983 health_register(health_relayd
, HEALTH_RELAYD_TYPE_DISPATCHER
);
985 if (testpoint(relayd_thread_dispatcher
)) {
986 goto error_testpoint
;
989 health_code_update();
992 health_code_update();
994 /* Atomically prepare the queue futex */
995 futex_nto1_prepare(&relay_conn_queue
.futex
);
997 if (CMM_LOAD_SHARED(dispatch_thread_exit
)) {
1002 health_code_update();
1004 /* Dequeue commands */
1005 node
= cds_wfcq_dequeue_blocking(&relay_conn_queue
.head
,
1006 &relay_conn_queue
.tail
);
1008 DBG("Woken up but nothing in the relay command queue");
1009 /* Continue thread execution */
1012 new_conn
= caa_container_of(node
, struct relay_connection
, qnode
);
1014 DBG("Dispatching request waiting on sock %d", new_conn
->sock
->fd
);
1017 * Inform worker thread of the new request. This
1018 * call is blocking so we can be assured that
1019 * the data will be read at some point in time
1020 * or wait to the end of the world :)
1022 ret
= lttng_write(relay_conn_pipe
[1], &new_conn
, sizeof(new_conn
));
1024 PERROR("write connection pipe");
1025 connection_put(new_conn
);
1028 } while (node
!= NULL
);
1030 /* Futex wait on queue. Blocking call on futex() */
1031 health_poll_entry();
1032 futex_nto1_wait(&relay_conn_queue
.futex
);
1036 /* Normal exit, no error */
1043 ERR("Health error occurred in %s", __func__
);
1045 health_unregister(health_relayd
);
1046 DBG("Dispatch thread dying");
1047 lttng_relay_stop_threads();
1052 * Set index data from the control port to a given index object.
1054 static int set_index_control_data(struct relay_index
*index
,
1055 struct lttcomm_relayd_index
*data
,
1056 struct relay_connection
*conn
)
1058 struct ctf_packet_index index_data
;
1061 * The index on disk is encoded in big endian, so we don't need
1062 * to convert the data received on the network. The data_offset
1063 * value is NEVER modified here and is updated by the data
1066 index_data
.packet_size
= data
->packet_size
;
1067 index_data
.content_size
= data
->content_size
;
1068 index_data
.timestamp_begin
= data
->timestamp_begin
;
1069 index_data
.timestamp_end
= data
->timestamp_end
;
1070 index_data
.events_discarded
= data
->events_discarded
;
1071 index_data
.stream_id
= data
->stream_id
;
1073 if (conn
->minor
>= 8) {
1074 index
->index_data
.stream_instance_id
= data
->stream_instance_id
;
1075 index
->index_data
.packet_seq_num
= data
->packet_seq_num
;
1078 return relay_index_set_data(index
, &index_data
);
1082 * Handle the RELAYD_CREATE_SESSION command.
1084 * On success, send back the session id or else return a negative value.
1086 static int relay_create_session(struct lttcomm_relayd_hdr
*recv_hdr
,
1087 struct relay_connection
*conn
)
1089 int ret
= 0, send_ret
;
1090 struct relay_session
*session
;
1091 struct lttcomm_relayd_status_session reply
;
1092 char session_name
[LTTNG_NAME_MAX
];
1093 char hostname
[LTTNG_HOST_NAME_MAX
];
1094 uint32_t live_timer
= 0;
1095 bool snapshot
= false;
1097 memset(session_name
, 0, LTTNG_NAME_MAX
);
1098 memset(hostname
, 0, LTTNG_HOST_NAME_MAX
);
1100 memset(&reply
, 0, sizeof(reply
));
1102 switch (conn
->minor
) {
1107 case 4: /* LTTng sessiond 2.4 */
1109 ret
= cmd_create_session_2_4(conn
, session_name
,
1110 hostname
, &live_timer
, &snapshot
);
1116 session
= session_create(session_name
, hostname
, live_timer
,
1117 snapshot
, conn
->major
, conn
->minor
);
1122 assert(!conn
->session
);
1123 conn
->session
= session
;
1124 DBG("Created session %" PRIu64
, session
->id
);
1126 reply
.session_id
= htobe64(session
->id
);
1130 reply
.ret_code
= htobe32(LTTNG_ERR_FATAL
);
1132 reply
.ret_code
= htobe32(LTTNG_OK
);
1135 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1137 ERR("Relayd sending session id");
1145 * When we have received all the streams and the metadata for a channel,
1146 * we make them visible to the viewer threads.
1148 static void publish_connection_local_streams(struct relay_connection
*conn
)
1150 struct relay_stream
*stream
;
1151 struct relay_session
*session
= conn
->session
;
1154 * We publish all streams belonging to a session atomically wrt
1157 pthread_mutex_lock(&session
->lock
);
1159 cds_list_for_each_entry_rcu(stream
, &session
->recv_list
,
1161 stream_publish(stream
);
1166 * Inform the viewer that there are new streams in the session.
1168 if (session
->viewer_attached
) {
1169 uatomic_set(&session
->new_streams
, 1);
1171 pthread_mutex_unlock(&session
->lock
);
1175 * relay_add_stream: allocate a new stream for a session
1177 static int relay_add_stream(struct lttcomm_relayd_hdr
*recv_hdr
,
1178 struct relay_connection
*conn
)
1182 struct relay_session
*session
= conn
->session
;
1183 struct relay_stream
*stream
= NULL
;
1184 struct lttcomm_relayd_status_stream reply
;
1185 struct ctf_trace
*trace
= NULL
;
1186 uint64_t stream_handle
= -1ULL;
1187 char *path_name
= NULL
, *channel_name
= NULL
;
1188 uint64_t tracefile_size
= 0, tracefile_count
= 0;
1190 if (!session
|| conn
->version_check_done
== 0) {
1191 ERR("Trying to add a stream before version check");
1193 goto end_no_session
;
1196 switch (session
->minor
) {
1197 case 1: /* LTTng sessiond 2.1. Allocates path_name and channel_name. */
1198 ret
= cmd_recv_stream_2_1(conn
, &path_name
,
1201 case 2: /* LTTng sessiond 2.2. Allocates path_name and channel_name. */
1203 ret
= cmd_recv_stream_2_2(conn
, &path_name
,
1204 &channel_name
, &tracefile_size
, &tracefile_count
);
1211 trace
= ctf_trace_get_by_path_or_create(session
, path_name
);
1215 /* This stream here has one reference on the trace. */
1217 pthread_mutex_lock(&last_relay_stream_id_lock
);
1218 stream_handle
= ++last_relay_stream_id
;
1219 pthread_mutex_unlock(&last_relay_stream_id_lock
);
1221 /* We pass ownership of path_name and channel_name. */
1222 stream
= stream_create(trace
, stream_handle
, path_name
,
1223 channel_name
, tracefile_size
, tracefile_count
);
1225 channel_name
= NULL
;
1228 * Streams are the owners of their trace. Reference to trace is
1229 * kept within stream_create().
1231 ctf_trace_put(trace
);
1234 memset(&reply
, 0, sizeof(reply
));
1235 reply
.handle
= htobe64(stream_handle
);
1237 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1239 reply
.ret_code
= htobe32(LTTNG_OK
);
1242 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1243 sizeof(struct lttcomm_relayd_status_stream
), 0);
1245 ERR("Relay sending stream id");
1246 ret
= (int) send_ret
;
1256 * relay_close_stream: close a specific stream
1258 static int relay_close_stream(struct lttcomm_relayd_hdr
*recv_hdr
,
1259 struct relay_connection
*conn
)
1262 struct relay_session
*session
= conn
->session
;
1263 struct lttcomm_relayd_close_stream stream_info
;
1264 struct lttcomm_relayd_generic_reply reply
;
1265 struct relay_stream
*stream
;
1267 DBG("Close stream received");
1269 if (!session
|| conn
->version_check_done
== 0) {
1270 ERR("Trying to close a stream before version check");
1272 goto end_no_session
;
1275 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &stream_info
,
1276 sizeof(struct lttcomm_relayd_close_stream
), 0);
1277 if (ret
< sizeof(struct lttcomm_relayd_close_stream
)) {
1279 /* Orderly shutdown. Not necessary to print an error. */
1280 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1282 ERR("Relay didn't receive valid add_stream struct size : %d", ret
);
1285 goto end_no_session
;
1288 stream
= stream_get_by_id(be64toh(stream_info
.stream_id
));
1295 * Set last_net_seq_num before the close flag. Required by data
1298 pthread_mutex_lock(&stream
->lock
);
1299 stream
->last_net_seq_num
= be64toh(stream_info
.last_net_seq_num
);
1300 pthread_mutex_unlock(&stream
->lock
);
1303 * This is one of the conditions which may trigger a stream close
1304 * with the others being:
1305 * 1) A close command is received for a stream
1306 * 2) The control connection owning the stream is closed
1307 * 3) We have received all of the stream's data _after_ a close
1310 try_stream_close(stream
);
1311 if (stream
->is_metadata
) {
1312 struct relay_viewer_stream
*vstream
;
1314 vstream
= viewer_stream_get_by_id(stream
->stream_handle
);
1316 if (vstream
->metadata_sent
== stream
->metadata_received
) {
1318 * Since all the metadata has been sent to the
1319 * viewer and that we have a request to close
1320 * its stream, we can safely teardown the
1321 * corresponding metadata viewer stream.
1323 viewer_stream_put(vstream
);
1325 /* Put local reference. */
1326 viewer_stream_put(vstream
);
1332 memset(&reply
, 0, sizeof(reply
));
1334 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1336 reply
.ret_code
= htobe32(LTTNG_OK
);
1338 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1339 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1341 ERR("Relay sending stream id");
1350 * relay_reset_metadata: reset a metadata stream
1353 int relay_reset_metadata(struct lttcomm_relayd_hdr
*recv_hdr
,
1354 struct relay_connection
*conn
)
1357 struct relay_session
*session
= conn
->session
;
1358 struct lttcomm_relayd_reset_metadata stream_info
;
1359 struct lttcomm_relayd_generic_reply reply
;
1360 struct relay_stream
*stream
;
1362 DBG("Reset metadata received");
1364 if (!session
|| conn
->version_check_done
== 0) {
1365 ERR("Trying to reset a metadata stream before version check");
1367 goto end_no_session
;
1370 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &stream_info
,
1371 sizeof(struct lttcomm_relayd_reset_metadata
), 0);
1372 if (ret
< sizeof(struct lttcomm_relayd_reset_metadata
)) {
1374 /* Orderly shutdown. Not necessary to print an error. */
1375 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1377 ERR("Relay didn't receive valid reset_metadata struct "
1381 goto end_no_session
;
1383 DBG("Update metadata to version %" PRIu64
, be64toh(stream_info
.version
));
1385 /* Unsupported for live sessions for now. */
1386 if (session
->live_timer
!= 0) {
1391 stream
= stream_get_by_id(be64toh(stream_info
.stream_id
));
1396 pthread_mutex_lock(&stream
->lock
);
1397 if (!stream
->is_metadata
) {
1402 ret
= utils_rotate_stream_file(stream
->path_name
, stream
->channel_name
,
1403 0, 0, -1, -1, stream
->stream_fd
->fd
, NULL
,
1404 &stream
->stream_fd
->fd
);
1406 ERR("Failed to rotate metadata file %s of channel %s",
1407 stream
->path_name
, stream
->channel_name
);
1412 pthread_mutex_unlock(&stream
->lock
);
1416 memset(&reply
, 0, sizeof(reply
));
1418 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1420 reply
.ret_code
= htobe32(LTTNG_OK
);
1422 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1423 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1425 ERR("Relay sending reset metadata reply");
1434 * relay_unknown_command: send -1 if received unknown command
1436 static void relay_unknown_command(struct relay_connection
*conn
)
1438 struct lttcomm_relayd_generic_reply reply
;
1441 memset(&reply
, 0, sizeof(reply
));
1442 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1443 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1444 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1446 ERR("Relay sending unknown command");
1451 * relay_start: send an acknowledgment to the client to tell if we are
1452 * ready to receive data. We are ready if a session is established.
1454 static int relay_start(struct lttcomm_relayd_hdr
*recv_hdr
,
1455 struct relay_connection
*conn
)
1457 int ret
= htobe32(LTTNG_OK
);
1458 struct lttcomm_relayd_generic_reply reply
;
1459 struct relay_session
*session
= conn
->session
;
1462 DBG("Trying to start the streaming without a session established");
1463 ret
= htobe32(LTTNG_ERR_UNK
);
1466 memset(&reply
, 0, sizeof(reply
));
1467 reply
.ret_code
= ret
;
1468 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1469 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1471 ERR("Relay sending start ack");
1478 * Append padding to the file pointed by the file descriptor fd.
1480 static int write_padding_to_file(int fd
, uint32_t size
)
1489 zeros
= zmalloc(size
);
1490 if (zeros
== NULL
) {
1491 PERROR("zmalloc zeros for padding");
1496 ret
= lttng_write(fd
, zeros
, size
);
1498 PERROR("write padding to file");
1508 * relay_recv_metadata: receive the metadata for the session.
1510 static int relay_recv_metadata(struct lttcomm_relayd_hdr
*recv_hdr
,
1511 struct relay_connection
*conn
)
1515 struct relay_session
*session
= conn
->session
;
1516 struct lttcomm_relayd_metadata_payload
*metadata_struct
;
1517 struct relay_stream
*metadata_stream
;
1518 uint64_t data_size
, payload_size
;
1521 ERR("Metadata sent before version check");
1526 data_size
= payload_size
= be64toh(recv_hdr
->data_size
);
1527 if (data_size
< sizeof(struct lttcomm_relayd_metadata_payload
)) {
1528 ERR("Incorrect data size");
1532 payload_size
-= sizeof(struct lttcomm_relayd_metadata_payload
);
1534 if (data_buffer_size
< data_size
) {
1535 /* In case the realloc fails, we can free the memory */
1538 tmp_data_ptr
= realloc(data_buffer
, data_size
);
1539 if (!tmp_data_ptr
) {
1540 ERR("Allocating data buffer");
1545 data_buffer
= tmp_data_ptr
;
1546 data_buffer_size
= data_size
;
1548 memset(data_buffer
, 0, data_size
);
1549 DBG2("Relay receiving metadata, waiting for %" PRIu64
" bytes", data_size
);
1550 size_ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, data_buffer
, data_size
, 0);
1551 if (size_ret
< 0 || size_ret
!= data_size
) {
1552 if (size_ret
== 0) {
1553 /* Orderly shutdown. Not necessary to print an error. */
1554 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1556 ERR("Relay didn't receive the whole metadata");
1561 metadata_struct
= (struct lttcomm_relayd_metadata_payload
*) data_buffer
;
1563 metadata_stream
= stream_get_by_id(be64toh(metadata_struct
->stream_id
));
1564 if (!metadata_stream
) {
1569 pthread_mutex_lock(&metadata_stream
->lock
);
1571 size_ret
= lttng_write(metadata_stream
->stream_fd
->fd
, metadata_struct
->payload
,
1573 if (size_ret
< payload_size
) {
1574 ERR("Relay error writing metadata on file");
1579 size_ret
= write_padding_to_file(metadata_stream
->stream_fd
->fd
,
1580 be32toh(metadata_struct
->padding_size
));
1585 metadata_stream
->metadata_received
+=
1586 payload_size
+ be32toh(metadata_struct
->padding_size
);
1587 DBG2("Relay metadata written. Updated metadata_received %" PRIu64
,
1588 metadata_stream
->metadata_received
);
1591 pthread_mutex_unlock(&metadata_stream
->lock
);
1592 stream_put(metadata_stream
);
1598 * relay_send_version: send relayd version number
1600 static int relay_send_version(struct lttcomm_relayd_hdr
*recv_hdr
,
1601 struct relay_connection
*conn
)
1604 struct lttcomm_relayd_version reply
, msg
;
1605 bool compatible
= true;
1607 conn
->version_check_done
= 1;
1609 /* Get version from the other side. */
1610 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1611 if (ret
< 0 || ret
!= sizeof(msg
)) {
1613 /* Orderly shutdown. Not necessary to print an error. */
1614 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1616 ERR("Relay failed to receive the version values.");
1622 memset(&reply
, 0, sizeof(reply
));
1623 reply
.major
= RELAYD_VERSION_COMM_MAJOR
;
1624 reply
.minor
= RELAYD_VERSION_COMM_MINOR
;
1626 /* Major versions must be the same */
1627 if (reply
.major
!= be32toh(msg
.major
)) {
1628 DBG("Incompatible major versions (%u vs %u), deleting session",
1629 reply
.major
, be32toh(msg
.major
));
1633 conn
->major
= reply
.major
;
1634 /* We adapt to the lowest compatible version */
1635 if (reply
.minor
<= be32toh(msg
.minor
)) {
1636 conn
->minor
= reply
.minor
;
1638 conn
->minor
= be32toh(msg
.minor
);
1641 reply
.major
= htobe32(reply
.major
);
1642 reply
.minor
= htobe32(reply
.minor
);
1643 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1644 sizeof(struct lttcomm_relayd_version
), 0);
1646 ERR("Relay sending version");
1654 DBG("Version check done using protocol %u.%u", conn
->major
,
1662 * Check for data pending for a given stream id from the session daemon.
1664 static int relay_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1665 struct relay_connection
*conn
)
1667 struct relay_session
*session
= conn
->session
;
1668 struct lttcomm_relayd_data_pending msg
;
1669 struct lttcomm_relayd_generic_reply reply
;
1670 struct relay_stream
*stream
;
1672 uint64_t last_net_seq_num
, stream_id
;
1674 DBG("Data pending command received");
1676 if (!session
|| conn
->version_check_done
== 0) {
1677 ERR("Trying to check for data before version check");
1679 goto end_no_session
;
1682 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1683 if (ret
< sizeof(msg
)) {
1685 /* Orderly shutdown. Not necessary to print an error. */
1686 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1688 ERR("Relay didn't receive valid data_pending struct size : %d",
1692 goto end_no_session
;
1695 stream_id
= be64toh(msg
.stream_id
);
1696 last_net_seq_num
= be64toh(msg
.last_net_seq_num
);
1698 stream
= stream_get_by_id(stream_id
);
1699 if (stream
== NULL
) {
1704 pthread_mutex_lock(&stream
->lock
);
1706 DBG("Data pending for stream id %" PRIu64
" prev_seq %" PRIu64
1707 " and last_seq %" PRIu64
, stream_id
, stream
->prev_seq
,
1710 /* Avoid wrapping issue */
1711 if (((int64_t) (stream
->prev_seq
- last_net_seq_num
)) >= 0) {
1712 /* Data has in fact been written and is NOT pending */
1715 /* Data still being streamed thus pending */
1719 stream
->data_pending_check_done
= true;
1720 pthread_mutex_unlock(&stream
->lock
);
1725 memset(&reply
, 0, sizeof(reply
));
1726 reply
.ret_code
= htobe32(ret
);
1727 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1729 ERR("Relay data pending ret code failed");
1737 * Wait for the control socket to reach a quiescent state.
1739 * Note that for now, when receiving this command from the session
1740 * daemon, this means that every subsequent commands or data received on
1741 * the control socket has been handled. So, this is why we simply return
1744 static int relay_quiescent_control(struct lttcomm_relayd_hdr
*recv_hdr
,
1745 struct relay_connection
*conn
)
1749 struct relay_stream
*stream
;
1750 struct lttcomm_relayd_quiescent_control msg
;
1751 struct lttcomm_relayd_generic_reply reply
;
1753 DBG("Checking quiescent state on control socket");
1755 if (!conn
->session
|| conn
->version_check_done
== 0) {
1756 ERR("Trying to check for data before version check");
1758 goto end_no_session
;
1761 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1762 if (ret
< sizeof(msg
)) {
1764 /* Orderly shutdown. Not necessary to print an error. */
1765 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1767 ERR("Relay didn't receive valid begin data_pending struct size: %d",
1771 goto end_no_session
;
1774 stream_id
= be64toh(msg
.stream_id
);
1775 stream
= stream_get_by_id(stream_id
);
1779 pthread_mutex_lock(&stream
->lock
);
1780 stream
->data_pending_check_done
= true;
1781 pthread_mutex_unlock(&stream
->lock
);
1782 DBG("Relay quiescent control pending flag set to %" PRIu64
, stream_id
);
1785 memset(&reply
, 0, sizeof(reply
));
1786 reply
.ret_code
= htobe32(LTTNG_OK
);
1787 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1789 ERR("Relay data quiescent control ret code failed");
1797 * Initialize a data pending command. This means that a consumer is about
1798 * to ask for data pending for each stream it holds. Simply iterate over
1799 * all streams of a session and set the data_pending_check_done flag.
1801 * This command returns to the client a LTTNG_OK code.
1803 static int relay_begin_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1804 struct relay_connection
*conn
)
1807 struct lttng_ht_iter iter
;
1808 struct lttcomm_relayd_begin_data_pending msg
;
1809 struct lttcomm_relayd_generic_reply reply
;
1810 struct relay_stream
*stream
;
1811 uint64_t session_id
;
1816 DBG("Init streams for data pending");
1818 if (!conn
->session
|| conn
->version_check_done
== 0) {
1819 ERR("Trying to check for data before version check");
1821 goto end_no_session
;
1824 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1825 if (ret
< sizeof(msg
)) {
1827 /* Orderly shutdown. Not necessary to print an error. */
1828 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1830 ERR("Relay didn't receive valid begin data_pending struct size: %d",
1834 goto end_no_session
;
1837 session_id
= be64toh(msg
.session_id
);
1840 * Iterate over all streams to set the begin data pending flag.
1841 * For now, the streams are indexed by stream handle so we have
1842 * to iterate over all streams to find the one associated with
1843 * the right session_id.
1846 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1848 if (!stream_get(stream
)) {
1851 if (stream
->trace
->session
->id
== session_id
) {
1852 pthread_mutex_lock(&stream
->lock
);
1853 stream
->data_pending_check_done
= false;
1854 pthread_mutex_unlock(&stream
->lock
);
1855 DBG("Set begin data pending flag to stream %" PRIu64
,
1856 stream
->stream_handle
);
1862 memset(&reply
, 0, sizeof(reply
));
1863 /* All good, send back reply. */
1864 reply
.ret_code
= htobe32(LTTNG_OK
);
1866 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1868 ERR("Relay begin data pending send reply failed");
1876 * End data pending command. This will check, for a given session id, if
1877 * each stream associated with it has its data_pending_check_done flag
1878 * set. If not, this means that the client lost track of the stream but
1879 * the data is still being streamed on our side. In this case, we inform
1880 * the client that data is in flight.
1882 * Return to the client if there is data in flight or not with a ret_code.
1884 static int relay_end_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1885 struct relay_connection
*conn
)
1888 struct lttng_ht_iter iter
;
1889 struct lttcomm_relayd_end_data_pending msg
;
1890 struct lttcomm_relayd_generic_reply reply
;
1891 struct relay_stream
*stream
;
1892 uint64_t session_id
;
1893 uint32_t is_data_inflight
= 0;
1895 DBG("End data pending command");
1897 if (!conn
->session
|| conn
->version_check_done
== 0) {
1898 ERR("Trying to check for data before version check");
1900 goto end_no_session
;
1903 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1904 if (ret
< sizeof(msg
)) {
1906 /* Orderly shutdown. Not necessary to print an error. */
1907 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1909 ERR("Relay didn't receive valid end data_pending struct size: %d",
1913 goto end_no_session
;
1916 session_id
= be64toh(msg
.session_id
);
1919 * Iterate over all streams to see if the begin data pending
1923 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1925 if (!stream_get(stream
)) {
1928 if (stream
->trace
->session
->id
!= session_id
) {
1932 pthread_mutex_lock(&stream
->lock
);
1933 if (!stream
->data_pending_check_done
) {
1934 if (!stream
->closed
|| !(((int64_t) (stream
->prev_seq
- stream
->last_net_seq_num
)) >= 0)) {
1935 is_data_inflight
= 1;
1936 DBG("Data is still in flight for stream %" PRIu64
,
1937 stream
->stream_handle
);
1938 pthread_mutex_unlock(&stream
->lock
);
1943 pthread_mutex_unlock(&stream
->lock
);
1948 memset(&reply
, 0, sizeof(reply
));
1949 /* All good, send back reply. */
1950 reply
.ret_code
= htobe32(is_data_inflight
);
1952 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1954 ERR("Relay end data pending send reply failed");
1962 * Receive an index for a specific stream.
1964 * Return 0 on success else a negative value.
1966 static int relay_recv_index(struct lttcomm_relayd_hdr
*recv_hdr
,
1967 struct relay_connection
*conn
)
1970 struct relay_session
*session
= conn
->session
;
1971 struct lttcomm_relayd_index index_info
;
1972 struct relay_index
*index
;
1973 struct lttcomm_relayd_generic_reply reply
;
1974 struct relay_stream
*stream
;
1975 uint64_t net_seq_num
;
1980 DBG("Relay receiving index");
1982 if (!session
|| conn
->version_check_done
== 0) {
1983 ERR("Trying to close a stream before version check");
1985 goto end_no_session
;
1988 msg_len
= lttcomm_relayd_index_len(
1989 lttng_to_index_major(conn
->major
, conn
->minor
),
1990 lttng_to_index_minor(conn
->major
, conn
->minor
));
1991 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &index_info
,
1993 if (ret
< msg_len
) {
1995 /* Orderly shutdown. Not necessary to print an error. */
1996 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1998 ERR("Relay didn't receive valid index struct size : %d", ret
);
2001 goto end_no_session
;
2004 net_seq_num
= be64toh(index_info
.net_seq_num
);
2006 stream
= stream_get_by_id(be64toh(index_info
.relay_stream_id
));
2008 ERR("stream_get_by_id not found");
2012 pthread_mutex_lock(&stream
->lock
);
2014 /* Live beacon handling */
2015 if (index_info
.packet_size
== 0) {
2016 DBG("Received live beacon for stream %" PRIu64
,
2017 stream
->stream_handle
);
2020 * Only flag a stream inactive when it has already
2021 * received data and no indexes are in flight.
2023 if (stream
->index_received_seqcount
> 0
2024 && stream
->indexes_in_flight
== 0) {
2025 stream
->beacon_ts_end
=
2026 be64toh(index_info
.timestamp_end
);
2029 goto end_stream_put
;
2031 stream
->beacon_ts_end
= -1ULL;
2034 if (stream
->ctf_stream_id
== -1ULL) {
2035 stream
->ctf_stream_id
= be64toh(index_info
.stream_id
);
2037 index
= relay_index_get_by_id_or_create(stream
, net_seq_num
);
2040 ERR("relay_index_get_by_id_or_create index NULL");
2041 goto end_stream_put
;
2043 if (set_index_control_data(index
, &index_info
, conn
)) {
2044 ERR("set_index_control_data error");
2045 relay_index_put(index
);
2047 goto end_stream_put
;
2049 ret
= relay_index_try_flush(index
);
2051 tracefile_array_commit_seq(stream
->tfa
);
2052 stream
->index_received_seqcount
++;
2053 } else if (ret
> 0) {
2060 * relay_index_try_flush is responsible for the self-reference
2061 * put of the index object on error.
2063 ERR("relay_index_try_flush error %d", ret
);
2068 pthread_mutex_unlock(&stream
->lock
);
2073 memset(&reply
, 0, sizeof(reply
));
2075 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
2077 reply
.ret_code
= htobe32(LTTNG_OK
);
2079 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
2081 ERR("Relay sending close index id reply");
2090 * Receive the streams_sent message.
2092 * Return 0 on success else a negative value.
2094 static int relay_streams_sent(struct lttcomm_relayd_hdr
*recv_hdr
,
2095 struct relay_connection
*conn
)
2098 struct lttcomm_relayd_generic_reply reply
;
2102 DBG("Relay receiving streams_sent");
2104 if (!conn
->session
|| conn
->version_check_done
== 0) {
2105 ERR("Trying to close a stream before version check");
2107 goto end_no_session
;
2111 * Publish every pending stream in the connection recv list which are
2112 * now ready to be used by the viewer.
2114 publish_connection_local_streams(conn
);
2116 memset(&reply
, 0, sizeof(reply
));
2117 reply
.ret_code
= htobe32(LTTNG_OK
);
2118 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
2120 ERR("Relay sending sent_stream reply");
2132 * Process the commands received on the control socket
2134 static int relay_process_control(struct lttcomm_relayd_hdr
*recv_hdr
,
2135 struct relay_connection
*conn
)
2139 switch (be32toh(recv_hdr
->cmd
)) {
2140 case RELAYD_CREATE_SESSION
:
2141 ret
= relay_create_session(recv_hdr
, conn
);
2143 case RELAYD_ADD_STREAM
:
2144 ret
= relay_add_stream(recv_hdr
, conn
);
2146 case RELAYD_START_DATA
:
2147 ret
= relay_start(recv_hdr
, conn
);
2149 case RELAYD_SEND_METADATA
:
2150 ret
= relay_recv_metadata(recv_hdr
, conn
);
2152 case RELAYD_VERSION
:
2153 ret
= relay_send_version(recv_hdr
, conn
);
2155 case RELAYD_CLOSE_STREAM
:
2156 ret
= relay_close_stream(recv_hdr
, conn
);
2158 case RELAYD_DATA_PENDING
:
2159 ret
= relay_data_pending(recv_hdr
, conn
);
2161 case RELAYD_QUIESCENT_CONTROL
:
2162 ret
= relay_quiescent_control(recv_hdr
, conn
);
2164 case RELAYD_BEGIN_DATA_PENDING
:
2165 ret
= relay_begin_data_pending(recv_hdr
, conn
);
2167 case RELAYD_END_DATA_PENDING
:
2168 ret
= relay_end_data_pending(recv_hdr
, conn
);
2170 case RELAYD_SEND_INDEX
:
2171 ret
= relay_recv_index(recv_hdr
, conn
);
2173 case RELAYD_STREAMS_SENT
:
2174 ret
= relay_streams_sent(recv_hdr
, conn
);
2176 case RELAYD_RESET_METADATA
:
2177 ret
= relay_reset_metadata(recv_hdr
, conn
);
2179 case RELAYD_UPDATE_SYNC_INFO
:
2181 ERR("Received unknown command (%u)", be32toh(recv_hdr
->cmd
));
2182 relay_unknown_command(conn
);
2192 * Handle index for a data stream.
2194 * Called with the stream lock held.
2196 * Return 0 on success else a negative value.
2198 static int handle_index_data(struct relay_stream
*stream
, uint64_t net_seq_num
,
2202 uint64_t data_offset
;
2203 struct relay_index
*index
;
2205 /* Get data offset because we are about to update the index. */
2206 data_offset
= htobe64(stream
->tracefile_size_current
);
2208 DBG("handle_index_data: stream %" PRIu64
" net_seq_num %" PRIu64
" data offset %" PRIu64
,
2209 stream
->stream_handle
, net_seq_num
, stream
->tracefile_size_current
);
2212 * Lookup for an existing index for that stream id/sequence
2213 * number. If it exists, the control thread has already received the
2214 * data for it, thus we need to write it to disk.
2216 index
= relay_index_get_by_id_or_create(stream
, net_seq_num
);
2222 if (rotate_index
|| !stream
->index_file
) {
2223 uint32_t major
, minor
;
2225 /* Put ref on previous index_file. */
2226 if (stream
->index_file
) {
2227 lttng_index_file_put(stream
->index_file
);
2228 stream
->index_file
= NULL
;
2230 major
= stream
->trace
->session
->major
;
2231 minor
= stream
->trace
->session
->minor
;
2232 stream
->index_file
= lttng_index_file_create(stream
->path_name
,
2233 stream
->channel_name
,
2234 -1, -1, stream
->tracefile_size
,
2235 tracefile_array_get_file_index_head(stream
->tfa
),
2236 lttng_to_index_major(major
, minor
),
2237 lttng_to_index_minor(major
, minor
));
2238 if (!stream
->index_file
) {
2240 /* Put self-ref for this index due to error. */
2241 relay_index_put(index
);
2247 if (relay_index_set_file(index
, stream
->index_file
, data_offset
)) {
2249 /* Put self-ref for this index due to error. */
2250 relay_index_put(index
);
2255 ret
= relay_index_try_flush(index
);
2257 tracefile_array_commit_seq(stream
->tfa
);
2258 stream
->index_received_seqcount
++;
2259 } else if (ret
> 0) {
2266 * relay_index_try_flush is responsible for the self-reference
2267 * put of the index object on error.
2269 ERR("relay_index_try_flush error %d", ret
);
2277 * relay_process_data: Process the data received on the data socket
2279 static int relay_process_data(struct relay_connection
*conn
)
2281 int ret
= 0, rotate_index
= 0;
2283 struct relay_stream
*stream
;
2284 struct lttcomm_relayd_data_hdr data_hdr
;
2286 uint64_t net_seq_num
;
2288 struct relay_session
*session
;
2289 bool new_stream
= false, close_requested
= false;
2290 size_t chunk_size
= RECV_DATA_BUFFER_SIZE
;
2291 size_t recv_off
= 0;
2292 char data_buffer
[chunk_size
];
2294 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &data_hdr
,
2295 sizeof(struct lttcomm_relayd_data_hdr
), 0);
2298 /* Orderly shutdown. Not necessary to print an error. */
2299 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
2301 ERR("Unable to receive data header on sock %d", conn
->sock
->fd
);
2307 stream_id
= be64toh(data_hdr
.stream_id
);
2308 stream
= stream_get_by_id(stream_id
);
2310 ERR("relay_process_data: Cannot find stream %" PRIu64
, stream_id
);
2314 session
= stream
->trace
->session
;
2315 data_size
= be32toh(data_hdr
.data_size
);
2317 net_seq_num
= be64toh(data_hdr
.net_seq_num
);
2319 DBG3("Receiving data of size %u for stream id %" PRIu64
" seqnum %" PRIu64
,
2320 data_size
, stream_id
, net_seq_num
);
2322 pthread_mutex_lock(&stream
->lock
);
2324 /* Check if a rotation is needed. */
2325 if (stream
->tracefile_size
> 0 &&
2326 (stream
->tracefile_size_current
+ data_size
) >
2327 stream
->tracefile_size
) {
2328 uint64_t old_id
, new_id
;
2330 old_id
= tracefile_array_get_file_index_head(stream
->tfa
);
2331 tracefile_array_file_rotate(stream
->tfa
);
2333 /* new_id is updated by utils_rotate_stream_file. */
2336 ret
= utils_rotate_stream_file(stream
->path_name
,
2337 stream
->channel_name
, stream
->tracefile_size
,
2338 stream
->tracefile_count
, -1,
2339 -1, stream
->stream_fd
->fd
,
2340 &new_id
, &stream
->stream_fd
->fd
);
2342 ERR("Rotating stream output file");
2343 goto end_stream_unlock
;
2346 * Reset current size because we just performed a stream
2349 stream
->tracefile_size_current
= 0;
2354 * Index are handled in protocol version 2.4 and above. Also,
2355 * snapshot and index are NOT supported.
2357 if (session
->minor
>= 4 && !session
->snapshot
) {
2358 ret
= handle_index_data(stream
, net_seq_num
, rotate_index
);
2360 ERR("handle_index_data: fail stream %" PRIu64
" net_seq_num %" PRIu64
" ret %d",
2361 stream
->stream_handle
, net_seq_num
, ret
);
2362 goto end_stream_unlock
;
2366 for (recv_off
= 0; recv_off
< data_size
; recv_off
+= chunk_size
) {
2367 size_t recv_size
= min(data_size
- recv_off
, chunk_size
);
2369 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, data_buffer
, recv_size
, 0);
2372 /* Orderly shutdown. Not necessary to print an error. */
2373 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
2375 ERR("Socket %d error %d", conn
->sock
->fd
, ret
);
2378 goto end_stream_unlock
;
2381 /* Write data to stream output fd. */
2382 size_ret
= lttng_write(stream
->stream_fd
->fd
, data_buffer
,
2384 if (size_ret
< recv_size
) {
2385 ERR("Relay error writing data to file");
2387 goto end_stream_unlock
;
2390 DBG2("Relay wrote %zd bytes to tracefile for stream id %" PRIu64
,
2391 size_ret
, stream
->stream_handle
);
2394 ret
= write_padding_to_file(stream
->stream_fd
->fd
,
2395 be32toh(data_hdr
.padding_size
));
2397 ERR("write_padding_to_file: fail stream %" PRIu64
" net_seq_num %" PRIu64
" ret %d",
2398 stream
->stream_handle
, net_seq_num
, ret
);
2399 goto end_stream_unlock
;
2401 stream
->tracefile_size_current
+=
2402 data_size
+ be32toh(data_hdr
.padding_size
);
2403 if (stream
->prev_seq
== -1ULL) {
2407 stream
->prev_seq
= net_seq_num
;
2410 close_requested
= stream
->close_requested
;
2411 pthread_mutex_unlock(&stream
->lock
);
2412 if (close_requested
) {
2413 try_stream_close(stream
);
2417 pthread_mutex_lock(&session
->lock
);
2418 uatomic_set(&session
->new_streams
, 1);
2419 pthread_mutex_unlock(&session
->lock
);
2426 static void cleanup_connection_pollfd(struct lttng_poll_event
*events
, int pollfd
)
2430 (void) lttng_poll_del(events
, pollfd
);
2432 ret
= close(pollfd
);
2434 ERR("Closing pollfd %d", pollfd
);
2438 static void relay_thread_close_connection(struct lttng_poll_event
*events
,
2439 int pollfd
, struct relay_connection
*conn
)
2441 const char *type_str
;
2443 switch (conn
->type
) {
2448 type_str
= "Control";
2450 case RELAY_VIEWER_COMMAND
:
2451 type_str
= "Viewer Command";
2453 case RELAY_VIEWER_NOTIFICATION
:
2454 type_str
= "Viewer Notification";
2457 type_str
= "Unknown";
2459 cleanup_connection_pollfd(events
, pollfd
);
2460 connection_put(conn
);
2461 DBG("%s connection closed with %d", type_str
, pollfd
);
2465 * This thread does the actual work
2467 static void *relay_thread_worker(void *data
)
2469 int ret
, err
= -1, last_seen_data_fd
= -1;
2471 struct lttng_poll_event events
;
2472 struct lttng_ht
*relay_connections_ht
;
2473 struct lttng_ht_iter iter
;
2474 struct lttcomm_relayd_hdr recv_hdr
;
2475 struct relay_connection
*destroy_conn
= NULL
;
2477 DBG("[thread] Relay worker started");
2479 rcu_register_thread();
2481 health_register(health_relayd
, HEALTH_RELAYD_TYPE_WORKER
);
2483 if (testpoint(relayd_thread_worker
)) {
2484 goto error_testpoint
;
2487 health_code_update();
2489 /* table of connections indexed on socket */
2490 relay_connections_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2491 if (!relay_connections_ht
) {
2492 goto relay_connections_ht_error
;
2495 ret
= create_thread_poll_set(&events
, 2);
2497 goto error_poll_create
;
2500 ret
= lttng_poll_add(&events
, relay_conn_pipe
[0], LPOLLIN
| LPOLLRDHUP
);
2507 int idx
= -1, i
, seen_control
= 0, last_notdel_data_fd
= -1;
2509 health_code_update();
2511 /* Infinite blocking call, waiting for transmission */
2512 DBG3("Relayd worker thread polling...");
2513 health_poll_entry();
2514 ret
= lttng_poll_wait(&events
, -1);
2518 * Restart interrupted system call.
2520 if (errno
== EINTR
) {
2529 * Process control. The control connection is
2530 * prioritized so we don't starve it with high
2531 * throughput tracing data on the data connection.
2533 for (i
= 0; i
< nb_fd
; i
++) {
2534 /* Fetch once the poll data */
2535 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
2536 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2538 health_code_update();
2542 * No activity for this FD (poll
2548 /* Thread quit pipe has been closed. Killing thread. */
2549 ret
= check_thread_quit_pipe(pollfd
, revents
);
2555 /* Inspect the relay conn pipe for new connection */
2556 if (pollfd
== relay_conn_pipe
[0]) {
2557 if (revents
& LPOLLIN
) {
2558 struct relay_connection
*conn
;
2560 ret
= lttng_read(relay_conn_pipe
[0], &conn
, sizeof(conn
));
2564 lttng_poll_add(&events
, conn
->sock
->fd
,
2565 LPOLLIN
| LPOLLRDHUP
);
2566 connection_ht_add(relay_connections_ht
, conn
);
2567 DBG("Connection socket %d added", conn
->sock
->fd
);
2568 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2569 ERR("Relay connection pipe error");
2572 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
2576 struct relay_connection
*ctrl_conn
;
2578 ctrl_conn
= connection_get_by_sock(relay_connections_ht
, pollfd
);
2579 /* If not found, there is a synchronization issue. */
2582 if (ctrl_conn
->type
== RELAY_DATA
) {
2583 if (revents
& LPOLLIN
) {
2585 * Flag the last seen data fd not deleted. It will be
2586 * used as the last seen fd if any fd gets deleted in
2589 last_notdel_data_fd
= pollfd
;
2591 goto put_ctrl_connection
;
2593 assert(ctrl_conn
->type
== RELAY_CONTROL
);
2595 if (revents
& LPOLLIN
) {
2596 ret
= ctrl_conn
->sock
->ops
->recvmsg(ctrl_conn
->sock
,
2597 &recv_hdr
, sizeof(recv_hdr
), 0);
2599 /* Connection closed */
2600 relay_thread_close_connection(&events
, pollfd
,
2603 ret
= relay_process_control(&recv_hdr
, ctrl_conn
);
2605 /* Clear the session on error. */
2606 relay_thread_close_connection(&events
,
2611 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2612 relay_thread_close_connection(&events
,
2614 if (last_seen_data_fd
== pollfd
) {
2615 last_seen_data_fd
= last_notdel_data_fd
;
2618 ERR("Unexpected poll events %u for control sock %d",
2620 connection_put(ctrl_conn
);
2623 put_ctrl_connection
:
2624 connection_put(ctrl_conn
);
2629 * The last loop handled a control request, go back to poll to make
2630 * sure we prioritise the control socket.
2636 if (last_seen_data_fd
>= 0) {
2637 for (i
= 0; i
< nb_fd
; i
++) {
2638 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2640 health_code_update();
2642 if (last_seen_data_fd
== pollfd
) {
2649 /* Process data connection. */
2650 for (i
= idx
+ 1; i
< nb_fd
; i
++) {
2651 /* Fetch the poll data. */
2652 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
2653 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2654 struct relay_connection
*data_conn
;
2656 health_code_update();
2659 /* No activity for this FD (poll implementation). */
2663 /* Skip the command pipe. It's handled in the first loop. */
2664 if (pollfd
== relay_conn_pipe
[0]) {
2668 data_conn
= connection_get_by_sock(relay_connections_ht
, pollfd
);
2670 /* Skip it. Might be removed before. */
2673 if (data_conn
->type
== RELAY_CONTROL
) {
2674 goto put_data_connection
;
2676 assert(data_conn
->type
== RELAY_DATA
);
2678 if (revents
& LPOLLIN
) {
2679 ret
= relay_process_data(data_conn
);
2680 /* Connection closed */
2682 relay_thread_close_connection(&events
, pollfd
,
2685 * Every goto restart call sets the last seen fd where
2686 * here we don't really care since we gracefully
2687 * continue the loop after the connection is deleted.
2690 /* Keep last seen port. */
2691 last_seen_data_fd
= pollfd
;
2692 connection_put(data_conn
);
2695 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2696 relay_thread_close_connection(&events
, pollfd
,
2699 ERR("Unknown poll events %u for data sock %d",
2702 put_data_connection
:
2703 connection_put(data_conn
);
2705 last_seen_data_fd
= -1;
2708 /* Normal exit, no error */
2713 /* Cleanup reamaining connection object. */
2715 cds_lfht_for_each_entry(relay_connections_ht
->ht
, &iter
.iter
,
2718 health_code_update();
2720 if (session_abort(destroy_conn
->session
)) {
2725 * No need to grab another ref, because we own
2728 relay_thread_close_connection(&events
, destroy_conn
->sock
->fd
,
2733 lttng_poll_clean(&events
);
2735 lttng_ht_destroy(relay_connections_ht
);
2736 relay_connections_ht_error
:
2737 /* Close relay conn pipes */
2738 utils_close_pipe(relay_conn_pipe
);
2740 DBG("Thread exited with error");
2742 DBG("Worker thread cleanup complete");
2746 ERR("Health error occurred in %s", __func__
);
2748 health_unregister(health_relayd
);
2749 rcu_unregister_thread();
2750 lttng_relay_stop_threads();
2755 * Create the relay command pipe to wake thread_manage_apps.
2756 * Closed in cleanup().
2758 static int create_relay_conn_pipe(void)
2762 ret
= utils_create_pipe_cloexec(relay_conn_pipe
);
2770 int main(int argc
, char **argv
)
2772 int ret
= 0, retval
= 0;
2775 /* Parse arguments */
2777 if (set_options(argc
, argv
)) {
2782 if (set_signal_handler()) {
2787 /* Try to create directory if -o, --output is specified. */
2788 if (opt_output_path
) {
2789 if (*opt_output_path
!= '/') {
2790 ERR("Please specify an absolute path for -o, --output PATH");
2795 ret
= utils_mkdir_recursive(opt_output_path
, S_IRWXU
| S_IRWXG
,
2798 ERR("Unable to create %s", opt_output_path
);
2805 if (opt_daemon
|| opt_background
) {
2808 ret
= lttng_daemonize(&child_ppid
, &recv_child_signal
,
2816 * We are in the child. Make sure all other file
2817 * descriptors are closed, in case we are called with
2818 * more opened file descriptors than the standard ones.
2820 for (i
= 3; i
< sysconf(_SC_OPEN_MAX
); i
++) {
2825 /* Initialize thread health monitoring */
2826 health_relayd
= health_app_create(NR_HEALTH_RELAYD_TYPES
);
2827 if (!health_relayd
) {
2828 PERROR("health_app_create error");
2830 goto exit_health_app_create
;
2833 /* Create thread quit pipe */
2834 if (init_thread_quit_pipe()) {
2836 goto exit_init_data
;
2839 /* Setup the thread apps communication pipe. */
2840 if (create_relay_conn_pipe()) {
2842 goto exit_init_data
;
2845 /* Init relay command queue. */
2846 cds_wfcq_init(&relay_conn_queue
.head
, &relay_conn_queue
.tail
);
2848 /* Initialize communication library */
2850 lttcomm_inet_init();
2852 /* tables of sessions indexed by session ID */
2853 sessions_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2856 goto exit_init_data
;
2859 /* tables of streams indexed by stream ID */
2860 relay_streams_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2861 if (!relay_streams_ht
) {
2863 goto exit_init_data
;
2866 /* tables of streams indexed by stream ID */
2867 viewer_streams_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2868 if (!viewer_streams_ht
) {
2870 goto exit_init_data
;
2873 ret
= utils_create_pipe(health_quit_pipe
);
2876 goto exit_health_quit_pipe
;
2879 /* Create thread to manage the client socket */
2880 ret
= pthread_create(&health_thread
, default_pthread_attr(),
2881 thread_manage_health
, (void *) NULL
);
2884 PERROR("pthread_create health");
2886 goto exit_health_thread
;
2889 /* Setup the dispatcher thread */
2890 ret
= pthread_create(&dispatcher_thread
, default_pthread_attr(),
2891 relay_thread_dispatcher
, (void *) NULL
);
2894 PERROR("pthread_create dispatcher");
2896 goto exit_dispatcher_thread
;
2899 /* Setup the worker thread */
2900 ret
= pthread_create(&worker_thread
, default_pthread_attr(),
2901 relay_thread_worker
, NULL
);
2904 PERROR("pthread_create worker");
2906 goto exit_worker_thread
;
2909 /* Setup the listener thread */
2910 ret
= pthread_create(&listener_thread
, default_pthread_attr(),
2911 relay_thread_listener
, (void *) NULL
);
2914 PERROR("pthread_create listener");
2916 goto exit_listener_thread
;
2919 ret
= relayd_live_create(live_uri
);
2921 ERR("Starting live viewer threads");
2927 * This is where we start awaiting program completion (e.g. through
2928 * signal that asks threads to teardown).
2931 ret
= relayd_live_join();
2937 ret
= pthread_join(listener_thread
, &status
);
2940 PERROR("pthread_join listener_thread");
2944 exit_listener_thread
:
2945 ret
= pthread_join(worker_thread
, &status
);
2948 PERROR("pthread_join worker_thread");
2953 ret
= pthread_join(dispatcher_thread
, &status
);
2956 PERROR("pthread_join dispatcher_thread");
2959 exit_dispatcher_thread
:
2961 ret
= pthread_join(health_thread
, &status
);
2964 PERROR("pthread_join health_thread");
2969 utils_close_pipe(health_quit_pipe
);
2970 exit_health_quit_pipe
:
2973 health_app_destroy(health_relayd
);
2974 exit_health_app_create
:
2977 * Wait for all pending call_rcu work to complete before tearing
2978 * down data structures. call_rcu worker may be trying to
2979 * perform lookups in those structures.
2984 /* Ensure all prior call_rcu are done. */