Browse Source

u-a: Flush the alternatives database file stream before fsync()ing it

For stream I/O the buffers have to be flushed before they are fsync()ed
to guarantee the data has been written, and as such fsync() can do its
job.

Missed in commit 0e0e26cb8e9e3b8e3a60c329d8ea0c6e5445742c.
Guillem Jover 15 years ago
parent
commit
9ccc961518
1 changed files with 2 additions and 0 deletions
  1. 2 0
      utils/update-alternatives.c

+ 2 - 0
utils/update-alternatives.c

@@ -1360,6 +1360,8 @@ alternative_save(struct alternative *a)
 	altdb_print_line(&ctx, "");
 
 	/* Close database file */
+	if (fflush(ctx.fh))
+		syserr(_("unable to flush file '%s'"), ctx.filename);
 	if (fsync(fileno(ctx.fh)))
 		syserr(_("unable to sync file '%s'"), ctx.filename);
 	if (fclose(ctx.fh))