[patch][python] dbus.bus: when a unique name goes away, disconnect all signal handlers.

Simon McVittie simon.mcvittie at collabora.co.uk
Mon Jun 11 06:56:54 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This also downgrades a GetNameOwner failure when hooking a signal from
level error to debug. We don't need to worry if the name currently has
no owner, because if it doesn't, it obviously can't emit the signal
we're looking for; before it can, we'll get a NameOwnerChanged we can
respond to.

- From cc6ea2758794601e2747ad9deccf7c8e887b0100 Mon Sep 17 00:00:00 2001
From: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Thu, 7 Jun 2007 20:11:57 +0100
Subject: [PATCH] dbus.bus: when a unique name goes away, disconnect all signal handlers.
Unique names are not recycled, so no more signals can arrive for that name.
- ---
 dbus/bus.py |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/dbus/bus.py b/dbus/bus.py
index 04180a4..86ca159 100644
- --- a/dbus/bus.py
+++ b/dbus/bus.py
@@ -51,7 +51,7 @@ class NameOwnerWatch(object):
     __slots__ = ('_match', '_pending_call')
 
     def __init__(self, bus_conn, bus_name, callback):
- -        validate_bus_name(bus_name, allow_unique=False)
+        validate_bus_name(bus_name)
 
         def signal_cb(owned, old_owner, new_owner):
             callback(new_owner)
@@ -61,7 +61,7 @@ class NameOwnerWatch(object):
                 callback('')
             else:
                 logging.basicConfig()
- -                _logger.error('GetNameOwner(%s) failed:', bus_name,
+                _logger.debug('GetNameOwner(%s) failed:', bus_name,
                               exc_info=(e.__class__, e, None))
 
         self._match = bus_conn.add_signal_receiver(signal_cb,
@@ -133,13 +133,14 @@ class BusConnection(Connection):
                 handler_function, signal_name, dbus_interface, bus_name,
                 path, **keywords)
 
- -        # The bus daemon is special - its unique-name is org.freedesktop.DBus
- -        # rather than starting with :
- -        if (bus_name is not None
- -            and bus_name[:1] != ':'
- -            and bus_name != BUS_DAEMON_NAME):
- -            watch = self.watch_name_owner(bus_name,
- -                                          match.set_sender_name_owner)
+        if (bus_name is not None and bus_name != BUS_DAEMON_NAME):
+            if bus_name[:1] == ':':
+                def callback(new_owner):
+                    if new_owner == '':
+                        match.remove()
+            else:
+                callback = match.set_sender_name_owner
+            watch = self.watch_name_owner(bus_name, callback)
             self._signal_sender_matches[match] = watch
 
         self.add_match_string(str(match))
- -- 
1.5.2.1

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: OpenPGP key: http://www.pseudorandom.co.uk/2003/contact/ or pgp.net

iD8DBQFGbVSmWSc8zVUw7HYRAjxLAJ4jUdV2UAIugu/12ghRC6Xe3tCgrQCfUBj4
jvWcyoNCdXVW63qqoNMci1g=
=/Ask
-----END PGP SIGNATURE-----


More information about the dbus mailing list