我编写了一个通过 dbus 作为会话服务运行的程序。
如果由 root (uid 0) 执行,我想让它作为系统服务运行(创建 dbus.SystemBus 总线名称)。
我正在尝试为 dbus.SystemBus 运行我目前为 dbus.SessionBus 运行的程序,但出现策略错误。
代码(python,但它并不重要),从所有不必要的东西中清除,我运行是这样的:
import gobject
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
loop = gobject.MainLoop()
class dbusService(dbus.service.Object):
def __init__(self):
bus_name = dbus.service.BusName('org.testobj.service', bus=dbus.SystemBus())
dbus.service.Object.__init__(self, bus_name, '/org/testobj/service')
a = dbusService()
并得到:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
File "/usr/lib/python2.7/site-packages/dbus/service.py", line 131, in __new__ retval = bus.request_name(name, name_flags)
File "/usr/lib/python2.7/site-packages/dbus/bus.py", line 303, in request_name 'su', (name, flags))
File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 651, in call_blocking message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.48" is not allowed to own the service "org.testobj.service" due to security policies in the configuration file