summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2009-07-13 12:47:19 -0400
committerColin Walters <walters@verbum.org>2009-07-14 15:41:40 -0400
commit44062b35af52e60b8e302488c556af0ad4443970 (patch)
treec38080f469aa38e7979469e7157970f921717c8b
parent8420a5bb5733f30d591ef6bbba8446fc9f42d3a1 (diff)
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. (cherry picked from commit 6478ec6949c6bb794237b43d03b68f80eba1288c)
-rw-r--r--dbus/dbus-bus.c70
-rw-r--r--dbus/dbus-sysdeps-unix.c31
-rw-r--r--dbus/dbus-sysdeps-win.c13
-rw-r--r--dbus/dbus-sysdeps.h4
4 files changed, 107 insertions, 11 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");
}
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index 456d4d5f..6396378c 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -3111,6 +3111,37 @@ _dbus_read_local_machine_uuid (DBusGUID *machine_id,
#define DBUS_UNIX_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
#define DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
+/**
+ * Determines the address of the session bus by querying a
+ * platform-specific method.
+ *
+ * The first parameter will be a boolean specifying whether
+ * or not a dynamic session lookup is supported on this platform.
+ *
+ * If supported is TRUE and the return value is #TRUE, the
+ * address will be appended to @p address.
+ * If a failure happens, returns #FALSE and sets an error in
+ * @p error.
+ *
+ * If supported is FALSE, ignore the return value.
+ *
+ * @param supported returns whether this method is supported
+ * @param address a DBusString where the address can be stored
+ * @param error a DBusError to store the error in case of failure
+ * @returns #TRUE on success, #FALSE if an error happened
+ */
+dbus_bool_t
+_dbus_lookup_session_address (dbus_bool_t *supported,
+ DBusString *address,
+ DBusError *error)
+{
+ /* On non-Mac Unix platforms, if the session address isn't already
+ * set in DBUS_SESSION_BUS_ADDRESS environment variable, we punt and
+ * fall back to the autolaunch: global default; see
+ * init_session_address in dbus/dbus-bus.c. */
+ *supported = FALSE;
+ return TRUE;
+}
/**
* Returns the standard directories for a session bus to look for service
diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c
index c62e145d..02f31231 100644
--- a/dbus/dbus-sysdeps-win.c
+++ b/dbus/dbus-sysdeps-win.c
@@ -5,7 +5,7 @@
* Copyright (C) 2003 CodeFactory AB
* Copyright (C) 2005 Novell, Inc.
* Copyright (C) 2006 Ralf Habacker <ralf.habacker@freenet.de>
- * Copyright (C) 2006 Peter Kümmel <syntheticpp@gmx.net>
+ * Copyright (C) 2006 Peter Kümmel <syntheticpp@gmx.net>
* Copyright (C) 2006 Christian Ehrlicher <ch.ehrlicher@gmx.de>
*
* Licensed under the Academic Free License version 2.1
@@ -3281,6 +3281,17 @@ _dbus_append_session_config_file (DBusString *str)
return _dbus_get_config_file_name(str, "session.conf");
}
+/* See comment in dbus-sysdeps-unix.c */
+dbus_bool_t
+_dbus_lookup_session_address (dbus_bool_t *supported,
+ DBusString *address,
+ DBusError *error)
+{
+ /* Probably fill this in with something based on COM? */
+ *supported = FALSE;
+ return TRUE;
+}
+
/**
* Appends the directory in which a keyring for the given credentials
* should be stored. The credentials should have either a Windows or
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index 7af4287a..2fd54214 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -468,6 +468,10 @@ void _dbus_log_security (const char *msg, va_list args);
dbus_bool_t _dbus_get_autolaunch_address (DBusString *address,
DBusError *error);
+dbus_bool_t _dbus_lookup_session_address (dbus_bool_t *supported,
+ DBusString *address,
+ DBusError *error);
+
/** Type representing a universally unique ID
* @todo rename to UUID instead of GUID
*/