From efe8831b51c6ebeb6f3c1d12e60789352e6ff3d9 Mon Sep 17 00:00:00 2001 From: pcarana Date: Thu, 4 Jun 2020 18:14:03 -0500 Subject: [PATCH] Fix bug when applying SLURM, and configure the log level on empty dirs +The bug was when a SLURM was successfully loaded, instead of stopping the interfal flow on success (a 'return' was needed) it continued to the error flow. This lead to worst errors later, such as segfault when a valid slurm was applied. +Log error whenever the TALs configured directory is empty, log warning if the SLURM directory is empty. --- src/common.c | 14 +++++++++----- src/common.h | 3 ++- src/object/tal.c | 2 +- src/slurm/slurm_loader.c | 6 ++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/common.c b/src/common.c index 7215b8dd..2059b9cc 100644 --- a/src/common.c +++ b/src/common.c @@ -131,7 +131,7 @@ process_file(char const *dir_name, char const *file_name, char const *file_ext, } static int -process_dir_files(char const *location, char const *file_ext, +process_dir_files(char const *location, char const *file_ext, bool empty_err, process_file_cb cb, void *arg) { DIR *dir_loc; @@ -160,8 +160,12 @@ process_dir_files(char const *location, char const *file_ext, error = -errno; } if (!error && found == 0) - pr_op_warn("Location '%s' doesn't have files with extension '%s'", - location, file_ext); + error = (empty_err ? + pr_op_err("Location '%s' doesn't have files with extension '%s'", + location, file_ext) : + pr_op_warn("Location '%s' doesn't have files with extension '%s'", + location, file_ext)); + close_dir: closedir(dir_loc); end: @@ -169,7 +173,7 @@ end: } int -process_file_or_dir(char const *location, char const *file_ext, +process_file_or_dir(char const *location, char const *file_ext, bool empty_err, process_file_cb cb, void *arg) { struct stat attr; @@ -182,7 +186,7 @@ process_file_or_dir(char const *location, char const *file_ext, if (S_ISDIR(attr.st_mode) == 0) return cb(location, arg); - return process_dir_files(location, file_ext, cb, arg); + return process_dir_files(location, file_ext, empty_err, cb, arg); } diff --git a/src/common.h b/src/common.h index a5392e3a..f4f311be 100644 --- a/src/common.h +++ b/src/common.h @@ -52,7 +52,8 @@ void rwlock_unlock(pthread_rwlock_t *); void close_thread(pthread_t thread, char const *); typedef int (*process_file_cb)(char const *, void *); -int process_file_or_dir(char const *, char const *, process_file_cb, void *); +int process_file_or_dir(char const *, char const *, bool, process_file_cb, + void *); typedef int (*pr_errno_cb)(int, const char *, ...); bool valid_file_or_dir(char const *, bool, bool, pr_errno_cb); diff --git a/src/object/tal.c b/src/object/tal.c index 9c084184..199f33d2 100644 --- a/src/object/tal.c +++ b/src/object/tal.c @@ -676,7 +676,7 @@ perform_standalone_validation(struct db_table *table) param->db = table; param->threads = &threads; - error = process_file_or_dir(config_get_tal(), TAL_FILE_EXTENSION, + error = process_file_or_dir(config_get_tal(), TAL_FILE_EXTENSION, true, __do_file_validation, param); if (error) { /* End all threads */ diff --git a/src/slurm/slurm_loader.c b/src/slurm/slurm_loader.c index 1912ea08..5f4ceb90 100644 --- a/src/slurm/slurm_loader.c +++ b/src/slurm/slurm_loader.c @@ -31,7 +31,7 @@ load_slurm_files(struct slurm_parser_params *params) params->db_slurm = db; error = process_file_or_dir(config_get_slurm(), SLURM_FILE_EXTENSION, - slurm_parse, params); + false, slurm_parse, params); if (error) { db_slurm_destroy(db); params->db_slurm = NULL; @@ -184,7 +184,7 @@ slurm_load_checksums(struct slurm_csum_list *csum_list) result.list_size = 0; error = process_file_or_dir(config_get_slurm(), SLURM_FILE_EXTENSION, - __slurm_load_checksums, &result); + false, __slurm_load_checksums, &result); if (error) { destroy_local_csum_list(&result); return error; @@ -221,6 +221,8 @@ __load_slurm_files(struct db_slurm **last_slurm, *last_slurm = params->db_slurm; + return; + use_last_slurm: /* Any error: use last valid SLURM */ pr_op_info("Error loading SLURM, the validation will still continue."); -- 2.47.2