diff options
author | Colin Walters <walters@verbum.org> | 2010-09-03 10:18:25 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2010-09-03 14:29:53 -0400 |
commit | 45d53565bc13678d6aa5edec1d4efb5bf8a64e0b (patch) | |
tree | 2d7793d95690894d29d52f7ece35ec8600d39727 /dbus/dbus-internals.c | |
parent | ff2325c92c411e6718ae38d6976f54580ed57e86 (diff) | |
download | dbus-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-internals.c')
-rw-r--r-- | dbus/dbus-internals.c | 16 |
1 files changed, 1 insertions, 15 deletions
diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 2ed56b35..5e864ce3 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -719,27 +719,13 @@ _dbus_create_uuid_file_exclusively (const DBusString *filename, goto error; } - /* FIXME this is racy; we need a save_file_exclusively - * function. But in practice this should be fine for now. - * - * - first be sure we can create the file and it - * doesn't exist by creating it empty with O_EXCL - * - then create it by creating a temporary file and - * overwriting atomically with rename() - */ - if (!_dbus_create_file_exclusively (filename, error)) - goto error; - if (!_dbus_string_append_byte (&encoded, '\n')) { _DBUS_SET_OOM (error); goto error; } - if (!_dbus_string_save_to_file (&encoded, filename, error)) - goto error; - - if (!_dbus_make_file_world_readable (filename, error)) + if (!_dbus_string_save_to_file (&encoded, filename, TRUE, error)) goto error; _dbus_string_free (&encoded); |