dbus: do not use the bus in watch_suspend_resume when there is none

The guard read

    if bus is not None and on_resume_callback is not None or on_suspend_callback is not None:

which parses as

    (bus is not None and on_resume_callback is not None) or (on_suspend_callback is not None)

so a caller passing on_suspend_callback entered the body regardless of
whether the bus exists, and bus.add_signal_receiver() raised AttributeError
on None. gtk.py passes both callbacks under --restart-on-wake-up, so that
option crashed on any system without a running system dbus. Test the bus
separately and return early.

The success message was also logged even when no bus was connected.
This commit is contained in:
Nick Price 2026-07-11 17:43:14 -07:00
parent 2cfddddd10
commit 9da66068dc
No known key found for this signature in database
1 changed files with 3 additions and 1 deletions

View File

@ -61,7 +61,9 @@ def watch_suspend_resume(
global _resume_callback, _suspend_callback
_suspend_callback = on_suspend_callback
_resume_callback = on_resume_callback
if bus is not None and on_resume_callback is not None or on_suspend_callback is not None:
if bus is None:
return
if on_resume_callback is not None or on_suspend_callback is not None:
bus.add_signal_receiver(
_suspend_or_resume,
"PrepareForSleep",