momo zone

调核人的blog

解决dbus应用不能启动的问题

有的程序会和dbus通讯,这类程序启动时有时候会发生无法连接到dbus总线的问题, 提示/tmp/dbus-xxxxxxx 不存在或没有权限。其实dbus服务已经启动了,可能是由另外一个dbus总线实例在之前启动过导致系统残余了一些旧id。

解决办法是修改一下 /var/lib/dbus/machine-id 就可以了:

dbus-uuidgen  > /var/lib/dbus/machine-id

再次执行测试程序,又有问题:Couldn’t connect to session bus: Failed to execute dbus-launch to autolaunch D-Bus session,看了帮助http://dbus.freedesktop.org/doc/dbus-launch.1.html
AUTOMATIC LAUNCHING一节,需要设置DBUS_SESSION_BUS_ADDRESS环境变量的值,先执行dbus-launch,获得了DBUS_SESSION_BUS_ADDRESS值,再export一下,最后执行测试程序,OK了

在dbus帮助中有一篇关于dbus-launch的文章,可以在脚本中启动dbus-launch,同时自动设置DBUS_SESSION_BUS_ADDRESS环境变量,脚本文件rundbus如下:

if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
## if not found, launch a new one
eval `dbus-launch --sh-syntax --exit-with-session`
echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
fi

执行. rundbus即可。

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: