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:
parent
2cfddddd10
commit
9da66068dc
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue