Translated message

A translation of this page exists in English.

dbus を使用するアプリケーションをリモートで起動し、アプリケーションを閉じた後に残った dbus プロセス

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL)
    • 6
    • 7

Issue

  • dbus を必要とするプロセスが (sshLSF、または同様のツールを介して) リモートで起動されると、メインプロセスが閉じられた後も、dbus プロセスは実行を継続し、リモートセッションをブロックして、正しく終了できなくなります。
$ emacs
(emacs opens and then close it)

$ ps -ef | grep USER
USER 12467     1  0 11:47 pts/115  00:00:00 dbus-launch --autolaunch e6d5e75b43ed447899e385d217cd827f --binary-syntax --close-stderr
USER  12469     1  0 11:47 ?        00:00:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
USER  12473     1  0 11:47 ?        00:00:00 /usr/libexec/gconfd-2

$ logout
(Waiting  until C-c)

Resolution

  • まず、以下へ更新します

    • (RHEL 7) dbus-1.10.24-3.el7
    • (RHEL 6) dbus-1.2.24-9.el6
      またはそれ以降
  • インタラクティブに使用するには、シェルの前に必ず dbus-run-session を起動してください。たとえば、これを .bashrc に追加します。

if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
  exec dbus-run-session -- bash
  echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
fi

結果のプロセスツリーに、dbus-run-session で実行されている bash シェルが表示されるようにします。

$ ps f
  PID TTY      STAT   TIME COMMAND
 2075 pts/0    Ss     0:00 dbus-run-session -- bash
 2095 pts/0    Sl     0:00  \_ dbus-daemon --nofork --print-address 4 --session
 2096 pts/0    S      0:00  \_ bash
  • 非対話型で使用する場合は、dbus-run-session -- command を直接使用します。これにより、コマンドがバックグラウンドでフォークされない限り、問題が解決します。

  • セッションに残っている dbus-* プログラムを kill する bash_logout スクリプトを記述します (これが最後の bash だと仮定します)。

# ~/.bash_logout

# Check if we are the "parent" shell in a ssh session
[ "$(cat /proc/$PPID/comm)" == "sshd" ] || return

cgroup=$(awk -F ':' '$2 == "name=systemd" { print $3 }' /proc/self/cgroup)
[ -n "$cgroup" ] || return

# Search for "dbus-[daemon|launch]" programs running for this session

for pid in $(cat /sys/fs/cgroup/systemd/$cgroup/tasks 2>/dev/null); do
    comm=$(cat /proc/$pid/comm 2>/dev/null)
    case "$comm" in
    dbus-daemon|dbus-launch)
        echo "Killing '$comm' (PID $pid) ..."
        kill $pid
        ;;
    esac
done

Root Cause

  • これは、dbus-launch/dbus-daemon が存続しているために発生します (これらは親ターミナルから切り離されて作成されます)。

Diagnostic Steps

  • gnome-terminal や gnome-text-editor などのコマンドをリモートで起動します (たとえば、ssh -X を使用)。
  • exit gnome-terminal / gnome-text-editor
  • リモートセッションは終了せずにスタックしたままになります。
  • dbus-launch および dbus-daemon プロセスは、ps ax の出力に残ります。

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments