【发布时间】:2013-12-28 11:31:45
【问题描述】:
我在没有 X11 的系统上运行,“myapp”,它注册了一个 dbus 服务器, 一个 php 应用程序,它应该通过 dbus 向服务器发送消息。
在开发机器上一切正常,(使用 gnome,X11) 但是当我部署在没有 X11 的服务器上时,我会在每次 dbus 调用时运行:
# process status
ps ax | grep dbus
2033 ? Ss 0:00 /usr/bin/dbus-daemon --system
2383 pts/0 S+ 0:00 grep --color=auto dbus
# listing names
dbus-send --session --print-reply --dest="org.freedesktop.DBus" /org/freedesktop/DBus org.freedesktop.DBus.ListNames
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
# from php running with system("<above command> 2>&1"); I get same response
./myapp
terminate called after throwing an instance of 'DBus::Error'
what(): Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Aborted
# same when calling into DBus::Connection bus = DBus::Connection::SessionBus();
如果我要向 ./.bashrc 添加以下脚本
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
#reboot
ps ax |grep dbus
2023 ? Ss 0:00 /usr/bin/dbus-daemon --system
2389 pts/0 S 0:00 dbus-launch --sh-syntax --exit-with-session
2390 ? Ss 0:00 /usr/bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session
2392 pts/0 S+ 0:00 grep --color=auto dbus
然后,从同一个外壳
dbus-send --session --print-reply --dest="org.freedesktop.DBus" /org/freedesktop/DBus org.freedesktop.DBus.ListNames
打印我的服务器名称,但来自 php
system("above command"); same error, and
system ("echo system("eval 'dbus-launch --auto-syntax' dbus-send --session --print-reply --dest=\"org.freedesktop.DBus\" /org/freedesktop/DBus org.freedesktop.DBus.ListNames 2>&1");
没有列出名字。
问题是,如何从 lighthttpd 加入现有的 dbus 会话或任何其他变体。
谢谢
【问题讨论】: