diff options
author | Simon McVittie <smcv@collabora.com> | 2017-06-07 17:14:00 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2017-06-08 18:31:06 +0100 |
commit | 6f751caf5f08366004d2af4a5e0bdf4e84ffffb1 (patch) | |
tree | 9c30d863b17259b1918750eda20402308711e6c6 /dbus/dbus-internals.c | |
parent | ffa410a0403dcba0116f644749c82e7fc2a0c49f (diff) | |
download | dbus-6f751caf5f08366004d2af4a5e0bdf4e84ffffb1.tar.gz |
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
Diffstat (limited to 'dbus/dbus-internals.c')
-rw-r--r-- | dbus/dbus-internals.c | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 1fb6f02e..bc3454d5 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -908,25 +908,8 @@ _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str, if (machine_uuid_initialized_generation != _dbus_current_generation) { - DBusError local_error = DBUS_ERROR_INIT; - - if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE, - &local_error)) - { -#ifndef DBUS_ENABLE_EMBEDDED_TESTS - /* For the test suite, we may not be installed so just continue silently - * here. But in a production build, we want to be nice and loud about - * this. - */ - _dbus_warn_check_failed ("D-Bus library appears to be incorrectly set up; failed to read machine uuid: %s\n" - "See the manual page for dbus-uuidgen to correct this issue.\n", - local_error.message); -#endif - - dbus_error_free (&local_error); - - ok = _dbus_generate_uuid (&machine_uuid, error); - } + if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE, error)) + ok = FALSE; } if (ok) |