From ca62631389dbc038c84a321f80e303f8903b7ea7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Feb 2018 18:24:36 +0100 Subject: 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. --- src/basic/fileio.c | 4 ++++ src/libelogind/sd-id128/id128-util.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3