summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-08-29 17:13:15 +0300
committerColin Walters <walters@verbum.org>2008-09-04 21:51:52 -0400
commit9680c283586d7165e7482db8c3dcaf2d03e2f0b6 (patch)
treedd0e3ca6b3043de368ae74a6a0f13e5d8bddb686 /dbus
parent1859c66351285de313d1ccd2540e9d71aaf768a3 (diff)
Bug 17352: synchronize the file before renaming
Dbus is doing atomic file updates by copying them, changing the copy, and re-naming them. However, it does not synchronize the file before re-naming, which results in corruption in case of unclean reboots. The reason for this is that file-systems have write-back cache and they postpone writing data to the media. This patch adds the missed fsync() for the Unix part. I do not have windows so cannot provide a windows port fix. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: Colin Walters <walters@verbum.org>
Diffstat (limited to 'dbus')
-rw-r--r--dbus/dbus-sysdeps-unix.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index 33f56fff..3f963bca 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -2224,6 +2224,15 @@ _dbus_string_save_to_file (const DBusString *str,
total += bytes_written;
}
+ if (fsync(fd))
+ {
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "Could not synchronize file %s: %s",
+ tmp_filename_c, _dbus_strerror (errno));
+
+ goto out;
+ }
+
if (!_dbus_close (fd, NULL))
{
dbus_set_error (error, _dbus_error_from_errno (errno),