加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 如何配置D-Bus和SSH X-Forwarding以防止SSH在退出时挂

发布时间:2020-12-13 18:42:39 所属栏目:Linux 来源:网络整理
导读:我试图通过X11 Forwarding和SSH运行各种Gnome应用程序.某些应用程序将导致首先生成’dbus-launch’应用程序.问题是当X应用程序退出时,dbus-launch不会关闭,因此必须在正确关闭SSH会话之前将其终止. 我假设问题是X / Gnome应用程序无法与主消息总线守护程序连
我试图通过X11 Forwarding和SSH运行各种Gnome应用程序.某些应用程序将导致首先生成’dbus-launch’应用程序.问题是当X应用程序退出时,dbus-launch不会关闭,因此必须在正确关闭SSH会话之前将其终止.

我假设问题是X / Gnome应用程序无法与主消息总线守护程序连接,因此必须启动自己的副本?我怎样才能解决这个问题?或者我错过了什么?

这是一个例子.我启用了X11 Forwarding,一切似乎都运行正常.

[me@host ~]$gnome-calculator &
[1] 4803

(这里gcalctool程序启动并显示给我的删除X服务器(Xming))

[me@host ~]$ps
  PID TTY          TIME CMD
 4706 pts/0    00:00:00 bash
 4803 pts/0    00:00:00 gnome-calculator
 4807 pts/0    00:00:00 dbus-launch
 4870 pts/0    00:00:00 ps

(现在,在关闭远程会话中的gcalctool应用程序之后)

[me@host ~]$ps
  PID TTY          TIME CMD
 4706 pts/0    00:00:00 bash
 4807 pts/0    00:00:00 dbus-launch
 4898 pts/0    00:00:00 ps

请注意,dbus-launch仍处于活动状态.最糟糕的是,这可以防止SSH连接正常关闭,直到它被杀死.

请注意,系统范围的消息守护程序正在运行,如下所示:

[me@host ~]$ps ax
 4696 ?     Ssl   0:00 dbus-daemon --system

我在这里想念的是什么?我以前从未见过这种行为.据推测,我只见过可以不受阻碍地连接到消息总线守护程序的应用程序?我在/ etc / dbus-1中查找了答案,但不知道该找什么.

在此先感谢您的帮助.

[编辑]

好的,我意识到我遇到了一个常见的问题.这似乎是一种相当普遍的行为,但没有一个好的解决方案.我正在经历SSH挂起,因为dbus-launch在tty中仍处于活动状态.但似乎没有好办法让dbus-launch安静地发生.

查看/etc/X11/xinit/xinitrc.d/00-start-message-bus.sh给出了一些关于“正常”X会话应该发生什么的线索.当然只需要向远程X服务器调用X应用程序时,这当然不起作用.

作为临时解决方法,我已将此添加到我的.bash_logout:

# ~/.bash_logout
pkill -u $USER -t `tty | cut -d '/' -f 3,4` dbus-launch

这将允许SSH会话关闭,但感觉很糟糕.那里有更好的解决方案吗?在没有dbus阻碍的情况下运行远程X11应用程序的正确方法是什么?

解决方法

每dbus-launch(1):

If DBUS_SESSION_BUS_ADDRESS is not set for a process that tries to use D-Bus,by default the process will attempt to invoke dbus-launch with the –autolaunch option to start up a new session bus or find the existing bus address on the X display or in a file in ~/.dbus/session-bus/

Whenever an autolaunch occurs,the application that had to start a new bus will be in its own little world; it can effectively end up starting a whole new session if it tries to use a lot of bus services. This can be suboptimal or even totally broken,depending on the app and what it tries to do.

There are two common reasons for autolaunch. One is ssh to a remote machine.

所以似乎诀窍就是先发制人启动dbus-daemon,程序可以找到它.我用:

[me@host ~]$dbus-launch --exit-with-session gnome-terminal

除了gnome-terminal之外,它启动dbus-daemon并在gnome-terminal中设置$DBUS_SESSION_BUS_ADDRESS.

任何从gnome-terminal运行的X程序都表现得很好,当gnome-terminal退出时,dbus-launch会自动清理.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读