]> sourceware.org Git - glibc.git/commitdiff
ldconfig: Sync temporary files to disk before renaming them [BZ #20890]
authorFlorian Weimer <fweimer@redhat.com>
Wed, 21 Feb 2018 09:42:48 +0000 (10:42 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 21 Feb 2018 09:42:48 +0000 (10:42 +0100)
If the system crashes before the file data has been written to disk, the
file system recovery upon the next mount may restore a partially
rewritten temporary file under the non-temporary (final) name (after the
rename operation).

ChangeLog
elf/cache.c

index a56f1fa0ff989d8c834f90c69ed3c5879a4076a8..25b8e1264d36f99fc6240caddc9a1216c150c859 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+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]
index c2c010f97bb23d2b568e6499e5806dac73211da3..e63979da7d25560c4072cca99749e879005c5c2f 100644 (file)
@@ -454,8 +454,7 @@ save_cache (const char *cache_name)
        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 */
@@ -464,6 +463,10 @@ save_cache (const char *cache_name)
           _("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,
@@ -818,7 +821,8 @@ save_aux_cache (const char *aux_cache_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;
This page took 0.087558 seconds and 5 git commands to generate.