From: Jérémie Galarneau Date: Wed, 27 Nov 2019 18:20:32 +0000 (-0500) Subject: relayd: clean-up: reduce the number of exit paths in main() X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=794e2e5f064718252b249e17914c9b2b089d8d0c relayd: clean-up: reduce the number of exit paths in main() The relay daemons's initialization and teardown relies on a large number of goto/labels to clean-up on failure to launch. All of the clean-up can be performed unconditionally by checking for NULL or uninitialized file descriptors in relayd_cleanup(). This reduces the number of possible tear-down paths and partly initialized state to keep track of. Signed-off-by: Jérémie Galarneau Change-Id: I3195caf05b3dd04cc7e9c60dcb322261159fe0df --- diff --git a/src/bin/lttng-relayd/health-relayd.c b/src/bin/lttng-relayd/health-relayd.c index 482be8eea..8b2febe05 100644 --- a/src/bin/lttng-relayd/health-relayd.c +++ b/src/bin/lttng-relayd/health-relayd.c @@ -55,7 +55,7 @@ static char health_unix_sock_path[PATH_MAX]; -int health_quit_pipe[2]; +int health_quit_pipe[2] = { -1, -1 }; /* * Check if the thread quit pipe was triggered. diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index f61f1f13e..07e7a0122 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -659,9 +659,18 @@ static void relayd_cleanup(void) free(opt_output_path); free(opt_working_directory); + if (health_relayd) { + health_app_destroy(health_relayd); + } /* Close thread quit pipes */ + utils_close_pipe(health_quit_pipe); utils_close_pipe(thread_quit_pipe); + if (sessiond_trace_chunk_registry) { + sessiond_trace_chunk_registry_destroy( + sessiond_trace_chunk_registry); + } + uri_free(control_uri); uri_free(data_uri); /* Live URI is freed in the live thread. */ @@ -4059,7 +4068,7 @@ int main(int argc, char **argv) if (!sessiond_trace_chunk_registry) { ERR("Failed to initialize session daemon trace chunk registry"); retval = -1; - goto exit_sessiond_trace_chunk_registry; + goto exit_options; } /* Initialize thread health monitoring */ @@ -4067,19 +4076,19 @@ int main(int argc, char **argv) if (!health_relayd) { PERROR("health_app_create error"); retval = -1; - goto exit_health_app_create; + goto exit_options; } /* Create thread quit pipe */ if (init_thread_quit_pipe()) { retval = -1; - goto exit_init_data; + goto exit_options; } /* Setup the thread apps communication pipe. */ if (create_relay_conn_pipe()) { retval = -1; - goto exit_init_data; + goto exit_options; } /* Init relay command queue. */ @@ -4093,27 +4102,27 @@ int main(int argc, char **argv) sessions_ht = lttng_ht_new(0, LTTNG_HT_TYPE_U64); if (!sessions_ht) { retval = -1; - goto exit_init_data; + goto exit_options; } /* tables of streams indexed by stream ID */ relay_streams_ht = lttng_ht_new(0, LTTNG_HT_TYPE_U64); if (!relay_streams_ht) { retval = -1; - goto exit_init_data; + goto exit_options; } /* tables of streams indexed by stream ID */ viewer_streams_ht = lttng_ht_new(0, LTTNG_HT_TYPE_U64); if (!viewer_streams_ht) { retval = -1; - goto exit_init_data; + goto exit_options; } ret = utils_create_pipe(health_quit_pipe); if (ret) { retval = -1; - goto exit_health_quit_pipe; + goto exit_options; } /* Create thread to manage the client socket */ @@ -4123,7 +4132,7 @@ int main(int argc, char **argv) errno = ret; PERROR("pthread_create health"); retval = -1; - goto exit_health_thread; + goto exit_options; } /* Setup the dispatcher thread */ @@ -4204,16 +4213,6 @@ exit_dispatcher_thread: PERROR("pthread_join health_thread"); retval = -1; } -exit_health_thread: - - utils_close_pipe(health_quit_pipe); -exit_health_quit_pipe: - -exit_init_data: - health_app_destroy(health_relayd); - sessiond_trace_chunk_registry_destroy(sessiond_trace_chunk_registry); -exit_health_app_create: -exit_sessiond_trace_chunk_registry: exit_options: /* * Wait for all pending call_rcu work to complete before tearing