From 25a27560785c447762e2a37a1d4afc377720a2e6 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:48:40 +0100 Subject: [PATCH] Check return value of fsync() and log error --- src/misc_file.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/misc_file.c b/src/misc_file.c index 7d279c4eb..743031411 100644 --- a/src/misc_file.c +++ b/src/misc_file.c @@ -21,6 +21,7 @@ */ #include "main.h" +#include #include #include #include @@ -70,7 +71,8 @@ int copyfile(char *oldpath, char *newpath) } } } - fsync(fo); + if (fsync(fo) < 0) + putlog(LOG_MISC, "*", "copyfile(): Error synchronising changes to file %s: %s", newpath, strerror(errno)); close(fo); close(fi); return 0; @@ -119,7 +121,8 @@ int copyfilef(char *oldpath, FILE *newfile) } } - fsync(fileno(newfile)); + if (fsync(fileno(newfile)) < 0) + putlog(LOG_MISC, "*", "copyfilef(): Error synchronising changes to fd %i: %s", fileno(newfile), strerror(errno)); close(fi); fseeko(newfile, oripos, SEEK_SET); @@ -167,7 +170,8 @@ int fcopyfile(FILE *oldfile, char *newpath) } } - fsync(fo); + if (fsync(fo) < 0); + putlog(LOG_MISC, "*", "fcopyfile(): Error synchronising changes to file %s: %s", newpath, strerror(errno)); close(fo); fseeko(oldfile, oripos, SEEK_SET);