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
);
755 ret
= sock
->ops
->listen(sock
, -1);
765 lttcomm_destroy_sock(sock
);
771 * This thread manages the listening for new connections on the network
773 static void *relay_thread_listener(void *data
)
775 int i
, ret
, pollfd
, err
= -1;
776 uint32_t revents
, nb_fd
;
777 struct lttng_poll_event events
;
778 struct lttcomm_sock
*control_sock
, *data_sock
;
780 DBG("[thread] Relay listener started");
782 health_register(health_relayd
, HEALTH_RELAYD_TYPE_LISTENER
);
784 health_code_update();
786 control_sock
= relay_socket_create(control_uri
);
788 goto error_sock_control
;
791 data_sock
= relay_socket_create(data_uri
);
793 goto error_sock_relay
;
797 * Pass 3 as size here for the thread quit pipe, control and
800 ret
= create_thread_poll_set(&events
, 3);
802 goto error_create_poll
;
805 /* Add the control socket */
806 ret
= lttng_poll_add(&events
, control_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
811 /* Add the data socket */
812 ret
= lttng_poll_add(&events
, data_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
817 lttng_relay_notify_ready();
819 if (testpoint(relayd_thread_listener
)) {
820 goto error_testpoint
;
824 health_code_update();
826 DBG("Listener accepting connections");
830 ret
= lttng_poll_wait(&events
, -1);
834 * Restart interrupted system call.
836 if (errno
== EINTR
) {
844 DBG("Relay new connection received");
845 for (i
= 0; i
< nb_fd
; i
++) {
846 health_code_update();
848 /* Fetch once the poll data */
849 revents
= LTTNG_POLL_GETEV(&events
, i
);
850 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
854 * No activity for this FD (poll
860 /* Thread quit pipe has been closed. Killing thread. */
861 ret
= check_thread_quit_pipe(pollfd
, revents
);
867 if (revents
& LPOLLIN
) {
869 * A new connection is requested, therefore a
870 * sessiond/consumerd connection is allocated in
871 * this thread, enqueued to a global queue and
872 * dequeued (and freed) in the worker thread.
875 struct relay_connection
*new_conn
;
876 struct lttcomm_sock
*newsock
;
877 enum connection_type type
;
879 if (pollfd
== data_sock
->fd
) {
881 newsock
= data_sock
->ops
->accept(data_sock
);
882 DBG("Relay data connection accepted, socket %d",
885 assert(pollfd
== control_sock
->fd
);
886 type
= RELAY_CONTROL
;
887 newsock
= control_sock
->ops
->accept(control_sock
);
888 DBG("Relay control connection accepted, socket %d",
892 PERROR("accepting sock");
896 ret
= setsockopt(newsock
->fd
, SOL_SOCKET
, SO_REUSEADDR
, &val
,
899 PERROR("setsockopt inet");
900 lttcomm_destroy_sock(newsock
);
904 ret
= socket_apply_keep_alive_config(newsock
->fd
);
906 ERR("Failed to apply TCP keep-alive configuration on socket (%i)",
908 lttcomm_destroy_sock(newsock
);
912 new_conn
= connection_create(newsock
, type
);
914 lttcomm_destroy_sock(newsock
);
918 /* Enqueue request for the dispatcher thread. */
919 cds_wfcq_enqueue(&relay_conn_queue
.head
, &relay_conn_queue
.tail
,
923 * Wake the dispatch queue futex.
924 * Implicit memory barrier with the
925 * exchange in cds_wfcq_enqueue.
927 futex_nto1_wake(&relay_conn_queue
.futex
);
928 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
929 ERR("socket poll error");
932 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
942 lttng_poll_clean(&events
);
944 if (data_sock
->fd
>= 0) {
945 ret
= data_sock
->ops
->close(data_sock
);
950 lttcomm_destroy_sock(data_sock
);
952 if (control_sock
->fd
>= 0) {
953 ret
= control_sock
->ops
->close(control_sock
);
958 lttcomm_destroy_sock(control_sock
);
962 ERR("Health error occurred in %s", __func__
);
964 health_unregister(health_relayd
);
965 DBG("Relay listener thread cleanup complete");
966 lttng_relay_stop_threads();
971 * This thread manages the dispatching of the requests to worker threads
973 static void *relay_thread_dispatcher(void *data
)
977 struct cds_wfcq_node
*node
;
978 struct relay_connection
*new_conn
= NULL
;
980 DBG("[thread] Relay dispatcher started");
982 health_register(health_relayd
, HEALTH_RELAYD_TYPE_DISPATCHER
);
984 if (testpoint(relayd_thread_dispatcher
)) {
985 goto error_testpoint
;
988 health_code_update();
991 health_code_update();
993 /* Atomically prepare the queue futex */
994 futex_nto1_prepare(&relay_conn_queue
.futex
);
996 if (CMM_LOAD_SHARED(dispatch_thread_exit
)) {
1001 health_code_update();
1003 /* Dequeue commands */
1004 node
= cds_wfcq_dequeue_blocking(&relay_conn_queue
.head
,
1005 &relay_conn_queue
.tail
);
1007 DBG("Woken up but nothing in the relay command queue");
1008 /* Continue thread execution */
1011 new_conn
= caa_container_of(node
, struct relay_connection
, qnode
);
1013 DBG("Dispatching request waiting on sock %d", new_conn
->sock
->fd
);
1016 * Inform worker thread of the new request. This
1017 * call is blocking so we can be assured that
1018 * the data will be read at some point in time
1019 * or wait to the end of the world :)
1021 ret
= lttng_write(relay_conn_pipe
[1], &new_conn
, sizeof(new_conn
));
1023 PERROR("write connection pipe");
1024 connection_put(new_conn
);
1027 } while (node
!= NULL
);
1029 /* Futex wait on queue. Blocking call on futex() */
1030 health_poll_entry();
1031 futex_nto1_wait(&relay_conn_queue
.futex
);
1035 /* Normal exit, no error */
1042 ERR("Health error occurred in %s", __func__
);
1044 health_unregister(health_relayd
);
1045 DBG("Dispatch thread dying");
1046 lttng_relay_stop_threads();
1051 * Set index data from the control port to a given index object.
1053 static int set_index_control_data(struct relay_index
*index
,
1054 struct lttcomm_relayd_index
*data
,
1055 struct relay_connection
*conn
)
1057 struct ctf_packet_index index_data
;
1060 * The index on disk is encoded in big endian, so we don't need
1061 * to convert the data received on the network. The data_offset
1062 * value is NEVER modified here and is updated by the data
1065 index_data
.packet_size
= data
->packet_size
;
1066 index_data
.content_size
= data
->content_size
;
1067 index_data
.timestamp_begin
= data
->timestamp_begin
;
1068 index_data
.timestamp_end
= data
->timestamp_end
;
1069 index_data
.events_discarded
= data
->events_discarded
;
1070 index_data
.stream_id
= data
->stream_id
;
1072 if (conn
->minor
>= 8) {
1073 index
->index_data
.stream_instance_id
= data
->stream_instance_id
;
1074 index
->index_data
.packet_seq_num
= data
->packet_seq_num
;
1077 return relay_index_set_data(index
, &index_data
);
1081 * Handle the RELAYD_CREATE_SESSION command.
1083 * On success, send back the session id or else return a negative value.
1085 static int relay_create_session(struct lttcomm_relayd_hdr
*recv_hdr
,
1086 struct relay_connection
*conn
)
1088 int ret
= 0, send_ret
;
1089 struct relay_session
*session
;
1090 struct lttcomm_relayd_status_session reply
;
1091 char session_name
[LTTNG_NAME_MAX
];
1092 char hostname
[LTTNG_HOST_NAME_MAX
];
1093 uint32_t live_timer
= 0;
1094 bool snapshot
= false;
1096 memset(session_name
, 0, LTTNG_NAME_MAX
);
1097 memset(hostname
, 0, LTTNG_HOST_NAME_MAX
);
1099 memset(&reply
, 0, sizeof(reply
));
1101 switch (conn
->minor
) {
1106 case 4: /* LTTng sessiond 2.4 */
1108 ret
= cmd_create_session_2_4(conn
, session_name
,
1109 hostname
, &live_timer
, &snapshot
);
1115 session
= session_create(session_name
, hostname
, live_timer
,
1116 snapshot
, conn
->major
, conn
->minor
);
1121 assert(!conn
->session
);
1122 conn
->session
= session
;
1123 DBG("Created session %" PRIu64
, session
->id
);
1125 reply
.session_id
= htobe64(session
->id
);
1129 reply
.ret_code
= htobe32(LTTNG_ERR_FATAL
);
1131 reply
.ret_code
= htobe32(LTTNG_OK
);
1134 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1136 ERR("Relayd sending session id");
1144 * When we have received all the streams and the metadata for a channel,
1145 * we make them visible to the viewer threads.
1147 static void publish_connection_local_streams(struct relay_connection
*conn
)
1149 struct relay_stream
*stream
;
1150 struct relay_session
*session
= conn
->session
;
1153 * We publish all streams belonging to a session atomically wrt
1156 pthread_mutex_lock(&session
->lock
);
1158 cds_list_for_each_entry_rcu(stream
, &session
->recv_list
,
1160 stream_publish(stream
);
1165 * Inform the viewer that there are new streams in the session.
1167 if (session
->viewer_attached
) {
1168 uatomic_set(&session
->new_streams
, 1);
1170 pthread_mutex_unlock(&session
->lock
);
1174 * relay_add_stream: allocate a new stream for a session
1176 static int relay_add_stream(struct lttcomm_relayd_hdr
*recv_hdr
,
1177 struct relay_connection
*conn
)
1181 struct relay_session
*session
= conn
->session
;
1182 struct relay_stream
*stream
= NULL
;
1183 struct lttcomm_relayd_status_stream reply
;
1184 struct ctf_trace
*trace
= NULL
;
1185 uint64_t stream_handle
= -1ULL;
1186 char *path_name
= NULL
, *channel_name
= NULL
;
1187 uint64_t tracefile_size
= 0, tracefile_count
= 0;
1189 if (!session
|| conn
->version_check_done
== 0) {
1190 ERR("Trying to add a stream before version check");
1192 goto end_no_session
;
1195 switch (session
->minor
) {
1196 case 1: /* LTTng sessiond 2.1. Allocates path_name and channel_name. */
1197 ret
= cmd_recv_stream_2_1(conn
, &path_name
,
1200 case 2: /* LTTng sessiond 2.2. Allocates path_name and channel_name. */
1202 ret
= cmd_recv_stream_2_2(conn
, &path_name
,
1203 &channel_name
, &tracefile_size
, &tracefile_count
);
1210 trace
= ctf_trace_get_by_path_or_create(session
, path_name
);
1214 /* This stream here has one reference on the trace. */
1216 pthread_mutex_lock(&last_relay_stream_id_lock
);
1217 stream_handle
= ++last_relay_stream_id
;
1218 pthread_mutex_unlock(&last_relay_stream_id_lock
);
1220 /* We pass ownership of path_name and channel_name. */
1221 stream
= stream_create(trace
, stream_handle
, path_name
,
1222 channel_name
, tracefile_size
, tracefile_count
);
1224 channel_name
= NULL
;
1227 * Streams are the owners of their trace. Reference to trace is
1228 * kept within stream_create().
1230 ctf_trace_put(trace
);
1233 memset(&reply
, 0, sizeof(reply
));
1234 reply
.handle
= htobe64(stream_handle
);
1236 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1238 reply
.ret_code
= htobe32(LTTNG_OK
);
1241 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1242 sizeof(struct lttcomm_relayd_status_stream
), 0);
1244 ERR("Relay sending stream id");
1245 ret
= (int) send_ret
;
1255 * relay_close_stream: close a specific stream
1257 static int relay_close_stream(struct lttcomm_relayd_hdr
*recv_hdr
,
1258 struct relay_connection
*conn
)
1261 struct relay_session
*session
= conn
->session
;
1262 struct lttcomm_relayd_close_stream stream_info
;
1263 struct lttcomm_relayd_generic_reply reply
;
1264 struct relay_stream
*stream
;
1266 DBG("Close stream received");
1268 if (!session
|| conn
->version_check_done
== 0) {
1269 ERR("Trying to close a stream before version check");
1271 goto end_no_session
;
1274 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &stream_info
,
1275 sizeof(struct lttcomm_relayd_close_stream
), 0);
1276 if (ret
< sizeof(struct lttcomm_relayd_close_stream
)) {
1278 /* Orderly shutdown. Not necessary to print an error. */
1279 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1281 ERR("Relay didn't receive valid add_stream struct size : %d", ret
);
1284 goto end_no_session
;
1287 stream
= stream_get_by_id(be64toh(stream_info
.stream_id
));
1294 * Set last_net_seq_num before the close flag. Required by data
1297 pthread_mutex_lock(&stream
->lock
);
1298 stream
->last_net_seq_num
= be64toh(stream_info
.last_net_seq_num
);
1299 pthread_mutex_unlock(&stream
->lock
);
1302 * This is one of the conditions which may trigger a stream close
1303 * with the others being:
1304 * 1) A close command is received for a stream
1305 * 2) The control connection owning the stream is closed
1306 * 3) We have received all of the stream's data _after_ a close
1309 try_stream_close(stream
);
1310 if (stream
->is_metadata
) {
1311 struct relay_viewer_stream
*vstream
;
1313 vstream
= viewer_stream_get_by_id(stream
->stream_handle
);
1315 if (vstream
->metadata_sent
== stream
->metadata_received
) {
1317 * Since all the metadata has been sent to the
1318 * viewer and that we have a request to close
1319 * its stream, we can safely teardown the
1320 * corresponding metadata viewer stream.
1322 viewer_stream_put(vstream
);
1324 /* Put local reference. */
1325 viewer_stream_put(vstream
);
1331 memset(&reply
, 0, sizeof(reply
));
1333 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1335 reply
.ret_code
= htobe32(LTTNG_OK
);
1337 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1338 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1340 ERR("Relay sending stream id");
1349 * relay_reset_metadata: reset a metadata stream
1352 int relay_reset_metadata(struct lttcomm_relayd_hdr
*recv_hdr
,
1353 struct relay_connection
*conn
)
1356 struct relay_session
*session
= conn
->session
;
1357 struct lttcomm_relayd_reset_metadata stream_info
;
1358 struct lttcomm_relayd_generic_reply reply
;
1359 struct relay_stream
*stream
;
1361 DBG("Reset metadata received");
1363 if (!session
|| conn
->version_check_done
== 0) {
1364 ERR("Trying to reset a metadata stream before version check");
1366 goto end_no_session
;
1369 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &stream_info
,
1370 sizeof(struct lttcomm_relayd_reset_metadata
), 0);
1371 if (ret
< sizeof(struct lttcomm_relayd_reset_metadata
)) {
1373 /* Orderly shutdown. Not necessary to print an error. */
1374 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1376 ERR("Relay didn't receive valid reset_metadata struct "
1380 goto end_no_session
;
1382 DBG("Update metadata to version %" PRIu64
, be64toh(stream_info
.version
));
1384 /* Unsupported for live sessions for now. */
1385 if (session
->live_timer
!= 0) {
1390 stream
= stream_get_by_id(be64toh(stream_info
.stream_id
));
1395 pthread_mutex_lock(&stream
->lock
);
1396 if (!stream
->is_metadata
) {
1401 ret
= utils_rotate_stream_file(stream
->path_name
, stream
->channel_name
,
1402 0, 0, -1, -1, stream
->stream_fd
->fd
, NULL
,
1403 &stream
->stream_fd
->fd
);
1405 ERR("Failed to rotate metadata file %s of channel %s",
1406 stream
->path_name
, stream
->channel_name
);
1411 pthread_mutex_unlock(&stream
->lock
);
1415 memset(&reply
, 0, sizeof(reply
));
1417 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1419 reply
.ret_code
= htobe32(LTTNG_OK
);
1421 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1422 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1424 ERR("Relay sending reset metadata reply");
1433 * relay_unknown_command: send -1 if received unknown command
1435 static void relay_unknown_command(struct relay_connection
*conn
)
1437 struct lttcomm_relayd_generic_reply reply
;
1440 memset(&reply
, 0, sizeof(reply
));
1441 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1442 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1443 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1445 ERR("Relay sending unknown command");
1450 * relay_start: send an acknowledgment to the client to tell if we are
1451 * ready to receive data. We are ready if a session is established.
1453 static int relay_start(struct lttcomm_relayd_hdr
*recv_hdr
,
1454 struct relay_connection
*conn
)
1456 int ret
= htobe32(LTTNG_OK
);
1457 struct lttcomm_relayd_generic_reply reply
;
1458 struct relay_session
*session
= conn
->session
;
1461 DBG("Trying to start the streaming without a session established");
1462 ret
= htobe32(LTTNG_ERR_UNK
);
1465 memset(&reply
, 0, sizeof(reply
));
1466 reply
.ret_code
= ret
;
1467 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1468 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1470 ERR("Relay sending start ack");
1477 * Append padding to the file pointed by the file descriptor fd.
1479 static int write_padding_to_file(int fd
, uint32_t size
)
1488 zeros
= zmalloc(size
);
1489 if (zeros
== NULL
) {
1490 PERROR("zmalloc zeros for padding");
1495 ret
= lttng_write(fd
, zeros
, size
);
1497 PERROR("write padding to file");
1507 * relay_recv_metadata: receive the metadata for the session.
1509 static int relay_recv_metadata(struct lttcomm_relayd_hdr
*recv_hdr
,
1510 struct relay_connection
*conn
)
1514 struct relay_session
*session
= conn
->session
;
1515 struct lttcomm_relayd_metadata_payload
*metadata_struct
;
1516 struct relay_stream
*metadata_stream
;
1517 uint64_t data_size
, payload_size
;
1520 ERR("Metadata sent before version check");
1525 data_size
= payload_size
= be64toh(recv_hdr
->data_size
);
1526 if (data_size
< sizeof(struct lttcomm_relayd_metadata_payload
)) {
1527 ERR("Incorrect data size");
1531 payload_size
-= sizeof(struct lttcomm_relayd_metadata_payload
);
1533 if (data_buffer_size
< data_size
) {
1534 /* In case the realloc fails, we can free the memory */
1537 tmp_data_ptr
= realloc(data_buffer
, data_size
);
1538 if (!tmp_data_ptr
) {
1539 ERR("Allocating data buffer");
1544 data_buffer
= tmp_data_ptr
;
1545 data_buffer_size
= data_size
;
1547 memset(data_buffer
, 0, data_size
);
1548 DBG2("Relay receiving metadata, waiting for %" PRIu64
" bytes", data_size
);
1549 size_ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, data_buffer
, data_size
, 0);
1550 if (size_ret
< 0 || size_ret
!= data_size
) {
1551 if (size_ret
== 0) {
1552 /* Orderly shutdown. Not necessary to print an error. */
1553 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1555 ERR("Relay didn't receive the whole metadata");
1560 metadata_struct
= (struct lttcomm_relayd_metadata_payload
*) data_buffer
;
1562 metadata_stream
= stream_get_by_id(be64toh(metadata_struct
->stream_id
));
1563 if (!metadata_stream
) {
1568 pthread_mutex_lock(&metadata_stream
->lock
);
1570 size_ret
= lttng_write(metadata_stream
->stream_fd
->fd
, metadata_struct
->payload
,
1572 if (size_ret
< payload_size
) {
1573 ERR("Relay error writing metadata on file");
1578 size_ret
= write_padding_to_file(metadata_stream
->stream_fd
->fd
,
1579 be32toh(metadata_struct
->padding_size
));
1584 metadata_stream
->metadata_received
+=
1585 payload_size
+ be32toh(metadata_struct
->padding_size
);
1586 DBG2("Relay metadata written. Updated metadata_received %" PRIu64
,
1587 metadata_stream
->metadata_received
);
1590 pthread_mutex_unlock(&metadata_stream
->lock
);
1591 stream_put(metadata_stream
);
1597 * relay_send_version: send relayd version number
1599 static int relay_send_version(struct lttcomm_relayd_hdr
*recv_hdr
,
1600 struct relay_connection
*conn
)
1603 struct lttcomm_relayd_version reply
, msg
;
1605 conn
->version_check_done
= 1;
1607 /* Get version from the other side. */
1608 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1609 if (ret
< 0 || ret
!= sizeof(msg
)) {
1611 /* Orderly shutdown. Not necessary to print an error. */
1612 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1614 ERR("Relay failed to receive the version values.");
1620 memset(&reply
, 0, sizeof(reply
));
1621 reply
.major
= RELAYD_VERSION_COMM_MAJOR
;
1622 reply
.minor
= RELAYD_VERSION_COMM_MINOR
;
1624 /* Major versions must be the same */
1625 if (reply
.major
!= be32toh(msg
.major
)) {
1626 DBG("Incompatible major versions (%u vs %u), deleting session",
1627 reply
.major
, be32toh(msg
.major
));
1628 connection_put(conn
);
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");
1649 DBG("Version check done using protocol %u.%u", conn
->major
,
1657 * Check for data pending for a given stream id from the session daemon.
1659 static int relay_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1660 struct relay_connection
*conn
)
1662 struct relay_session
*session
= conn
->session
;
1663 struct lttcomm_relayd_data_pending msg
;
1664 struct lttcomm_relayd_generic_reply reply
;
1665 struct relay_stream
*stream
;
1667 uint64_t last_net_seq_num
, stream_id
;
1669 DBG("Data pending command received");
1671 if (!session
|| conn
->version_check_done
== 0) {
1672 ERR("Trying to check for data before version check");
1674 goto end_no_session
;
1677 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1678 if (ret
< sizeof(msg
)) {
1680 /* Orderly shutdown. Not necessary to print an error. */
1681 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1683 ERR("Relay didn't receive valid data_pending struct size : %d",
1687 goto end_no_session
;
1690 stream_id
= be64toh(msg
.stream_id
);
1691 last_net_seq_num
= be64toh(msg
.last_net_seq_num
);
1693 stream
= stream_get_by_id(stream_id
);
1694 if (stream
== NULL
) {
1699 pthread_mutex_lock(&stream
->lock
);
1701 DBG("Data pending for stream id %" PRIu64
" prev_seq %" PRIu64
1702 " and last_seq %" PRIu64
, stream_id
, stream
->prev_seq
,
1705 /* Avoid wrapping issue */
1706 if (((int64_t) (stream
->prev_seq
- last_net_seq_num
)) >= 0) {
1707 /* Data has in fact been written and is NOT pending */
1710 /* Data still being streamed thus pending */
1714 stream
->data_pending_check_done
= true;
1715 pthread_mutex_unlock(&stream
->lock
);
1720 memset(&reply
, 0, sizeof(reply
));
1721 reply
.ret_code
= htobe32(ret
);
1722 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1724 ERR("Relay data pending ret code failed");
1732 * Wait for the control socket to reach a quiescent state.
1734 * Note that for now, when receiving this command from the session
1735 * daemon, this means that every subsequent commands or data received on
1736 * the control socket has been handled. So, this is why we simply return
1739 static int relay_quiescent_control(struct lttcomm_relayd_hdr
*recv_hdr
,
1740 struct relay_connection
*conn
)
1744 struct relay_stream
*stream
;
1745 struct lttcomm_relayd_quiescent_control msg
;
1746 struct lttcomm_relayd_generic_reply reply
;
1748 DBG("Checking quiescent state on control socket");
1750 if (!conn
->session
|| conn
->version_check_done
== 0) {
1751 ERR("Trying to check for data before version check");
1753 goto end_no_session
;
1756 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1757 if (ret
< sizeof(msg
)) {
1759 /* Orderly shutdown. Not necessary to print an error. */
1760 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1762 ERR("Relay didn't receive valid begin data_pending struct size: %d",
1766 goto end_no_session
;
1769 stream_id
= be64toh(msg
.stream_id
);
1770 stream
= stream_get_by_id(stream_id
);
1774 pthread_mutex_lock(&stream
->lock
);
1775 stream
->data_pending_check_done
= true;
1776 pthread_mutex_unlock(&stream
->lock
);
1777 DBG("Relay quiescent control pending flag set to %" PRIu64
, stream_id
);
1780 memset(&reply
, 0, sizeof(reply
));
1781 reply
.ret_code
= htobe32(LTTNG_OK
);
1782 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1784 ERR("Relay data quiescent control ret code failed");
1792 * Initialize a data pending command. This means that a consumer is about
1793 * to ask for data pending for each stream it holds. Simply iterate over
1794 * all streams of a session and set the data_pending_check_done flag.
1796 * This command returns to the client a LTTNG_OK code.
1798 static int relay_begin_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1799 struct relay_connection
*conn
)
1802 struct lttng_ht_iter iter
;
1803 struct lttcomm_relayd_begin_data_pending msg
;
1804 struct lttcomm_relayd_generic_reply reply
;
1805 struct relay_stream
*stream
;
1806 uint64_t session_id
;
1811 DBG("Init streams for data pending");
1813 if (!conn
->session
|| conn
->version_check_done
== 0) {
1814 ERR("Trying to check for data before version check");
1816 goto end_no_session
;
1819 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1820 if (ret
< sizeof(msg
)) {
1822 /* Orderly shutdown. Not necessary to print an error. */
1823 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1825 ERR("Relay didn't receive valid begin data_pending struct size: %d",
1829 goto end_no_session
;
1832 session_id
= be64toh(msg
.session_id
);
1835 * Iterate over all streams to set the begin data pending flag.
1836 * For now, the streams are indexed by stream handle so we have
1837 * to iterate over all streams to find the one associated with
1838 * the right session_id.
1841 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1843 if (!stream_get(stream
)) {
1846 if (stream
->trace
->session
->id
== session_id
) {
1847 pthread_mutex_lock(&stream
->lock
);
1848 stream
->data_pending_check_done
= false;
1849 pthread_mutex_unlock(&stream
->lock
);
1850 DBG("Set begin data pending flag to stream %" PRIu64
,
1851 stream
->stream_handle
);
1857 memset(&reply
, 0, sizeof(reply
));
1858 /* All good, send back reply. */
1859 reply
.ret_code
= htobe32(LTTNG_OK
);
1861 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1863 ERR("Relay begin data pending send reply failed");
1871 * End data pending command. This will check, for a given session id, if
1872 * each stream associated with it has its data_pending_check_done flag
1873 * set. If not, this means that the client lost track of the stream but
1874 * the data is still being streamed on our side. In this case, we inform
1875 * the client that data is in flight.
1877 * Return to the client if there is data in flight or not with a ret_code.
1879 static int relay_end_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1880 struct relay_connection
*conn
)
1883 struct lttng_ht_iter iter
;
1884 struct lttcomm_relayd_end_data_pending msg
;
1885 struct lttcomm_relayd_generic_reply reply
;
1886 struct relay_stream
*stream
;
1887 uint64_t session_id
;
1888 uint32_t is_data_inflight
= 0;
1890 DBG("End data pending command");
1892 if (!conn
->session
|| conn
->version_check_done
== 0) {
1893 ERR("Trying to check for data before version check");
1895 goto end_no_session
;
1898 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1899 if (ret
< sizeof(msg
)) {
1901 /* Orderly shutdown. Not necessary to print an error. */
1902 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1904 ERR("Relay didn't receive valid end data_pending struct size: %d",
1908 goto end_no_session
;
1911 session_id
= be64toh(msg
.session_id
);
1914 * Iterate over all streams to see if the begin data pending
1918 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1920 if (!stream_get(stream
)) {
1923 if (stream
->trace
->session
->id
!= session_id
) {
1927 pthread_mutex_lock(&stream
->lock
);
1928 if (!stream
->data_pending_check_done
) {
1929 if (!stream
->closed
|| !(((int64_t) (stream
->prev_seq
- stream
->last_net_seq_num
)) >= 0)) {
1930 is_data_inflight
= 1;
1931 DBG("Data is still in flight for stream %" PRIu64
,
1932 stream
->stream_handle
);
1933 pthread_mutex_unlock(&stream
->lock
);
1938 pthread_mutex_unlock(&stream
->lock
);
1943 memset(&reply
, 0, sizeof(reply
));
1944 /* All good, send back reply. */
1945 reply
.ret_code
= htobe32(is_data_inflight
);
1947 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1949 ERR("Relay end data pending send reply failed");
1957 * Receive an index for a specific stream.
1959 * Return 0 on success else a negative value.
1961 static int relay_recv_index(struct lttcomm_relayd_hdr
*recv_hdr
,
1962 struct relay_connection
*conn
)
1965 struct relay_session
*session
= conn
->session
;
1966 struct lttcomm_relayd_index index_info
;
1967 struct relay_index
*index
;
1968 struct lttcomm_relayd_generic_reply reply
;
1969 struct relay_stream
*stream
;
1970 uint64_t net_seq_num
;
1975 DBG("Relay receiving index");
1977 if (!session
|| conn
->version_check_done
== 0) {
1978 ERR("Trying to close a stream before version check");
1980 goto end_no_session
;
1983 msg_len
= lttcomm_relayd_index_len(
1984 lttng_to_index_major(conn
->major
, conn
->minor
),
1985 lttng_to_index_minor(conn
->major
, conn
->minor
));
1986 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &index_info
,
1988 if (ret
< msg_len
) {
1990 /* Orderly shutdown. Not necessary to print an error. */
1991 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1993 ERR("Relay didn't receive valid index struct size : %d", ret
);
1996 goto end_no_session
;
1999 net_seq_num
= be64toh(index_info
.net_seq_num
);
2001 stream
= stream_get_by_id(be64toh(index_info
.relay_stream_id
));
2003 ERR("stream_get_by_id not found");
2007 pthread_mutex_lock(&stream
->lock
);
2009 /* Live beacon handling */
2010 if (index_info
.packet_size
== 0) {
2011 DBG("Received live beacon for stream %" PRIu64
,
2012 stream
->stream_handle
);
2015 * Only flag a stream inactive when it has already
2016 * received data and no indexes are in flight.
2018 if (stream
->index_received_seqcount
> 0
2019 && stream
->indexes_in_flight
== 0) {
2020 stream
->beacon_ts_end
=
2021 be64toh(index_info
.timestamp_end
);
2024 goto end_stream_put
;
2026 stream
->beacon_ts_end
= -1ULL;
2029 if (stream
->ctf_stream_id
== -1ULL) {
2030 stream
->ctf_stream_id
= be64toh(index_info
.stream_id
);
2032 index
= relay_index_get_by_id_or_create(stream
, net_seq_num
);
2035 ERR("relay_index_get_by_id_or_create index NULL");
2036 goto end_stream_put
;
2038 if (set_index_control_data(index
, &index_info
, conn
)) {
2039 ERR("set_index_control_data error");
2040 relay_index_put(index
);
2042 goto end_stream_put
;
2044 ret
= relay_index_try_flush(index
);
2046 tracefile_array_commit_seq(stream
->tfa
);
2047 stream
->index_received_seqcount
++;
2048 } else if (ret
> 0) {
2052 ERR("relay_index_try_flush error %d", ret
);
2053 relay_index_put(index
);
2058 pthread_mutex_unlock(&stream
->lock
);
2063 memset(&reply
, 0, sizeof(reply
));
2065 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
2067 reply
.ret_code
= htobe32(LTTNG_OK
);
2069 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
2071 ERR("Relay sending close index id reply");
2080 * Receive the streams_sent message.
2082 * Return 0 on success else a negative value.
2084 static int relay_streams_sent(struct lttcomm_relayd_hdr
*recv_hdr
,
2085 struct relay_connection
*conn
)
2088 struct lttcomm_relayd_generic_reply reply
;
2092 DBG("Relay receiving streams_sent");
2094 if (!conn
->session
|| conn
->version_check_done
== 0) {
2095 ERR("Trying to close a stream before version check");
2097 goto end_no_session
;
2101 * Publish every pending stream in the connection recv list which are
2102 * now ready to be used by the viewer.
2104 publish_connection_local_streams(conn
);
2106 memset(&reply
, 0, sizeof(reply
));
2107 reply
.ret_code
= htobe32(LTTNG_OK
);
2108 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
2110 ERR("Relay sending sent_stream reply");
2122 * Process the commands received on the control socket
2124 static int relay_process_control(struct lttcomm_relayd_hdr
*recv_hdr
,
2125 struct relay_connection
*conn
)
2129 switch (be32toh(recv_hdr
->cmd
)) {
2130 case RELAYD_CREATE_SESSION
:
2131 ret
= relay_create_session(recv_hdr
, conn
);
2133 case RELAYD_ADD_STREAM
:
2134 ret
= relay_add_stream(recv_hdr
, conn
);
2136 case RELAYD_START_DATA
:
2137 ret
= relay_start(recv_hdr
, conn
);
2139 case RELAYD_SEND_METADATA
:
2140 ret
= relay_recv_metadata(recv_hdr
, conn
);
2142 case RELAYD_VERSION
:
2143 ret
= relay_send_version(recv_hdr
, conn
);
2145 case RELAYD_CLOSE_STREAM
:
2146 ret
= relay_close_stream(recv_hdr
, conn
);
2148 case RELAYD_DATA_PENDING
:
2149 ret
= relay_data_pending(recv_hdr
, conn
);
2151 case RELAYD_QUIESCENT_CONTROL
:
2152 ret
= relay_quiescent_control(recv_hdr
, conn
);
2154 case RELAYD_BEGIN_DATA_PENDING
:
2155 ret
= relay_begin_data_pending(recv_hdr
, conn
);
2157 case RELAYD_END_DATA_PENDING
:
2158 ret
= relay_end_data_pending(recv_hdr
, conn
);
2160 case RELAYD_SEND_INDEX
:
2161 ret
= relay_recv_index(recv_hdr
, conn
);
2163 case RELAYD_STREAMS_SENT
:
2164 ret
= relay_streams_sent(recv_hdr
, conn
);
2166 case RELAYD_RESET_METADATA
:
2167 ret
= relay_reset_metadata(recv_hdr
, conn
);
2169 case RELAYD_UPDATE_SYNC_INFO
:
2171 ERR("Received unknown command (%u)", be32toh(recv_hdr
->cmd
));
2172 relay_unknown_command(conn
);
2182 * Handle index for a data stream.
2184 * Called with the stream lock held.
2186 * Return 0 on success else a negative value.
2188 static int handle_index_data(struct relay_stream
*stream
, uint64_t net_seq_num
,
2192 uint64_t data_offset
;
2193 struct relay_index
*index
;
2195 /* Get data offset because we are about to update the index. */
2196 data_offset
= htobe64(stream
->tracefile_size_current
);
2198 DBG("handle_index_data: stream %" PRIu64
" net_seq_num %" PRIu64
" data offset %" PRIu64
,
2199 stream
->stream_handle
, net_seq_num
, stream
->tracefile_size_current
);
2202 * Lookup for an existing index for that stream id/sequence
2203 * number. If it exists, the control thread has already received the
2204 * data for it, thus we need to write it to disk.
2206 index
= relay_index_get_by_id_or_create(stream
, net_seq_num
);
2212 if (rotate_index
|| !stream
->index_file
) {
2213 uint32_t major
, minor
;
2215 /* Put ref on previous index_file. */
2216 if (stream
->index_file
) {
2217 lttng_index_file_put(stream
->index_file
);
2218 stream
->index_file
= NULL
;
2220 major
= stream
->trace
->session
->major
;
2221 minor
= stream
->trace
->session
->minor
;
2222 stream
->index_file
= lttng_index_file_create(stream
->path_name
,
2223 stream
->channel_name
,
2224 -1, -1, stream
->tracefile_size
,
2225 tracefile_array_get_file_index_head(stream
->tfa
),
2226 lttng_to_index_major(major
, minor
),
2227 lttng_to_index_minor(major
, minor
));
2228 if (!stream
->index_file
) {
2230 /* Put self-ref for this index due to error. */
2231 relay_index_put(index
);
2237 if (relay_index_set_file(index
, stream
->index_file
, data_offset
)) {
2239 /* Put self-ref for this index due to error. */
2240 relay_index_put(index
);
2245 ret
= relay_index_try_flush(index
);
2247 tracefile_array_commit_seq(stream
->tfa
);
2248 stream
->index_received_seqcount
++;
2249 } else if (ret
> 0) {
2253 /* Put self-ref for this index due to error. */
2254 relay_index_put(index
);
2263 * relay_process_data: Process the data received on the data socket
2265 static int relay_process_data(struct relay_connection
*conn
)
2267 int ret
= 0, rotate_index
= 0;
2269 struct relay_stream
*stream
;
2270 struct lttcomm_relayd_data_hdr data_hdr
;
2272 uint64_t net_seq_num
;
2274 struct relay_session
*session
;
2275 bool new_stream
= false, close_requested
= false;
2276 size_t chunk_size
= RECV_DATA_BUFFER_SIZE
;
2277 size_t recv_off
= 0;
2278 char data_buffer
[chunk_size
];
2280 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &data_hdr
,
2281 sizeof(struct lttcomm_relayd_data_hdr
), 0);
2284 /* Orderly shutdown. Not necessary to print an error. */
2285 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
2287 ERR("Unable to receive data header on sock %d", conn
->sock
->fd
);
2293 stream_id
= be64toh(data_hdr
.stream_id
);
2294 stream
= stream_get_by_id(stream_id
);
2296 ERR("relay_process_data: Cannot find stream %" PRIu64
, stream_id
);
2300 session
= stream
->trace
->session
;
2301 data_size
= be32toh(data_hdr
.data_size
);
2303 net_seq_num
= be64toh(data_hdr
.net_seq_num
);
2305 DBG3("Receiving data of size %u for stream id %" PRIu64
" seqnum %" PRIu64
,
2306 data_size
, stream_id
, net_seq_num
);
2308 pthread_mutex_lock(&stream
->lock
);
2310 /* Check if a rotation is needed. */
2311 if (stream
->tracefile_size
> 0 &&
2312 (stream
->tracefile_size_current
+ data_size
) >
2313 stream
->tracefile_size
) {
2314 uint64_t old_id
, new_id
;
2316 old_id
= tracefile_array_get_file_index_head(stream
->tfa
);
2317 tracefile_array_file_rotate(stream
->tfa
);
2319 /* new_id is updated by utils_rotate_stream_file. */
2322 ret
= utils_rotate_stream_file(stream
->path_name
,
2323 stream
->channel_name
, stream
->tracefile_size
,
2324 stream
->tracefile_count
, -1,
2325 -1, stream
->stream_fd
->fd
,
2326 &new_id
, &stream
->stream_fd
->fd
);
2328 ERR("Rotating stream output file");
2329 goto end_stream_unlock
;
2332 * Reset current size because we just performed a stream
2335 stream
->tracefile_size_current
= 0;
2340 * Index are handled in protocol version 2.4 and above. Also,
2341 * snapshot and index are NOT supported.
2343 if (session
->minor
>= 4 && !session
->snapshot
) {
2344 ret
= handle_index_data(stream
, net_seq_num
, rotate_index
);
2346 ERR("handle_index_data: fail stream %" PRIu64
" net_seq_num %" PRIu64
" ret %d",
2347 stream
->stream_handle
, net_seq_num
, ret
);
2348 goto end_stream_unlock
;
2352 for (recv_off
= 0; recv_off
< data_size
; recv_off
+= chunk_size
) {
2353 size_t recv_size
= min(data_size
- recv_off
, chunk_size
);
2355 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, data_buffer
, recv_size
, 0);
2358 /* Orderly shutdown. Not necessary to print an error. */
2359 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
2361 ERR("Socket %d error %d", conn
->sock
->fd
, ret
);
2364 goto end_stream_unlock
;
2367 /* Write data to stream output fd. */
2368 size_ret
= lttng_write(stream
->stream_fd
->fd
, data_buffer
,
2370 if (size_ret
< recv_size
) {
2371 ERR("Relay error writing data to file");
2373 goto end_stream_unlock
;
2376 DBG2("Relay wrote %zd bytes to tracefile for stream id %" PRIu64
,
2377 size_ret
, stream
->stream_handle
);
2380 ret
= write_padding_to_file(stream
->stream_fd
->fd
,
2381 be32toh(data_hdr
.padding_size
));
2383 ERR("write_padding_to_file: fail stream %" PRIu64
" net_seq_num %" PRIu64
" ret %d",
2384 stream
->stream_handle
, net_seq_num
, ret
);
2385 goto end_stream_unlock
;
2387 stream
->tracefile_size_current
+=
2388 data_size
+ be32toh(data_hdr
.padding_size
);
2389 if (stream
->prev_seq
== -1ULL) {
2393 stream
->prev_seq
= net_seq_num
;
2396 close_requested
= stream
->close_requested
;
2397 pthread_mutex_unlock(&stream
->lock
);
2398 if (close_requested
) {
2399 try_stream_close(stream
);
2403 pthread_mutex_lock(&session
->lock
);
2404 uatomic_set(&session
->new_streams
, 1);
2405 pthread_mutex_unlock(&session
->lock
);
2412 static void cleanup_connection_pollfd(struct lttng_poll_event
*events
, int pollfd
)
2416 (void) lttng_poll_del(events
, pollfd
);
2418 ret
= close(pollfd
);
2420 ERR("Closing pollfd %d", pollfd
);
2424 static void relay_thread_close_connection(struct lttng_poll_event
*events
,
2425 int pollfd
, struct relay_connection
*conn
)
2427 const char *type_str
;
2429 switch (conn
->type
) {
2434 type_str
= "Control";
2436 case RELAY_VIEWER_COMMAND
:
2437 type_str
= "Viewer Command";
2439 case RELAY_VIEWER_NOTIFICATION
:
2440 type_str
= "Viewer Notification";
2443 type_str
= "Unknown";
2445 cleanup_connection_pollfd(events
, pollfd
);
2446 connection_put(conn
);
2447 DBG("%s connection closed with %d", type_str
, pollfd
);
2451 * This thread does the actual work
2453 static void *relay_thread_worker(void *data
)
2455 int ret
, err
= -1, last_seen_data_fd
= -1;
2457 struct lttng_poll_event events
;
2458 struct lttng_ht
*relay_connections_ht
;
2459 struct lttng_ht_iter iter
;
2460 struct lttcomm_relayd_hdr recv_hdr
;
2461 struct relay_connection
*destroy_conn
= NULL
;
2463 DBG("[thread] Relay worker started");
2465 rcu_register_thread();
2467 health_register(health_relayd
, HEALTH_RELAYD_TYPE_WORKER
);
2469 if (testpoint(relayd_thread_worker
)) {
2470 goto error_testpoint
;
2473 health_code_update();
2475 /* table of connections indexed on socket */
2476 relay_connections_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2477 if (!relay_connections_ht
) {
2478 goto relay_connections_ht_error
;
2481 ret
= create_thread_poll_set(&events
, 2);
2483 goto error_poll_create
;
2486 ret
= lttng_poll_add(&events
, relay_conn_pipe
[0], LPOLLIN
| LPOLLRDHUP
);
2493 int idx
= -1, i
, seen_control
= 0, last_notdel_data_fd
= -1;
2495 health_code_update();
2497 /* Infinite blocking call, waiting for transmission */
2498 DBG3("Relayd worker thread polling...");
2499 health_poll_entry();
2500 ret
= lttng_poll_wait(&events
, -1);
2504 * Restart interrupted system call.
2506 if (errno
== EINTR
) {
2515 * Process control. The control connection is
2516 * prioritized so we don't starve it with high
2517 * throughput tracing data on the data connection.
2519 for (i
= 0; i
< nb_fd
; i
++) {
2520 /* Fetch once the poll data */
2521 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
2522 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2524 health_code_update();
2528 * No activity for this FD (poll
2534 /* Thread quit pipe has been closed. Killing thread. */
2535 ret
= check_thread_quit_pipe(pollfd
, revents
);
2541 /* Inspect the relay conn pipe for new connection */
2542 if (pollfd
== relay_conn_pipe
[0]) {
2543 if (revents
& LPOLLIN
) {
2544 struct relay_connection
*conn
;
2546 ret
= lttng_read(relay_conn_pipe
[0], &conn
, sizeof(conn
));
2550 lttng_poll_add(&events
, conn
->sock
->fd
,
2551 LPOLLIN
| LPOLLRDHUP
);
2552 connection_ht_add(relay_connections_ht
, conn
);
2553 DBG("Connection socket %d added", conn
->sock
->fd
);
2554 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2555 ERR("Relay connection pipe error");
2558 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
2562 struct relay_connection
*ctrl_conn
;
2564 ctrl_conn
= connection_get_by_sock(relay_connections_ht
, pollfd
);
2565 /* If not found, there is a synchronization issue. */
2568 if (ctrl_conn
->type
== RELAY_DATA
) {
2569 if (revents
& LPOLLIN
) {
2571 * Flag the last seen data fd not deleted. It will be
2572 * used as the last seen fd if any fd gets deleted in
2575 last_notdel_data_fd
= pollfd
;
2577 goto put_ctrl_connection
;
2579 assert(ctrl_conn
->type
== RELAY_CONTROL
);
2581 if (revents
& LPOLLIN
) {
2582 ret
= ctrl_conn
->sock
->ops
->recvmsg(ctrl_conn
->sock
,
2583 &recv_hdr
, sizeof(recv_hdr
), 0);
2585 /* Connection closed */
2586 relay_thread_close_connection(&events
, pollfd
,
2589 ret
= relay_process_control(&recv_hdr
, ctrl_conn
);
2591 /* Clear the session on error. */
2592 relay_thread_close_connection(&events
,
2597 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2598 relay_thread_close_connection(&events
,
2600 if (last_seen_data_fd
== pollfd
) {
2601 last_seen_data_fd
= last_notdel_data_fd
;
2604 ERR("Unexpected poll events %u for control sock %d",
2606 connection_put(ctrl_conn
);
2609 put_ctrl_connection
:
2610 connection_put(ctrl_conn
);
2615 * The last loop handled a control request, go back to poll to make
2616 * sure we prioritise the control socket.
2622 if (last_seen_data_fd
>= 0) {
2623 for (i
= 0; i
< nb_fd
; i
++) {
2624 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2626 health_code_update();
2628 if (last_seen_data_fd
== pollfd
) {
2635 /* Process data connection. */
2636 for (i
= idx
+ 1; i
< nb_fd
; i
++) {
2637 /* Fetch the poll data. */
2638 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
2639 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2640 struct relay_connection
*data_conn
;
2642 health_code_update();
2645 /* No activity for this FD (poll implementation). */
2649 /* Skip the command pipe. It's handled in the first loop. */
2650 if (pollfd
== relay_conn_pipe
[0]) {
2654 data_conn
= connection_get_by_sock(relay_connections_ht
, pollfd
);
2656 /* Skip it. Might be removed before. */
2659 if (data_conn
->type
== RELAY_CONTROL
) {
2660 goto put_data_connection
;
2662 assert(data_conn
->type
== RELAY_DATA
);
2664 if (revents
& LPOLLIN
) {
2665 ret
= relay_process_data(data_conn
);
2666 /* Connection closed */
2668 relay_thread_close_connection(&events
, pollfd
,
2671 * Every goto restart call sets the last seen fd where
2672 * here we don't really care since we gracefully
2673 * continue the loop after the connection is deleted.
2676 /* Keep last seen port. */
2677 last_seen_data_fd
= pollfd
;
2678 connection_put(data_conn
);
2681 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2682 relay_thread_close_connection(&events
, pollfd
,
2685 ERR("Unknown poll events %u for data sock %d",
2688 put_data_connection
:
2689 connection_put(data_conn
);
2691 last_seen_data_fd
= -1;
2694 /* Normal exit, no error */
2699 /* Cleanup reamaining connection object. */
2701 cds_lfht_for_each_entry(relay_connections_ht
->ht
, &iter
.iter
,
2704 health_code_update();
2706 if (session_abort(destroy_conn
->session
)) {
2711 * No need to grab another ref, because we own
2714 relay_thread_close_connection(&events
, destroy_conn
->sock
->fd
,
2719 lttng_poll_clean(&events
);
2721 lttng_ht_destroy(relay_connections_ht
);
2722 relay_connections_ht_error
:
2723 /* Close relay conn pipes */
2724 utils_close_pipe(relay_conn_pipe
);
2726 DBG("Thread exited with error");
2728 DBG("Worker thread cleanup complete");
2732 ERR("Health error occurred in %s", __func__
);
2734 health_unregister(health_relayd
);
2735 rcu_unregister_thread();
2736 lttng_relay_stop_threads();
2741 * Create the relay command pipe to wake thread_manage_apps.
2742 * Closed in cleanup().
2744 static int create_relay_conn_pipe(void)
2748 ret
= utils_create_pipe_cloexec(relay_conn_pipe
);
2756 int main(int argc
, char **argv
)
2758 int ret
= 0, retval
= 0;
2761 /* Parse arguments */
2763 if (set_options(argc
, argv
)) {
2768 if (set_signal_handler()) {
2773 /* Try to create directory if -o, --output is specified. */
2774 if (opt_output_path
) {
2775 if (*opt_output_path
!= '/') {
2776 ERR("Please specify an absolute path for -o, --output PATH");
2781 ret
= utils_mkdir_recursive(opt_output_path
, S_IRWXU
| S_IRWXG
,
2784 ERR("Unable to create %s", opt_output_path
);
2791 if (opt_daemon
|| opt_background
) {
2794 ret
= lttng_daemonize(&child_ppid
, &recv_child_signal
,
2802 * We are in the child. Make sure all other file
2803 * descriptors are closed, in case we are called with
2804 * more opened file descriptors than the standard ones.
2806 for (i
= 3; i
< sysconf(_SC_OPEN_MAX
); i
++) {
2811 /* Initialize thread health monitoring */
2812 health_relayd
= health_app_create(NR_HEALTH_RELAYD_TYPES
);
2813 if (!health_relayd
) {
2814 PERROR("health_app_create error");
2816 goto exit_health_app_create
;
2819 /* Create thread quit pipe */
2820 if (init_thread_quit_pipe()) {
2822 goto exit_init_data
;
2825 /* Setup the thread apps communication pipe. */
2826 if (create_relay_conn_pipe()) {
2828 goto exit_init_data
;
2831 /* Init relay command queue. */
2832 cds_wfcq_init(&relay_conn_queue
.head
, &relay_conn_queue
.tail
);
2834 /* Initialize communication library */
2836 lttcomm_inet_init();
2838 /* tables of sessions indexed by session ID */
2839 sessions_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2842 goto exit_init_data
;
2845 /* tables of streams indexed by stream ID */
2846 relay_streams_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2847 if (!relay_streams_ht
) {
2849 goto exit_init_data
;
2852 /* tables of streams indexed by stream ID */
2853 viewer_streams_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2854 if (!viewer_streams_ht
) {
2856 goto exit_init_data
;
2859 ret
= utils_create_pipe(health_quit_pipe
);
2862 goto exit_health_quit_pipe
;
2865 /* Create thread to manage the client socket */
2866 ret
= pthread_create(&health_thread
, default_pthread_attr(),
2867 thread_manage_health
, (void *) NULL
);
2870 PERROR("pthread_create health");
2872 goto exit_health_thread
;
2875 /* Setup the dispatcher thread */
2876 ret
= pthread_create(&dispatcher_thread
, default_pthread_attr(),
2877 relay_thread_dispatcher
, (void *) NULL
);
2880 PERROR("pthread_create dispatcher");
2882 goto exit_dispatcher_thread
;
2885 /* Setup the worker thread */
2886 ret
= pthread_create(&worker_thread
, default_pthread_attr(),
2887 relay_thread_worker
, NULL
);
2890 PERROR("pthread_create worker");
2892 goto exit_worker_thread
;
2895 /* Setup the listener thread */
2896 ret
= pthread_create(&listener_thread
, default_pthread_attr(),
2897 relay_thread_listener
, (void *) NULL
);
2900 PERROR("pthread_create listener");
2902 goto exit_listener_thread
;
2905 ret
= relayd_live_create(live_uri
);
2907 ERR("Starting live viewer threads");
2913 * This is where we start awaiting program completion (e.g. through
2914 * signal that asks threads to teardown).
2917 ret
= relayd_live_join();
2923 ret
= pthread_join(listener_thread
, &status
);
2926 PERROR("pthread_join listener_thread");
2930 exit_listener_thread
:
2931 ret
= pthread_join(worker_thread
, &status
);
2934 PERROR("pthread_join worker_thread");
2939 ret
= pthread_join(dispatcher_thread
, &status
);
2942 PERROR("pthread_join dispatcher_thread");
2945 exit_dispatcher_thread
:
2947 ret
= pthread_join(health_thread
, &status
);
2950 PERROR("pthread_join health_thread");
2955 utils_close_pipe(health_quit_pipe
);
2956 exit_health_quit_pipe
:
2959 health_app_destroy(health_relayd
);
2960 exit_health_app_create
:
2963 * Wait for all pending call_rcu work to complete before tearing
2964 * down data structures. call_rcu worker may be trying to
2965 * perform lookups in those structures.
2970 /* Ensure all prior call_rcu are done. */