relayd: clean-up: reduce the number of exit paths in main()
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 27 Nov 2019 18:20:32 +0000 (13:20 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 30 Jan 2020 06:55:34 +0000 (01:55 -0500)
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 <jeremie.galarneau@efficios.com>
Change-Id: I3195caf05b3dd04cc7e9c60dcb322261159fe0df

src/bin/lttng-relayd/health-relayd.c
src/bin/lttng-relayd/main.c

index 482be8eea92240beb047801eb291b99af3796067..8b2febe05c7e55a53f942d2a4e2a22a917acc2c0 100644 (file)
@@ -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.
index f61f1f13e69ce72eedfc53d3a1941951ae50041c..07e7a012245d5fa0d36fd919f40d00c380070be1 100644 (file)
@@ -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
This page took 0.03183 seconds and 5 git commands to generate.