]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Fix bug when applying SLURM, and configure the log level on empty dirs
authorpcarana <pc.moreno2099@gmail.com>
Thu, 4 Jun 2020 23:14:03 +0000 (18:14 -0500)
committerpcarana <pc.moreno2099@gmail.com>
Thu, 4 Jun 2020 23:14:03 +0000 (18:14 -0500)
+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
src/common.h
src/object/tal.c
src/slurm/slurm_loader.c

index 7215b8dd92ccda8c9308456430b6846125aa3291..2059b9ccaba8f9f64da5ca038c3a2a6915ee5efe 100644 (file)
@@ -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);
 }
 
 
index a5392e3aba1200015dcdf184ff59b3ed0894ad90..f4f311be5c2c05fb46a168ab0604c8502e21b660 100644 (file)
@@ -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);
index 9c0841847c1d5f8bacb61dba213715581ca58389..199f33d26854b5c4dcdc8c586c08325fffcdb77a 100644 (file)
@@ -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 */
index 1912ea0886e5c1e17fede9b25a7e9e3dfdbf489c..5f4ceb908112a7c361b5f8cb6f519911b10d94ef 100644 (file)
@@ -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.");