[PATCH] Make dbus-uuidgen atomic

Jörg Barfurth joerg.barfurth at oracle.com
Mon Sep 6 00:58:27 PDT 2010


Colin Walters schrieb:
> New patch with just the mask fix attached.
> 

> @@ -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;
> -


This change seem to lose the cross-process locking provided by creat(.., 
O_EXCL). Isn't that what the '_exclusively' in the function name is 
supposed to express?

If there still is a check for file existence (I haven't looked if even 
that is there!), it is now racy.

- Jörg


>    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;

-- 
Jörg Barfurth                        http://blogs.sun.com/joergb

Disclaimer: I am employed by Oracle. The statements and opinions
expressed here are my own and do not necessarily represent those
of Oracle Corporation.


More information about the dbus mailing list