From: Alberto Leiva Popper Date: Fri, 6 Dec 2024 19:41:05 +0000 (-0300) Subject: Clear the cache after a crash X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0880f8eac3d35e576a2c1a2cb588424ab4b3e1b;p=thirdparty%2FFORT-validator.git Clear the cache after a crash 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. --- diff --git a/src/cache.c b/src/cache.c index 2b89f740..f6b81583 100644 --- a/src/cache.c +++ b/src/cache.c @@ -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); diff --git a/src/file.c b/src/file.c index 970de0ed..81387a64 100644 --- a/src/file.c +++ b/src/file.c @@ -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)