summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2012-07-27 12:46:58 +0200
committerMichael Albinus <michael.albinus@gmx.de>2012-07-27 12:46:58 +0200
commite518bc71e8ae11ad81573d6dbf66317a047c4ba7 (patch)
tree6f72431b9cd1afbfa4e0eb492d4eb13462e5bdf7 /src
parentbcfbc9de654b0718d46349ca8ada284dba3dc761 (diff)
downloademacs-e518bc71e8ae11ad81573d6dbf66317a047c4ba7.tar.gz
* dbusbind.c (XD_DBUS_VALIDATE_BUS_ADDRESS): Canonicalize session
bus address. (xd_close_bus, Fdbus_init_bus): Handle reference counter properly.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/dbusbind.c141
2 files changed, 84 insertions, 63 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index ab870b56f1e..bd0422bd3c3 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2012-07-27 Albinus Michael <michael.albinus@gmx.de>
+
+ * dbusbind.c (XD_DBUS_VALIDATE_BUS_ADDRESS): Canonicalize session
+ bus address.
+ (xd_close_bus, Fdbus_init_bus): Handle reference counter properly.
+
2012-07-27 Eli Zaretskii <eliz@gnu.org>
* alloc.c (listn): Fix the order the arguments are consed onto the
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 86013d92c07..06f47643bbf 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -261,6 +261,7 @@ xd_symbol_to_dbus_type (Lisp_Object object)
#define XD_DBUS_VALIDATE_BUS_ADDRESS(bus) \
do { \
+ char const *session_bus_address = getenv ("DBUS_SESSION_BUS_ADDRESS"); \
if (STRINGP (bus)) \
{ \
DBusAddressEntry **entries; \
@@ -272,6 +273,10 @@ xd_symbol_to_dbus_type (Lisp_Object object)
/* Cleanup. */ \
dbus_error_free (&derror); \
dbus_address_entries_free (entries); \
+ /* Canonicalize session bus address. */ \
+ if (session_bus_address != NULL \
+ && Fstring_equal (bus, build_string (session_bus_address))) \
+ bus = QCdbus_session_bus; \
} \
\
else \
@@ -280,8 +285,7 @@ xd_symbol_to_dbus_type (Lisp_Object object)
if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) \
XD_SIGNAL2 (build_string ("Wrong bus name"), bus); \
/* We do not want to have an autolaunch for the session bus. */ \
- if (EQ (bus, QCdbus_session_bus) \
- && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) \
+ if (EQ (bus, QCdbus_session_bus) && session_bus_address == NULL) \
XD_SIGNAL2 (build_string ("No connection to bus"), bus); \
} \
} while (0)
@@ -1071,19 +1075,19 @@ xd_close_bus (Lisp_Object bus)
/* Retrieve bus address. */
connection = xd_get_connection_address (bus);
- /* Close connection, if there isn't another shared application. */
if (xd_get_connection_references (connection) == 1)
{
+ /* Close connection, if there isn't another shared application. */
XD_DEBUG_MESSAGE ("Close connection to bus %s",
XD_OBJECT_TO_STRING (bus));
dbus_connection_close (connection);
- }
- /* Decrement reference count. */
- dbus_connection_unref (connection);
+ xd_registered_buses = Fdelete (val, xd_registered_buses);
+ }
- /* Remove bus from list of registered buses. */
- xd_registered_buses = Fdelete (val, xd_registered_buses);
+ else
+ /* Decrement reference count. */
+ dbus_connection_unref (connection);
/* Return. */
return;
@@ -1124,65 +1128,76 @@ this connection to those buses. */)
/* Close bus if it is already open. */
xd_close_bus (bus);
- /* Initialize. */
- dbus_error_init (&derror);
-
- /* Open the connection. */
- if (STRINGP (bus))
- if (NILP (private))
- connection = dbus_connection_open (SSDATA (bus), &derror);
- else
- connection = dbus_connection_open_private (SSDATA (bus), &derror);
+ /* Check, whether we are still connected. */
+ val = Fassoc (bus, xd_registered_buses);
+ if (!NILP (val))
+ {
+ connection = xd_get_connection_address (bus);
+ dbus_connection_ref (connection);
+ }
else
- if (NILP (private))
- connection = dbus_bus_get (EQ (bus, QCdbus_system_bus)
- ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION,
- &derror);
- else
- connection = dbus_bus_get_private (EQ (bus, QCdbus_system_bus)
- ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION,
- &derror);
-
- if (dbus_error_is_set (&derror))
- XD_ERROR (derror);
-
- if (connection == NULL)
- XD_SIGNAL2 (build_string ("No connection to bus"), bus);
+ {
+ /* Initialize. */
+ dbus_error_init (&derror);
- /* If it is not the system or session bus, we must register
- ourselves. Otherwise, we have called dbus_bus_get, which has
- configured us to exit if the connection closes - we undo this
- setting. */
- if (STRINGP (bus))
- dbus_bus_register (connection, &derror);
- else
- dbus_connection_set_exit_on_disconnect (connection, FALSE);
-
- if (dbus_error_is_set (&derror))
- XD_ERROR (derror);
-
- /* Add the watch functions. We pass also the bus as data, in order
- to distinguish between the buses in xd_remove_watch. */
- if (!dbus_connection_set_watch_functions (connection,
- xd_add_watch,
- xd_remove_watch,
- xd_toggle_watch,
- SYMBOLP (bus)
- ? (void *) XSYMBOL (bus)
- : (void *) XSTRING (bus),
- NULL))
- XD_SIGNAL1 (build_string ("Cannot add watch functions"));
-
- /* Add bus to list of registered buses. */
- XSETFASTINT (val, (intptr_t) connection);
- xd_registered_buses = Fcons (Fcons (bus, val), xd_registered_buses);
-
- /* We do not want to abort. */
- putenv ((char *) "DBUS_FATAL_WARNINGS=0");
+ /* Open the connection. */
+ if (STRINGP (bus))
+ if (NILP (private))
+ connection = dbus_connection_open (SSDATA (bus), &derror);
+ else
+ connection = dbus_connection_open_private (SSDATA (bus), &derror);
- /* Cleanup. */
- dbus_error_free (&derror);
+ else
+ if (NILP (private))
+ connection = dbus_bus_get (EQ (bus, QCdbus_system_bus)
+ ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION,
+ &derror);
+ else
+ connection = dbus_bus_get_private (EQ (bus, QCdbus_system_bus)
+ ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION,
+ &derror);
+
+ if (dbus_error_is_set (&derror))
+ XD_ERROR (derror);
+
+ if (connection == NULL)
+ XD_SIGNAL2 (build_string ("No connection to bus"), bus);
+
+ /* If it is not the system or session bus, we must register
+ ourselves. Otherwise, we have called dbus_bus_get, which has
+ configured us to exit if the connection closes - we undo this
+ setting. */
+ if (STRINGP (bus))
+ dbus_bus_register (connection, &derror);
+ else
+ dbus_connection_set_exit_on_disconnect (connection, FALSE);
+
+ if (dbus_error_is_set (&derror))
+ XD_ERROR (derror);
+
+ /* Add the watch functions. We pass also the bus as data, in
+ order to distinguish between the buses in xd_remove_watch. */
+ if (!dbus_connection_set_watch_functions (connection,
+ xd_add_watch,
+ xd_remove_watch,
+ xd_toggle_watch,
+ SYMBOLP (bus)
+ ? (void *) XSYMBOL (bus)
+ : (void *) XSTRING (bus),
+ NULL))
+ XD_SIGNAL1 (build_string ("Cannot add watch functions"));
+
+ /* Add bus to list of registered buses. */
+ XSETFASTINT (val, (intptr_t) connection);
+ xd_registered_buses = Fcons (Fcons (bus, val), xd_registered_buses);
+
+ /* We do not want to abort. */
+ putenv ((char *) "DBUS_FATAL_WARNINGS=0");
+
+ /* Cleanup. */
+ dbus_error_free (&derror);
+ }
/* Return reference counter. */
refcount = xd_get_connection_references (connection);