chiark / gitweb /
tree-wide: make use of fsync_directory_of_file() all over the place
authorLennart Poettering <lennart@poettering.net>
Mon, 19 Feb 2018 17:24:36 +0000 (18:24 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:59:00 +0000 (07:59 +0200)
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
src/libelogind/sd-id128/id128-util.c

index c16ef3b1e0e154e9212e4d917a15d653009a14b9..484355652912dfbb460e43d6293d053ab4964339 100644 (file)
@@ -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;
 }
 
index bdadf3efac47e50485d9ee3f81c72caf14673ca1..95cda29436f076e3b36006d34e920d99095bac46 100644 (file)
@@ -23,6 +23,7 @@
 #include <unistd.h>
 
 #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