Clarify machine-id file path
The spec says
On Unix, implementations should try to read the machine ID from
/var/lib/dbus/machine-id
and/etc/machine-id
. The latter is defined by systemd, but systems not using systemd may provide an equivalent file. If both exist, they are expected to have the same contents, and if they differ, the spec does not define which takes precedence (the reference implementation prefers/var/lib/dbus/machine-id
, but sd-bus does not).
but the reference implementation actually uses the DBUS_MACHINE_UUID_FILE
definition, which is set to $localstatedir/lib/dbus/machine-id
by the build system, where $localstatedir
likely defaults to /var/local
, and is otherwise build-time configurable (I can imagine it being set to /opt/dbus-1.0/var
or something like ~/.local/share
for example).
This does not normally cause issues as long as clients all use the same build of libdbus along with dbus-daemon which also comes from the same build. But then glib has its own D-Bus implementation, which also uses $localstatedir/lib/dbus/machine-id
, this time with glib's own $localstatedir
, which may be different from D-Bus's. zbus uses the literal /var/lib/dbus/machine-id
path, as specified in the spec.
It would make sense to resolve the contradiction between the spec and the reference implementation, and either always make the reference implementation (and others) use /var/lib/dbus/machine-id
, or update the spec to mention that the state dir in fact doesn't have to be /var
, but may be something else like /var/local
. In the latter case, it would also perhaps make sense to export the reference implementation's state dir path as a pkg-config variable, so the other implementations would be able to do:
dbus_machine_uuid_file = dbus1_dep.get_variable('localstatedir') / 'lib' / 'dbus' / 'machine-id'
This was prompted by https://gitlab.gnome.org/GNOME/glib/-/issues/3148#note_1873481