From: Thibault Godouet Date: Sun, 13 Apr 2014 09:53:41 +0000 (+0100) Subject: file save: sync data before renaming file for extra robustness X-Git-Tag: ver3_1_3~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9a70a687642cd0d2ec4a436b6286d8cfeabde90e;p=thirdparty%2Ffcron.git file save: sync data before renaming file for extra robustness --- diff --git a/save.c b/save.c index 7b5299c..7084c4e 100644 --- a/save.c +++ b/save.c @@ -306,6 +306,16 @@ write_file_to_disk(int fd, struct cf_t *file, time_t time_date) return ERR; } + /* Make sure the data is fully synchronize to disk before files are renamed + * to their final destination. + * This is to avoid cases where the file name (meta-data) would be updated, + * and there is a crash before the data is fully written: not sure if that + * is possible, but better safe than sorry! */ + if (fdatasync(fd) < 0) { + error_e("could not fdatasync() %s's fcrontab", file->cf_user); + return ERR; + } + return OK; }