summaryrefslogtreecommitdiff
path: root/dbus/dbus-file-win.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-09-03 10:18:25 -0400
committerColin Walters <walters@verbum.org>2010-09-03 14:29:53 -0400
commit45d53565bc13678d6aa5edec1d4efb5bf8a64e0b (patch)
tree2d7793d95690894d29d52f7ece35ec8600d39727 /dbus/dbus-file-win.c
parentff2325c92c411e6718ae38d6976f54580ed57e86 (diff)
downloaddbus-45d53565bc13678d6aa5edec1d4efb5bf8a64e0b.tar.gz
Make dbus-uuidgen atomic
A Red Hat QA engineer hit in practice a race condition in dbus-uuidgen where it could leave an empty file. dbus-uuidgen (_dbus_create_uuid_file_exclusively) formerly created an empty file in the path to the uuid, then filled it in. At some point, the internal libdbus _dbus_string_save_to_file became atomic on Unix at least (doing the save to temp file, fsync(), rename() dance). So _dbus_create_uuid_file_exclusively doesn't need to create the file beforehand anymore. However, it *does* need the file to be world-readable, unlike all other consumers of _dbus_string_save_to_file. So add a "world_readable" argument.
Diffstat (limited to 'dbus/dbus-file-win.c')
-rw-r--r--dbus/dbus-file-win.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/dbus/dbus-file-win.c b/dbus/dbus-file-win.c
index 4f0b0759..53a3fc5b 100644
--- a/dbus/dbus-file-win.c
+++ b/dbus/dbus-file-win.c
@@ -204,12 +204,14 @@ _dbus_file_get_contents (DBusString *str,
*
* @param str the string to write out
* @param filename the file to save string to
+ * @param world_readable if true, ensure file is world readable
* @param error error to be filled in on failure
* @returns #FALSE on failure
*/
dbus_bool_t
_dbus_string_save_to_file (const DBusString *str,
const DBusString *filename,
+ dbus_bool_t world_readable,
DBusError *error)
{
HANDLE hnd;
@@ -259,6 +261,7 @@ _dbus_string_save_to_file (const DBusString *str,
filename_c = _dbus_string_get_const_data (filename);
tmp_filename_c = _dbus_string_get_const_data (&tmp_filename);
+ /* TODO - support world-readable in an atomic fashion */
hnd = CreateFileA (tmp_filename_c, GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
@@ -271,6 +274,8 @@ _dbus_string_save_to_file (const DBusString *str,
_dbus_win_free_error_string (emsg);
goto out;
}
+ if (world_readable)
+ _dbus_make_file_world_readable (tmp_filename_c);
_dbus_verbose ("tmp file %s hnd %p opened\n", tmp_filename_c, hnd);