From: Lennart Poettering Date: Mon, 19 Feb 2018 17:24:36 +0000 (+0100) Subject: tree-wide: make use of fsync_directory_of_file() all over the place X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ca62631389dbc038c84a321f80e303f8903b7ea7;p=elogind.git tree-wide: make use of fsync_directory_of_file() all over the place Let's make use this at various places we call fsync(), to make things fully reliable, as the kernel devs suggest to first fsync() files and then fsync() the directories they are located in. --- diff --git a/src/basic/fileio.c b/src/basic/fileio.c index c16ef3b1e..484355652 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -1193,6 +1193,10 @@ int fflush_sync_and_check(FILE *f) { if (fsync(fileno(f)) < 0) return -errno; + r = fsync_directory_of_file(fileno(f)); + if (r < 0) + return r; + return 0; } diff --git a/src/libelogind/sd-id128/id128-util.c b/src/libelogind/sd-id128/id128-util.c index bdadf3efa..95cda2943 100644 --- a/src/libelogind/sd-id128/id128-util.c +++ b/src/libelogind/sd-id128/id128-util.c @@ -23,6 +23,7 @@ #include #include "fd-util.h" +//#include "fs-util.h" #include "hexdecoct.h" #include "id128-util.h" #include "io-util.h" @@ -180,9 +181,13 @@ int id128_write_fd(int fd, Id128Format f, sd_id128_t id, bool do_sync) { if (do_sync) { if (fsync(fd) < 0) return -errno; + + r = fsync_directory_of_file(fd); + if (r < 0) + return r; } - return r; + return 0; } #if 0 /// UNNEEDED by elogind