From cc0978bd85204de787e45a53d4d361dd85d7eea9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Thu, 26 Mar 2009 14:16:55 +0000 Subject: [PATCH] registry: do fsync() before close() and rename() This helps prevent filesystem/data inconsistencies in certain circumstances on certain filesystems (like ext4, xfs, ubifs). Also see bug #562976. --- gst/gstregistrybinary.c | 10 ++++++++++ gst/gstregistryxml.c | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/gst/gstregistrybinary.c b/gst/gstregistrybinary.c index 4849c0b..af98e4b 100644 --- a/gst/gstregistrybinary.c +++ b/gst/gstregistrybinary.c @@ -226,6 +226,10 @@ static gboolean gst_registry_binary_cache_finish (GstRegistry * registry, BinaryRegistryCache * cache, gboolean success) { + /* only fsync if we're actually going to use and rename the file below */ + if (success && fsync (registry->cache_file) < 0) + goto fsync_failed; + if (close (registry->cache_file) < 0) goto close_failed; @@ -240,6 +244,7 @@ gst_registry_binary_cache_finish (GstRegistry * registry, GST_INFO ("Wrote binary registry cache"); return TRUE; +/* ERRORS */ fail_after_close: { g_unlink (cache->tmp_location); @@ -247,6 +252,11 @@ fail_after_close: g_free (cache); return FALSE; } +fsync_failed: + { + GST_ERROR ("fsync() failed: %s", g_strerror (errno)); + goto fail_after_close; + } close_failed: { GST_ERROR ("close() failed: %s", g_strerror (errno)); diff --git a/gst/gstregistryxml.c b/gst/gstregistryxml.c index f402b77..9623cf9 100644 --- a/gst/gstregistryxml.c +++ b/gst/gstregistryxml.c @@ -919,6 +919,9 @@ gst_registry_xml_write_cache (GstRegistry * registry, const char *location) if (!gst_registry_save (registry, "\n")) goto fail; + if (fsync (registry->cache_file) < 0) + goto fsync_failed; + /* check return value of close(), write errors may only get reported here */ if (close (registry->cache_file) < 0) goto close_failed; @@ -949,6 +952,11 @@ fail_after_close: g_free (tmp_location); return FALSE; } +fsync_failed: + { + GST_ERROR ("fsync() failed: %s", g_strerror (errno)); + goto fail_after_close; + } close_failed: { GST_ERROR ("close() failed: %s", g_strerror (errno)); -- 2.7.4