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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-08-07 12:29:58 +09:30
parent 98c805e267
commit 1fbe87f6e4

View File

@@ -504,7 +504,8 @@ static bool configfile_replace_var(struct lightningd *ld,
contents = tal_strjoin(tmpctx, take(lines), "\n", STR_TRAIL); contents = tal_strjoin(tmpctx, take(lines), "\n", STR_TRAIL);
if (!write_all(outfd, contents, strlen(contents))) if (!write_all(outfd, contents, strlen(contents)))
fatal("Writing %s: %s", template, strerror(errno)); 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) if (rename(template, cv->file) != 0)
fatal("Renaming %s over %s: %s", fatal("Renaming %s over %s: %s",