]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
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)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Feb 2018 14:39:31 +0000 (15:39 +0100)
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/boot/bootctl.c
src/coredump/coredump.c
src/libsystemd/sd-id128/id128-util.c

index 26d6174664e6461b55c43d9a5ce46e5d6db2e52d..29b941348aa2f9dc961a326064feb8bac86f8f47 100644 (file)
@@ -1187,6 +1187,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 ae034f5cdb1ba614072a78d2885bb27ea67ac917..37a5f1d63418f2fb9efe26bca554b696611e812c 100644 (file)
@@ -434,12 +434,13 @@ static int copy_file_with_version_check(const char *from, const char *to, bool f
 
         (void) copy_times(fd_from, fd_to);
 
-        r = fsync(fd_to);
-        if (r < 0) {
+        if (fsync(fd_to) < 0) {
                 (void) unlink_noerrno(t);
                 return log_error_errno(errno, "Failed to copy data from \"%s\" to \"%s\": %m", from, t);
         }
 
+        (void) fsync_directory_of_file(fd_to);
+
         r = renameat(AT_FDCWD, t, AT_FDCWD, to);
         if (r < 0) {
                 (void) unlink_noerrno(t);
index 6900af9fb50fac3e1fc24178e5847cfa31545825..e924750d1b457498a94181bc6589dc433aa17486 100644 (file)
@@ -260,6 +260,8 @@ static int fix_permissions(
         if (fsync(fd) < 0)
                 return log_error_errno(errno, "Failed to sync coredump %s: %m", coredump_tmpfile_name(filename));
 
+        (void) fsync_directory_of_file(fd);
+
         r = link_tmpfile(fd, filename, target);
         if (r < 0)
                 return log_error_errno(r, "Failed to move coredump %s into place: %m", target);
index a6e38578b168443976c2c45eb71647ebced7eb40..8ce012e35fabee705eee43ec5ef4d3df077fc355 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;
 }
 
 int id128_write(const char *p, Id128Format f, sd_id128_t id, bool do_sync) {