dbus填坑记录
- 如果普通用户登陆,不能用root用户创建DBUS_BUS_SESSION类型的dbus
- DBUS_BUS_SYSTEM类型需要在/etc/dbus-1/system.d/中增加定义,比如
<busconfig> <policy user="root"> <allow own="uk.org.thekelleys.dnsmasq"/> <allow send_destination="uk.org.thekelleys.dnsmasq"/> </policy> <policy context="default"> <deny own="uk.org.thekelleys.dnsmasq"/> <deny send_destination="uk.org.thekelleys.dnsmasq"/> </policy> </busconfig>
- 普通用户sudo执行时,DBUS_BUS_SESSION类型和DBUS_BUS_SYSTEM不能通信。
DBUS_BUS_SESSION
这种类型的dbus不能用root用户创建,否则会报如下错误
dbus_bus_get failed: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
如果加上 setenv("DISPLAY", ":0", true);又会报如下错误
dbus_bus_get failed: /usr/bin/dbus-launch terminated abnormally with the following error: No protocol specified
Autolaunch error: X11 initialization failed.
DBUS_BUS_SYSTEM
直接用会报如下错误
dbus_bus_request_name failed: Connection ":1.21" is not allowed to own the service "xxx" due to security policies in the configuration file
dbus[19129]: Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.
D-Bus not built with -rdynamic so unable to print a backtrace
Aborted
必须在/etc/dbus-1/system.d/中增加相应的定义
dbus_bus_add_match
网上查到的粟子中,基本上都是type='signal',interface='%s',其实match的规则可以有很多,比如type, interface,sender,destination,所有的规则可以单独出现,也可以组合,实际使用中根据需要选择。