From 1fbe87f6e4b5153b1d922e8a857e5e5fbadb0843 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 7 Aug 2023 12:29:58 +0930 Subject: [PATCH] lightningd: use fsync not fdatasync. Apparently MacOS doesn't always have fdatasync, so use fsync. Even more importantly check whether it succeeds! Fixes: #6516 Signed-off-by: Rusty Russell --- lightningd/configs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lightningd/configs.c b/lightningd/configs.c index 65b325a22..564dde853 100644 --- a/lightningd/configs.c +++ b/lightningd/configs.c @@ -504,7 +504,8 @@ static bool configfile_replace_var(struct lightningd *ld, contents = tal_strjoin(tmpctx, take(lines), "\n", STR_TRAIL); if (!write_all(outfd, contents, strlen(contents))) fatal("Writing %s: %s", template, strerror(errno)); - fdatasync(outfd); + if (fsync(outfd) != 0) + fatal("Syncing %s: %s", template, strerror(errno)); if (rename(template, cv->file) != 0) fatal("Renaming %s over %s: %s",