]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Try to read /etc/machine-id before inventing a new /var/lib/dbus/machine-id
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 25 Apr 2014 17:51:26 +0000 (18:51 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 28 Apr 2014 13:59:54 +0000 (14:59 +0100)
It's least confusing if the two files have the same contents. systemd
already knows how to pick up our /var/lib/dbus/machine-id if it exists
and /etc/machine-id doesn't, but the converse is not currently true.
We should make it true, so that it doesn't matter what order
systemd-machine-id-setup and "dbus-uuidgen --ensure" were
invoked in.

In Debian, systemd currently Recommends dbus, so "dbus-uuidgen --ensure"
will *usually* - but not always! - run first, and the two files will
match. However, if you install systemd without dbus, and then install
dbus later, there will be a mismatch. With this change, it doesn't
matter which one is installed first: whichever one happens to come
first, it will generate the machine ID, and then the other one will
copy it.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=77941
Reviewed-by: Lennart Poettering
dbus/dbus-sysdeps-unix.c

index ae42f56e398b6625477c6dbcb04c6cbbf18ce9da..e81e52c3299f1d0d07dfa9ab0718b134acc0e410 100644 (file)
@@ -3579,7 +3579,7 @@ _dbus_read_local_machine_uuid (DBusGUID   *machine_id,
 
   _dbus_string_init_const (&filename, DBUS_MACHINE_UUID_FILE);
 
-  b = _dbus_read_uuid_file (&filename, machine_id, create_if_not_found, error);
+  b = _dbus_read_uuid_file (&filename, machine_id, FALSE, error);
   if (b)
     return TRUE;
 
@@ -3587,7 +3587,26 @@ _dbus_read_local_machine_uuid (DBusGUID   *machine_id,
 
   /* Fallback to the system machine ID */
   _dbus_string_init_const (&filename, "/etc/machine-id");
-  return _dbus_read_uuid_file (&filename, machine_id, FALSE, error);
+  b = _dbus_read_uuid_file (&filename, machine_id, FALSE, error);
+
+  if (b)
+    {
+      /* try to copy it to the DBUS_MACHINE_UUID_FILE, but do not
+       * complain if that isn't possible for whatever reason */
+      _dbus_string_init_const (&filename, DBUS_MACHINE_UUID_FILE);
+      _dbus_write_uuid_file (&filename, machine_id, NULL);
+
+      return TRUE;
+    }
+
+  if (!create_if_not_found)
+    return FALSE;
+
+  /* if none found, try to make a new one */
+  dbus_error_free (error);
+  _dbus_string_init_const (&filename, DBUS_MACHINE_UUID_FILE);
+  _dbus_generate_uuid (machine_id);
+  return _dbus_write_uuid_file (&filename, machine_id, error);
 }
 
 /**