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.
if (fsync(fileno(f)) < 0)
return -errno;
+ r = fsync_directory_of_file(fileno(f));
+ if (r < 0)
+ return r;
+
return 0;
}
(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);
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);
#include <unistd.h>
#include "fd-util.h"
+#include "fs-util.h"
#include "hexdecoct.h"
#include "id128-util.h"
#include "io-util.h"
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) {