]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Use static vars, fix unit tests, TAL thread list lives per validation
authorpcarana <pc.moreno2099@gmail.com>
Sat, 28 Mar 2020 00:49:35 +0000 (18:49 -0600)
committerpcarana <pc.moreno2099@gmail.com>
Sat, 28 Mar 2020 00:49:35 +0000 (18:49 -0600)
src/object/tal.c
src/object/tal.h
src/rtr/db/vrps.c
src/xml/relax_ng.c
test/http_test.c
test/rtr/db/rtr_db_impersonator.c

index fe834cf167b90f6de0b90ee553defd985804d92d..6d482859ddc8e2aeb7bcc01824fbe311a0270241 100644 (file)
@@ -43,7 +43,7 @@ struct tal {
        size_t spki_len;
 };
 
-struct fv_param {
+struct pthread_param {
        int *exit_status; /* Return status of the file validation */
        char *tal_file;
        void *arg;
@@ -57,7 +57,12 @@ struct thread {
 };
 
 /* List of threads, one per TAL file */
-SLIST_HEAD(threads_list, thread) threads;
+SLIST_HEAD(threads_list, thread);
+
+struct tal_param {
+       struct db_table *db;
+       struct threads_list *threads;
+};
 
 static int
 uris_init(struct uris *uris)
@@ -566,7 +571,7 @@ end:        validation_destroy(state);
 static void *
 do_file_validation(void *thread_arg)
 {
-       struct fv_param param;
+       struct pthread_param param;
        struct tal *tal;
        int error;
 
@@ -610,8 +615,9 @@ thread_destroy(struct thread *thread)
 static int
 __do_file_validation(char const *tal_file, void *arg)
 {
+       struct tal_param *t_param = arg;
        struct thread *thread;
-       struct fv_param *param;
+       struct pthread_param *p_param;
        static pthread_t pid;
        int *exit_status;
        int error;
@@ -626,17 +632,17 @@ __do_file_validation(char const *tal_file, void *arg)
                goto free_db_rrdp;
        }
 
-       param = malloc(sizeof(struct fv_param));
-       if (param == NULL) {
+       p_param = malloc(sizeof(struct pthread_param));
+       if (p_param == NULL) {
                error = pr_enomem();
                goto free_status;
        }
 
-       param->exit_status = exit_status;
-       param->tal_file = strdup(tal_file);
-       param->arg = arg;
+       p_param->exit_status = exit_status;
+       p_param->tal_file = strdup(tal_file);
+       p_param->arg = t_param->db;
 
-       errno = pthread_create(&pid, NULL, do_file_validation, param);
+       errno = pthread_create(&pid, NULL, do_file_validation, p_param);
        if (errno) {
                error = -pr_errno(errno,
                    "Could not spawn the file validation thread");
@@ -653,12 +659,12 @@ __do_file_validation(char const *tal_file, void *arg)
        thread->pid = pid;
        thread->file = strdup(tal_file);
        thread->exit_status = exit_status;
-       SLIST_INSERT_HEAD(&threads, thread, next);
+       SLIST_INSERT_HEAD(t_param->threads, thread, next);
 
        return 0;
 free_param:
-       free(param->tal_file);
-       free(param);
+       free(p_param->tal_file);
+       free(p_param);
 free_status:
        free(exit_status);
 free_db_rrdp:
@@ -669,17 +675,36 @@ free_db_rrdp:
 int
 perform_standalone_validation(struct db_table *table)
 {
+       struct tal_param *param;
+       struct threads_list threads;
        struct thread *thread;
        int error, t_error;
 
+       param = malloc(sizeof(struct tal_param));
+       if (param == NULL)
+               return pr_enomem();
+
        /* Set existent tal RRDP info to non visited */
        db_rrdp_reset_visited_tals();
 
        SLIST_INIT(&threads);
+
+       param->db = table;
+       param->threads = &threads;
+
        error = process_file_or_dir(config_get_tal(), TAL_FILE_EXTENSION,
-           __do_file_validation, table);
-       if (error)
+           __do_file_validation, param);
+       if (error) {
+               /* End all threads */
+               while (!SLIST_EMPTY(&threads)) {
+                       thread = threads.slh_first;
+                       close_thread(thread->pid, thread->file);
+                       SLIST_REMOVE_HEAD(&threads, next);
+                       thread_destroy(thread);
+               }
+               free(param);
                return error;
+       }
 
        /* Wait for all */
        t_error = 0;
@@ -698,6 +723,9 @@ perform_standalone_validation(struct db_table *table)
                thread_destroy(thread);
        }
 
+       /* The parameter isn't needed anymore */
+       free(param);
+
        /* One thread has errors, validation can't keep the resulting table */
        if (t_error)
                return t_error;
@@ -707,17 +735,3 @@ perform_standalone_validation(struct db_table *table)
 
        return error;
 }
-
-void
-terminate_standalone_validation(void)
-{
-       struct thread *thread;
-
-       /* End all threads */
-       while (!SLIST_EMPTY(&threads)) {
-               thread = threads.slh_first;
-               close_thread(thread->pid, thread->file);
-               SLIST_REMOVE_HEAD(&threads, next);
-               thread_destroy(thread);
-       }
-}
index 19ff0811f2208ea74bdaa205368eb11857ee43ad..62227535b89db68fdb38a6843e6ac6b7134174e5 100644 (file)
@@ -20,6 +20,5 @@ char const *tal_get_file_name(struct tal *);
 void tal_get_spki(struct tal *, unsigned char const **, size_t *);
 
 int perform_standalone_validation(struct db_table *);
-void terminate_standalone_validation(void);
 
 #endif /* TAL_OBJECT_H_ */
index a54dbc2cb8301f7eeb0841ab5b787127a4398d57..aaf4ef85f998b95ae44254f18695c050b8200895 100644 (file)
@@ -60,7 +60,9 @@ struct state {
        serial_t next_serial;
        uint16_t v0_session_id;
        uint16_t v1_session_id;
-} state;
+};
+
+static struct state state;
 
 /** Read/write lock, which protects @state and its inhabitants. */
 static pthread_rwlock_t state_lock;
@@ -182,7 +184,6 @@ __perform_standalone_validation(struct db_table **result)
 
        error = perform_standalone_validation(db);
        if (error) {
-               terminate_standalone_validation();
                db_table_destroy(db);
                return error;
        }
index 5206d566ecabc4edace836ca9863f4f26532971e..ee8d7eae03ff12af9a93d2e58776620711e86e23 100644 (file)
@@ -8,8 +8,8 @@
 
 #include "log.h"
 
-xmlRelaxNGPtr schema;
-xmlRelaxNGParserCtxtPtr rngparser;
+static xmlRelaxNGPtr schema;
+static xmlRelaxNGParserCtxtPtr rngparser;
 
 /* Initialize global schema to parse RRDP files */
 int
index 765b722a90878c9d7387ce2dbbb9d274e134247e..4487fc5742165ac78de3c947b73bb40df7bf9292 100644 (file)
@@ -44,13 +44,15 @@ static int
 local_download(char const *url, long *response_code, struct response *resp)
 {
        struct http_handler handler;
+       long cond;
        int error;
 
+       cond = 0;
        error = http_easy_init(&handler);
        if (error)
                return error;
 
-       error = http_fetch(&handler, url, response_code, write_cb, resp);
+       error = http_fetch(&handler, url, response_code, &cond, write_cb, resp);
        http_easy_cleanup(&handler);
        return error;
 }
index 158b63360461f358ba58f03b3f7d7afa5b996f53..6d83c5266f375b653458f05e91bec04662761a1a 100644 (file)
@@ -111,9 +111,3 @@ perform_standalone_validation(struct db_table *table)
        iteration++;
        return 0;
 }
-
-void
-terminate_standalone_validation(void)
-{
-       /* Nothing, no threads to join */
-}