Make _dbus_get_local_machine_uuid_encoded() properly failable
authorSimon McVittie <smcv@collabora.com>
Wed, 7 Jun 2017 16:14:00 +0000 (17:14 +0100)
committerSimon McVittie <smcv@collabora.com>
Thu, 8 Jun 2017 17:31:06 +0000 (18:31 +0100)
commit6f751caf5f08366004d2af4a5e0bdf4e84ffffb1
tree9c30d863b17259b1918750eda20402308711e6c6
parentffa410a0403dcba0116f644749c82e7fc2a0c49f
Make _dbus_get_local_machine_uuid_encoded() properly failable

This function already raised an error, and all callers handled that
error as gracefully as they could (because _dbus_generate_uuid() is
failable, since 2015). Given that, it seems unnecessarily hostile
to do a _dbus_warn_check_failed() unless we have no better alternative:
yes, it indicates that dbus has not been installed correctly, but
during build-time tests it's entirely reasonable that dbus has not
yet been installed.

Callers are:

* DBusConnection, to implement Peer.GetMachineId()
* The bus driver, to implement Peer.GetMachineId()
* X11 autolaunching
* dbus_get_local_machine_id()

Of those, only the last one is not in a position to return an error
gracefully, so move the _dbus_warn_check_failed() to there.

Migrate the text about the D-Bus library being incorrectly set up
into the error emitted by the Unix implementation, and to make it
less misleading, include separate error messages for both the
files we try to read:

$ bwrap --ro-bind / / --dev /dev --tmpfs /etc --tmpfs /var \
  ./tools/dbus-uuidgen --get
D-Bus library appears to be incorrectly set up: see the manual
page for dbus-uuidgen to correct this issue. (Failed to open
"/var/lib/dbus/machine-id": No such file or directory; Failed to open
"/etc/machine-id": No such file or directory)

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=13194
dbus/dbus-internals.c
dbus/dbus-misc.c
dbus/dbus-sysdeps-unix.c