From a4ba42d2345baf3ca5ed245330e126f6a5823023 Mon Sep 17 00:00:00 2001 From: pcarana Date: Wed, 20 May 2020 23:23:20 -0500 Subject: [PATCH] Use common function to get time, try to simplify previous SLURM loading --- src/slurm/db_slurm.c | 10 ++++++++-- src/slurm/db_slurm.h | 2 +- src/slurm/slurm_loader.c | 31 ++++++++++++++++++------------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/slurm/db_slurm.c b/src/slurm/db_slurm.c index a4735107..2a962c0e 100644 --- a/src/slurm/db_slurm.c +++ b/src/slurm/db_slurm.c @@ -444,11 +444,17 @@ db_slurm_foreach_assertion_bgpsec(struct db_slurm *db, bgpsec_foreach_cb cb, return foreach_assertion_bgpsec(&db->lists, cb, arg); } -void +int db_slurm_update_time(struct db_slurm *db) { - db->loaded_date = time(NULL); + int error; + + error = get_current_time(&db->loaded_date); + if (error) + return error; + db->loaded_date_set = true; + return 0; } static int diff --git a/src/slurm/db_slurm.h b/src/slurm/db_slurm.h index c644f8b3..65df53c2 100644 --- a/src/slurm/db_slurm.h +++ b/src/slurm/db_slurm.h @@ -63,7 +63,7 @@ int db_slurm_foreach_assertion_bgpsec(struct db_slurm *, bgpsec_foreach_cb, void *); /* Set the last update to current datetime */ -void db_slurm_update_time(struct db_slurm *); +int db_slurm_update_time(struct db_slurm *); /* Log the DB in human readable form at INFO level */ void db_slurm_log(struct db_slurm *); diff --git a/src/slurm/slurm_loader.c b/src/slurm/slurm_loader.c index 4bac7e89..1912ea08 100644 --- a/src/slurm/slurm_loader.c +++ b/src/slurm/slurm_loader.c @@ -204,17 +204,15 @@ __load_slurm_files(struct db_slurm **last_slurm, int error; error = load_slurm_files(params); - if (error) { - /* Any error: use last valid SLURM */ - pr_op_info("Error loading SLURM, the validation will still continue."); - if (*last_slurm != NULL) { - pr_op_info("A previous valid version of the SLURM exists and will be applied."); - params->db_slurm = *last_slurm; - /* Log applied SLURM as info */ - db_slurm_log(params->db_slurm); - } - destroy_local_csum_list(csum_list); - return; + if (error) + goto use_last_slurm; + + /* Prepare the new SLURM DB */ + if (params->db_slurm != NULL) { + error = db_slurm_update_time(params->db_slurm); + if (error) + goto use_last_slurm; + db_slurm_set_csum_list(params->db_slurm, csum_list); } /* Use new SLURM as last valid slurm */ @@ -222,10 +220,17 @@ __load_slurm_files(struct db_slurm **last_slurm, db_slurm_destroy(*last_slurm); *last_slurm = params->db_slurm; + +use_last_slurm: + /* Any error: use last valid SLURM */ + pr_op_info("Error loading SLURM, the validation will still continue."); if (*last_slurm != NULL) { - db_slurm_update_time(*last_slurm); - db_slurm_set_csum_list(*last_slurm, csum_list); + pr_op_info("A previous valid version of the SLURM exists and will be applied."); + params->db_slurm = *last_slurm; + /* Log applied SLURM as info */ + db_slurm_log(params->db_slurm); } + destroy_local_csum_list(csum_list); } static bool -- 2.47.2