Skip to content

Commit

Permalink
lightningd: use fsync not fdatasync.
Browse files Browse the repository at this point in the history
Apparently MacOS doesn't always have fdatasync, so use fsync.  Even more importantly
check whether it succeeds!

Fixes: ElementsProject#6516
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and litch committed Aug 11, 2023
1 parent 385c05b commit 6faefda
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lightningd/configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6faefda

Please sign in to comment.