从 tmux 内部运行时,gnome-open 会引发此错误

从 tmux 内部运行时,gnome-open 会引发此错误

我收到的错误是这样的:

GConf Error: Failed to contact configuration server; the most common cause is a missing or misconfigured D-Bus session bus daemon. 
See http://projects.gnome.org/gconf/ for information. 
(Details -  1: Failed to get connection to session: Error connecting: Connection refused)
Failed to open bus: Failed to connect to socket /tmp/dbus-BYC0LHrEHk: Connection refused

有什么建议么?

答案1

不要让 Gnome 运行dbus-launch来创建随机的 D-Bus 地址,而是dbus-daemon在 X 会话启动时明确启动并为其指定一个固定地址,如unix:path=~/.dbus-$HOSTNAME-$DISPLAY

鉴于错误报告,您甚至可以摆脱困境unset DBUS_SESSION_BUS_ADDRESS,让应用程序从根窗口属性中找出总线地址。

从 15.10 开始,每个会话的 dbus 实例是通过暴发户 会话作业。相关作业文件是/usr/share/upstart/sessions/dbus.conf。你可以用以下方式替换默认随机地址:覆盖pre-start script指定要使用的地址的节。使用~/.config/upstart/dbus.override以下内容创建:

pre-start script
    DBUS_SESSION_BUS_ADDRESS=unix:path=$HOME/.dbus-$(hostname)-$(echo $DISPLAY | sed -e s/:/%3A/)
    initctl set-env DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
end script

您下次登录后将使用该固定地址。

答案2

这显然是 gconf 中的一个错误,已经有一个修复(如果我理解正确的话)错误报告)。与此同时,以下方法应该可以解决该问题:

export DBUS_SESSION_BUS_ADDRESS=$(tr '\0' '\n' < /proc/$(pgrep -U $(whoami) gnome-session)/environ|grep ^DBUS_SESSION_BUS_ADDRESS=|cut -d= -f2-)

答案3

或者如果你像我一样不使用 gnome:

unset DBUS_SESSION_BUS_ADDRESS

答案4

可以指示 tmux 始终重置某些环境变量:

update-environment variables

Set a space-separated string containing a list of environment variables to
be copied into the session environment when a new session is created or an
existing session is attached. Any variables that do not exist in the source
environment are set to be removed from the session environment (as if -r was
given to the set-environment command). The default is "DISPLAY SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY".

基于此,将 DBUS_SESSION_BUS_ADDRES 添加到此选项可能是合适的~/tmux.conf

set-option -g update-environment "DBUS_SESSION_BUS_ADDRESS DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"

这对我有用。

相关内容