From: pcarana Date: Sat, 28 Mar 2020 00:49:35 +0000 (-0600) Subject: Use static vars, fix unit tests, TAL thread list lives per validation X-Git-Tag: v1.2.1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24009fbaddc2b11fc499c8ccf99216d2e1a20045;p=thirdparty%2FFORT-validator.git Use static vars, fix unit tests, TAL thread list lives per validation --- diff --git a/src/object/tal.c b/src/object/tal.c index fe834cf1..6d482859 100644 --- a/src/object/tal.c +++ b/src/object/tal.c @@ -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); - } -} diff --git a/src/object/tal.h b/src/object/tal.h index 19ff0811..62227535 100644 --- a/src/object/tal.h +++ b/src/object/tal.h @@ -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_ */ diff --git a/src/rtr/db/vrps.c b/src/rtr/db/vrps.c index a54dbc2c..aaf4ef85 100644 --- a/src/rtr/db/vrps.c +++ b/src/rtr/db/vrps.c @@ -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; } diff --git a/src/xml/relax_ng.c b/src/xml/relax_ng.c index 5206d566..ee8d7eae 100644 --- a/src/xml/relax_ng.c +++ b/src/xml/relax_ng.c @@ -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 diff --git a/test/http_test.c b/test/http_test.c index 765b722a..4487fc57 100644 --- a/test/http_test.c +++ b/test/http_test.c @@ -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; } diff --git a/test/rtr/db/rtr_db_impersonator.c b/test/rtr/db/rtr_db_impersonator.c index 158b6336..6d83c526 100644 --- a/test/rtr/db/rtr_db_impersonator.c +++ b/test/rtr/db/rtr_db_impersonator.c @@ -111,9 +111,3 @@ perform_standalone_validation(struct db_table *table) iteration++; return 0; } - -void -terminate_standalone_validation(void) -{ - /* Nothing, no threads to join */ -}