【发布时间】:2019-05-05 08:04:42
【问题描述】:
我使用 x86_64 Debian 9 Stretch。我运行systemd-inhibit cat,然后在另一个控制台中运行systemctl poweroff。正确关机被禁止。根据this doc 应该发出信号PrepareForShutdown(false),但我看不到它。我用dbus-monitor --system 观看dbus 并使用python 程序:
#!/usr/bin/env python
import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop
def handle(*args):
print "PrepareForShutdown %s" % (args)
DBusGMainLoop(set_as_default=True) # integrate into gobject main loop
bus = dbus.SystemBus() # connect to system wide dbus
bus.add_signal_receiver( # define the signal to listen to
handle, # callback function
'PrepareForShutdown', # signal name
'org.freedesktop.login1.Manager', # interface
'org.freedesktop.login1' # bus name
)
loop = gobject.MainLoop()
loop.run()
程序什么也不打印。 dbus-monitor 输出一些晦涩的消息(看起来像是在调用 ListInhibitors)。
是没有发出信号还是我无法捕捉到它?我的目标是通过监听 D-Bus 来检测禁止关机,我该怎么做?
编辑:当使用非延迟抑制时,关闭请求会被丢弃,信号不会触发。但是如果我通过systemd-inhibit --mode=delay --what=shutdown cat 使用延迟锁定,那么 PrepareForShutdown 信号就会触发。
【问题讨论】: