[PATCH] Make dbus-uuidgen atomic

Ray Strode halfline at gmail.com
Fri Sep 3 08:59:35 PDT 2010


Hi,

On Fri, Sep 3, 2010 at 10:36 AM, Colin Walters <walters at verbum.org> wrote:
> From 8279d913daf9d58ca72684519549e44f58310807 Mon Sep 17 00:00:00 2001
> From: Colin Walters <walters at verbum.org>
> Date: Fri, 3 Sep 2010 10:18:25 -0400
> Subject: [PATCH] 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.
So just to expand on this... The engineer hit ctrl-c on their qemu quest, while
dbus-uuidgen was creating the machine-id file and from then on their virtual
machine wouldn't boot (since ibus was making the login screen crash
because libdbus was aborting)

> --- a/dbus/dbus-file-unix.c
> +++ b/dbus/dbus-file-unix.c
[...]
>  dbus_bool_t
>  _dbus_string_save_to_file (const DBusString *str,
>                             const DBusString *filename,
> +                           dbus_bool_t      world_readable,
>                             DBusError        *error)
>  {
>    int fd;
> @@ -211,7 +213,7 @@ _dbus_string_save_to_file (const DBusString *str,
>    tmp_filename_c = _dbus_string_get_const_data (&tmp_filename);
>
>    fd = open (tmp_filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT,
> -             0600);
> +             world_readable ? 0666 : 0600);
I think you want this to be 0644 right? Actually, it's probably better
not to rely on umask being sane at all, and also:

1) fchmod explicitly after the open
2) check the permissions on the file on start up and make sure they're
right (and either fix them if they're wrong or error out)

--Ray


More information about the dbus mailing list