sysdeps-unix: Report missing launchd session bus as non-fatal

init_connections_unlocked() is called when connecting to any of the
well-known buses, and it initializes all of the well-known addresses:
session, system and starter. This means that a failure here causes
failure to connect to any one of the well-known buses, even if the
failure is actually only relevant to a different well-known bus.
As such, it should only fail on genuinely fatal errors, for example
an out-of-memory condition. It calls init_session_address() and
indirectly _dbus_lookup_session_address(), which therefore need to
have similar behaviour.

Previously, _dbus_lookup_session_address() would fail with a
fatal error whenever the macOS session bus was not correctly set up,
but that breaks the ability to connect to the system bus on macOS,
even though the system bus is not directly related to the session bus.
Instead, we should report a missing session bus as "not supported",
reserving an unsuccessful result for fatal situations like
out-of-memory. This brings _dbus_lookup_session_address_launchd()
into line with the error behaviour of _dbus_lookup_user_bus().

Closes: #510
This commit is contained in:
Mohamed Akram 2024-12-10 17:30:19 +04:00 committed by Simon McVittie
parent b407eba60d
commit 827e952793

View file

@ -4391,6 +4391,9 @@ _dbus_get_autolaunch_address (const char *scope,
#else
dbus_set_error_const (error, DBUS_ERROR_NOT_SUPPORTED,
"Using X11 for dbus-daemon autolaunch was disabled at compile time, "
#ifdef DBUS_ENABLE_LAUNCHD
"verify that org.freedesktop.dbus-session.plist is loaded or "
#endif
"set your DBUS_SESSION_BUS_ADDRESS instead");
return FALSE;
#endif
@ -4532,39 +4535,27 @@ _dbus_lookup_launchd_socket (DBusString *socket_path,
#ifdef DBUS_ENABLE_LAUNCHD
static dbus_bool_t
_dbus_lookup_session_address_launchd (DBusString *address, DBusError *error)
_dbus_lookup_session_address_launchd (dbus_bool_t *supported,
DBusString *address,
DBusError *error)
{
dbus_bool_t valid_socket;
DBusString socket_path;
if (_dbus_check_setuid ())
{
dbus_set_error_const (error, DBUS_ERROR_NOT_SUPPORTED,
"Unable to find launchd socket when setuid");
return FALSE;
}
if (!_dbus_string_init (&socket_path))
{
_DBUS_SET_OOM (error);
return FALSE;
}
valid_socket = _dbus_lookup_launchd_socket (&socket_path, "DBUS_LAUNCHD_SESSION_BUS_SOCKET", error);
if (dbus_error_is_set(error))
{
_dbus_string_free(&socket_path);
return FALSE;
}
valid_socket = _dbus_lookup_launchd_socket (&socket_path, "DBUS_LAUNCHD_SESSION_BUS_SOCKET", NULL);
if (!valid_socket)
{
dbus_set_error(error, "no socket path",
"launchd did not provide a socket path, "
"verify that org.freedesktop.dbus-session.plist is loaded!");
_dbus_verbose ("launchd did not provide a socket path");
_dbus_string_free(&socket_path);
return FALSE;
*supported = FALSE;
return TRUE; /* Cannot use it, but not an error */
}
if (!_dbus_string_append (address, "unix:path="))
{
@ -4682,7 +4673,7 @@ _dbus_lookup_session_address (dbus_bool_t *supported,
{
#ifdef DBUS_ENABLE_LAUNCHD
*supported = TRUE;
return _dbus_lookup_session_address_launchd (address, error);
return _dbus_lookup_session_address_launchd (supported, address, error);
#else
*supported = FALSE;