Leftover dbus processes after launching a dbus-using application remotely and then closing the application
Environment
- Red Hat Enterprise Linux (RHEL)
- 6
- 7
Issue
- When processes needing
dbus
are launched remotely (viassh
,LSF
, or a similar tool),dbus
processes keep running even after the main process is closed, blocking the remote session and preventing it from terminating properly.
$ 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
-
First, update to
- (RHEL 7) dbus-1.10.24-3.el7
- (RHEL 6) dbus-1.2.24-9.el6
or later
-
For interactive use, make sure to launch dbus-run-session before the shell. For instance, add this to .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
so that the resulting process tree shows the bash shell running under dbus-run-session:
$ 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
-
For non-interactive use, use "dbus-run-session -- command" directly, which will solve the issue unless the command forks in the background.
-
Write bash_logout script which will be in charge of killing remaining dbus-* programs for the session, assuming it's the last 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
- This happens because dbus-launch/dbus-daemon remain alive (they are created detached from parent terminal)
Diagnostic Steps
- launch a command like gnome-terminal or gnome-text-editor remotely (via
ssh -X
for instance) - exit
gnome-terminal
/gnome-text-editor
- the remote session stays stuck instead of exiting
dbus-launch
anddbus-daemon
processes are left over in the output of "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