]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
machine-id: fall back to reading /etc/machine-id if D-Bus machine ID is not available
authorLennart Poettering <lennart@poettering.net>
Fri, 11 Mar 2011 01:58:39 +0000 (02:58 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 27 Apr 2011 16:54:38 +0000 (17:54 +0100)
Newer systemd-based systems support a global machine ID with the same
metrics as the D-Bus machine ID, but more powerful semantics (for
example on ro media) in /etc/machine-id.

If the D-Bus machine ID cannot be read, fall back to the systemd machine
ID.

This is a first step towards allowing D-Bus to be started up during
early boot where /var is not available.

[plus a whitespace fix -smcv]

Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Colin Walters <walters@verbum.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=35228

dbus/dbus-sysdeps-unix.c

index e9ea2535677c5713d063e8509b24307596f7edfa..bb066ce993f5d789e15399f4de27527d4d9df00c 100644 (file)
@@ -3349,8 +3349,19 @@ _dbus_read_local_machine_uuid (DBusGUID   *machine_id,
                                DBusError  *error)
 {
   DBusString filename;
+  dbus_bool_t b;
+
   _dbus_string_init_const (&filename, DBUS_MACHINE_UUID_FILE);
-  return _dbus_read_uuid_file (&filename, machine_id, create_if_not_found, error);
+
+  b = _dbus_read_uuid_file (&filename, machine_id, create_if_not_found, error);
+  if (b)
+    return TRUE;
+
+  dbus_error_free (error);
+
+  /* Fallback to the system machine ID */
+  _dbus_string_init_const (&filename, "/etc/machine-id");
+  return _dbus_read_uuid_file (&filename, machine_id, FALSE, error);
 }
 
 #define DBUS_UNIX_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"