DBUS_SETUP.md 2.0 KB

D-Bus 配置说明

问题描述

如果遇到以下错误:

Failed to register D-Bus service: "Connection \":1.179\" is not allowed to own the service \"com.softbus.Daemon\" due to security policies in the configuration file"

这是因为 D-Bus 安全策略不允许应用程序注册 com.softbus.Daemon 服务。

解决方案

方法 1:使用安装脚本(推荐)

cd /path/to/soft_bus/soft_bus
bash config/install_dbus_config.sh

方法 2:手动安装

  1. 创建配置目录(如果不存在):

    mkdir -p ~/.config/dbus-1/session.d
    
  2. 复制配置文件:

    cp config/com.softbus.Daemon.conf ~/.config/dbus-1/session.d/
    

应用配置

配置文件安装后,需要重启 D-Bus 会话才能生效。有以下几种方法:

方法 A:重新登录(最安全)

  • 注销并重新登录到桌面环境

方法 B:重启 D-Bus 会话守护进程

# 查找会话 D-Bus 守护进程
ps aux | grep dbus-daemon | grep session

# 重启会话 D-Bus(会自动重启)
killall -HUP dbus-daemon

方法 C:重启桌面环境

  • 重启桌面环境(如 GNOME、KDE 等)

验证配置

安装并重启后,可以验证配置是否生效:

# 检查配置文件是否存在
ls -l ~/.config/dbus-1/session.d/com.softbus.Daemon.conf

# 检查 D-Bus 服务是否可用
dbus-send --session --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep softbus

系统级安装(可选)

如果需要为所有用户安装配置(需要 root 权限):

sudo bash config/install_dbus_config.sh --system

配置文件说明

配置文件 com.softbus.Daemon.conf 包含以下策略:

  • 允许所有用户注册服务<allow own="com.softbus.Daemon"/>
  • 允许发送消息到服务<allow send_destination="com.softbus.Daemon"/>
  • 允许接收服务消息<allow receive_sender="com.softbus.Daemon"/>

这些策略确保守护进程可以正常注册和运行。