diff options
author | Colin Walters <walters@verbum.org> | 2009-07-13 12:47:19 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2009-07-13 12:47:19 -0400 |
commit | 6478ec6949c6bb794237b43d03b68f80eba1288c (patch) | |
tree | 6cf13e96d9f6aa52abff418ff8a048e586a2b01b /dbus/dbus-bus.c | |
parent | c71403ddde230378e3beffee21a3d1fe6edc9bce (diff) | |
download | dbus-6478ec6949c6bb794237b43d03b68f80eba1288c.tar.gz |
Bug 14259 - Make session address lookup system-dependent
On some platforms such as MacOS X and Windows, we can't depend
on an environment variable to determine the address of the
session bus. Create a sysdep function dbus_lookup_session_address
which can be filled in with platform-specific code.
Diffstat (limited to 'dbus/dbus-bus.c')
-rw-r--r-- | dbus/dbus-bus.c | 70 |
1 files changed, 60 insertions, 10 deletions
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c index 4a4314b1..92ec20ed 100644 --- a/dbus/dbus-bus.c +++ b/dbus/dbus-bus.c @@ -22,6 +22,7 @@ * */ +#include <config.h> #include "dbus-bus.h" #include "dbus-protocol.h" #include "dbus-internals.h" @@ -29,7 +30,7 @@ #include "dbus-marshal-validate.h" #include "dbus-threads-internal.h" #include "dbus-connection-internal.h" -#include <string.h> +#include "dbus-string.h" /** * @defgroup DBusBus Message bus APIs @@ -147,6 +148,63 @@ get_from_env (char **connection_p, } static dbus_bool_t +init_session_address (void) +{ + dbus_bool_t retval; + + retval = FALSE; + + /* First, look in the environment. This is the normal case on + * freedesktop.org/Unix systems. */ + get_from_env (&bus_connection_addresses[DBUS_BUS_SESSION], + "DBUS_SESSION_BUS_ADDRESS"); + if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL) + { + dbus_bool_t supported; + DBusString addr; + DBusError error = DBUS_ERROR_INIT; + + if (!_dbus_string_init (&addr)) + return FALSE; + + supported = FALSE; + /* So it's not in the environment - let's try a platform-specific method. + * On MacOS, this involves asking launchd. On Windows (not specified yet) + * we might do a COM lookup. + * Ignore errors - if we failed, fall back to autolaunch. */ + retval = _dbus_lookup_session_address (&supported, &addr, &error); + if (supported && retval) + { + retval =_dbus_string_steal_data (&addr, &bus_connection_addresses[DBUS_BUS_SESSION]); + } + else if (supported && !retval) + { + if (dbus_error_is_set(&error)) + _dbus_warn ("Dynamic session lookup supported but failed: %s\n", error.message); + else + _dbus_warn ("Dynamic session lookup supported but failed silently\n"); + } + _dbus_string_free (&addr); + } + else + retval = TRUE; + + if (!retval) + return FALSE; + + /* The DBUS_SESSION_BUS_DEFAULT_ADDRESS should have really been named + * DBUS_SESSION_BUS_FALLBACK_ADDRESS. + */ + if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL) + bus_connection_addresses[DBUS_BUS_SESSION] = + _dbus_strdup (DBUS_SESSION_BUS_DEFAULT_ADDRESS); + if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL) + return FALSE; + + return TRUE; +} + +static dbus_bool_t init_connections_unlocked (void) { if (!initialized) @@ -198,17 +256,9 @@ init_connections_unlocked (void) { _dbus_verbose ("Filling in session bus address...\n"); - if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SESSION], - "DBUS_SESSION_BUS_ADDRESS")) + if (!init_session_address ()) return FALSE; - if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL) - bus_connection_addresses[DBUS_BUS_SESSION] = - _dbus_strdup (DBUS_SESSION_BUS_DEFAULT_ADDRESS); - - if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL) - return FALSE; - _dbus_verbose (" \"%s\"\n", bus_connection_addresses[DBUS_BUS_SESSION] ? bus_connection_addresses[DBUS_BUS_SESSION] : "none set"); } |