Improve crash resilience in Linux

Syncing the directory is a required step to ensure resilience.
Also create the temporary file with O_EXCL to ensure to don't
use a stale copy that may link to the original copy.
This commit is contained in:
Andrea Mazzoleni 2018-06-04 22:14:23 +02:00
parent c696c56df1
commit 473819467f
5 changed files with 87 additions and 6 deletions

View file

@ -112,7 +112,8 @@ int sopen_multi_file(STREAM* s, unsigned i, const char* file)
pathcpy(s->handle[i].path, sizeof(s->handle[i].path), file);
f = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_SEQUENTIAL, 0600);
/* O_EXCL to be resilent ensure to always create a new file and not use a stale link to the original file */
f = open(file, O_WRONLY | O_CREAT | O_EXCL | O_BINARY | O_SEQUENTIAL, 0600);
if (f == -1) {
/* LCOV_EXCL_START */
return -1;