]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Bits of random cleanup
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 2 May 2019 17:45:27 +0000 (12:45 -0500)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 2 May 2019 17:45:27 +0000 (12:45 -0500)
src/main.c
src/nid.c
src/nid.h
src/rtr/db/vrps.c
src/rtr/rtr.c
src/rtr/rtr.h

index f3813e3558befc86b6fd1a931262479d7b9452a0..2051f16d49af3761b3a89ed3cc9c45297476392f 100644 (file)
@@ -26,7 +26,6 @@ start_rtr_server(void)
                goto revert_clients;
 
        error = rtr_listen();
-       rtr_cleanup(); /* TODO shouldn't this only happen on !error? */
 
        slurm_cleanup();
 revert_clients:
@@ -60,12 +59,14 @@ main(int argc, char **argv)
                goto revert_rsync;
        error = extension_init();
        if (error)
-               goto revert_rsync;
+               goto revert_nid;
 
        error = (config_get_server_address() != NULL)
            ? start_rtr_server()
            : validate_into_console();
 
+revert_nid:
+       nid_destroy();
 revert_rsync:
        rsync_destroy();
 revert_config:
index 408f48a10bb8cb2bb2d113b1dc2b54646cbdb587..7bbb148ccfa87d41c47b4926f7b4aa610e8bff8b 100644 (file)
--- a/src/nid.c
+++ b/src/nid.c
@@ -78,6 +78,12 @@ nid_init(void)
        return 0;
 }
 
+void
+nid_destroy(void)
+{
+       OBJ_cleanup();
+}
+
 int nid_rpkiManifest(void)
 {
        return NID_rpkiManifest;
index 64cdac8605fcc8cb5b7f04c11af4ac666f9e6efb..2b34afc1d5edd2248957d35e745debfbd60b14c2 100644 (file)
--- a/src/nid.h
+++ b/src/nid.h
@@ -2,6 +2,7 @@
 #define SRC_NID_H_
 
 int nid_init(void);
+void nid_destroy(void);
 
 int nid_rpkiManifest(void);
 int nid_signedObject(void);
index b5b753ed0d0eb271c9ad8b6a84d96a02f7e2138d..1b2626843cc8fef8fb9e890c6fa6474c21625af4 100644 (file)
@@ -44,7 +44,9 @@ vrps_init(void)
 {
        int error;
 
-       state.base = NULL;
+       state.base = roa_table_create();
+       if (state.base == NULL)
+               return pr_enomem();
 
        deltas_db_init(&state.deltas);
 
@@ -65,6 +67,7 @@ vrps_init(void)
        error = pthread_rwlock_init(&lock, NULL);
        if (error) {
                deltas_db_cleanup(&state.deltas, delta_destroy);
+               roa_table_put(state.base);
                return pr_errno(error, "pthread_rwlock_init() errored");
        }
 
index e8077c935e91b283b1cbc8521c352df59b3d0f19..4662da9ac04ebc1e7a90fddfa1898d6502dd9c28 100644 (file)
@@ -22,6 +22,7 @@
 /* TODO (next iteration) Support both RTR v0 and v1 */
 #define RTR_VERSION_SUPPORTED  RTR_V0
 
+/* TODO (urgent) this needs to be atomic */
 volatile bool loop;
 
 struct thread_node {
@@ -315,6 +316,7 @@ init_signal_handler(void)
        act.sa_flags = SA_SIGINFO;
        act.sa_sigaction = signal_handler;
 
+       /* TODO is this really legal? @act might need to be global. */
        error = sigaction(SIGINT, &act, NULL);
        if (error) {
                pr_errno(errno, "Error initializing signal handler");
@@ -323,6 +325,23 @@ init_signal_handler(void)
        return error;
 }
 
+/* Wait for threads to end gracefully */
+static void
+wait_threads(void)
+{
+       struct thread_node *ptr;
+
+       loop = false;
+       while (!SLIST_EMPTY(&threads)) {
+               ptr = SLIST_FIRST(&threads);
+               SLIST_REMOVE_HEAD(&threads, next);
+               /* TODO interrupt then join? Is this legal? */
+               pthread_kill(ptr->tid, SIGINT);
+               pthread_join(ptr->tid, NULL);
+               free(ptr);
+       }
+}
+
 /*
  * Starts the server, using the current thread to listen for RTR client
  * requests.
@@ -342,7 +361,7 @@ rtr_listen(void)
        /* Server ready, start updates thread */
        error = updates_daemon_start();
        if (error)
-               return error;
+               goto revert_server_socket;
 
        /* Init global vars */
        loop = true;
@@ -350,25 +369,14 @@ rtr_listen(void)
 
        error = init_signal_handler();
        if (error)
-               return error;
-
-       return handle_client_connections(server_fd);
-}
+               goto revert_updates_daemon;
 
-void
-rtr_cleanup(void)
-{
-       struct thread_node *ptr;
+       error = handle_client_connections(server_fd);
 
+       wait_threads();
+revert_updates_daemon:
        updates_daemon_destroy();
-
-       /* Wait for threads to end gracefully */
-       loop = false;
-       while (!SLIST_EMPTY(&threads)) {
-               ptr = SLIST_FIRST(&threads);
-               SLIST_REMOVE_HEAD(&threads, next);
-               pthread_kill(ptr->tid, SIGINT);
-               pthread_join(ptr->tid, NULL);
-               free(ptr);
-       }
+revert_server_socket:
+       close(server_fd);
+       return error;
 }
index 2d445c8d01d733ccef526279aae5e1c12af244e6..7353be96508878469aafff27effb676f4ba2c23a 100644 (file)
@@ -1,9 +1,6 @@
 #ifndef RTR_RTR_H_
 #define RTR_RTR_H_
 
-#include "common.h"
-
 int rtr_listen(void);
-void rtr_cleanup(void);
 
 #endif /* RTR_RTR_H_ */