]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Clear the cache after a crash
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 6 Dec 2024 19:41:05 +0000 (16:41 -0300)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 6 Dec 2024 19:41:05 +0000 (16:41 -0300)
There are many ways in which a mismatching cache index can cause erratic
behavior that's hard to detect. Since the index is written at the end of
the validation cycle, crashing at any point between a cache refresh and
the index write results in a misindexed cache.

Deleting the index after loading it seems to be a reliable way to force
Fort to reset the cache after a crash.

Terminating signals are still a problem, though.

src/cache.c
src/file.c

index 2b89f7402bc2c805386e04b450a0e9c576524180..f6b8158382bc5cb661b16bbd759a5bcb466a9f17 100644 (file)
@@ -487,6 +487,25 @@ load_index_file(void)
 
        json_decref(root);
        pr_op_debug(INDEX_FILE " loaded.");
+
+       /*
+        * There are many ways in which a mismatching cache index can cause
+        * erratic behavior that's hard to detect. Since the index is written at
+        * the end of the validation cycle, crashing at any point between a
+        * cache refresh and the index write results in a misindexed cache.
+        *
+        * Deleting the index right after loading it seems to be a simple and
+        * reliable way to force Fort to reset the cache after a crash.
+        * (Recovering with an empty cache is safer than with a misindexed one.)
+        */
+       error = file_rm_f(INDEX_FILE);
+       if (error)
+               pr_op_warn("Unable to delete " INDEX_FILE ": %s. "
+                   "This means Fort might not recover properly after a crash. "
+                   "If Fort crashes for some reason, "
+                   "please clear the cache manually before restarting.",
+                   strerror(error));
+
        return 0;
 
 fail:  json_decref(root);
index 970de0ed43df6614114a9e93fad3fe3155277c53..81387a64b61c9422b4552aa968c67e5ba8e189ee 100644 (file)
@@ -180,6 +180,8 @@ file_rm_f(char const *path)
 {
        int error;
 
+       pr_op_debug("rm -f %s", path);
+
        if (remove(path) < 0) {
                error = errno;
                if (error != ENOENT)