+2018-02-21 Florian Weimer <fweimer@redhat.com>
+
+ [BZ #20890]
+ * elf/cache.c (save_cache): Call fsync on temporary file before
+ renaming it.
+ (save_aux_cache): Call fdatasync on temporary file before renaming
+ it.
+
2018-02-21 Florian Weimer <fweimer@redhat.com>
[BZ #22787]
error (EXIT_FAILURE, errno, _("Writing of cache data failed"));
}
- if (write (fd, strings, total_strlen) != (ssize_t) total_strlen
- || close (fd))
+ if (write (fd, strings, total_strlen) != (ssize_t) total_strlen)
error (EXIT_FAILURE, errno, _("Writing of cache data failed"));
/* Make sure user can always read cache file */
_("Changing access rights of %s to %#o failed"), temp_name,
S_IROTH|S_IRGRP|S_IRUSR|S_IWUSR);
+ /* Make sure that data is written to disk. */
+ if (fsync (fd) != 0 || close (fd) != 0)
+ error (EXIT_FAILURE, errno, _("Writing of cache data failed"));
+
/* Move temporary to its final location. */
if (rename (temp_name, cache_name))
error (EXIT_FAILURE, errno, _("Renaming of %s to %s failed"), temp_name,
if (write (fd, file_entries, file_entries_size + total_strlen)
!= (ssize_t) (file_entries_size + total_strlen)
- || close (fd))
+ || fdatasync (fd) != 0
+ || close (fd) != 0)
{
unlink (temp_name);
goto out_fail;