Skip to content

Commit

Permalink
[pd] daemon service: reconnect to dbus on dbus reset (openthread#2605)
Browse files Browse the repository at this point in the history
This commit addresses a potential issue where the pd daemon loses its
dbus connection when original dbus is reset. The daemon now monitors
the io.openthread.BorderRouter.wpan0 dbus name and reconnects if the
name owner changes, indicating a likely otbr-agent reload. This
ensures the daemon continues to function correctly after dbus is reset
by otbr-agent.
  • Loading branch information
yangsong-cnyn authored Nov 21, 2024
1 parent 6334e5b commit 7d32700
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions script/reference-device/dhcp6_pd_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,13 @@ def connect_to_signal():
properties_changed_handler,
dbus_interface=properties_dbus_iface.dbus_interface)
logging.info("Connected to D-Bus signal.")
return dbus_obj
except dbus.DBusException as e:
logging.error(f"Error connecting to D-Bus: {e}")
return None


def check_and_reconnect(dbus_obj):
if dbus_obj is None:
def handle_name_owner_changed(new_owner):
if new_owner:
logging.info(f"New D-Bus owner({new_owner}) assigned, connecting...")
connect_to_signal()


Expand All @@ -130,9 +129,8 @@ def main():

loop = GLib.MainLoop()

thread_dbus_obj = connect_to_signal()

GLib.timeout_add_seconds(5, check_and_reconnect, thread_dbus_obj)
bus.watch_name_owner(bus_name='io.openthread.BorderRouter.wpan0',
callback=handle_name_owner_changed)

loop.run()

Expand Down

0 comments on commit 7d32700

Please sign in to comment.