Bug 9884 - dbus-daemon from 2007 does not terminate on X logout, somehow related to zsh
Summary: dbus-daemon from 2007 does not terminate on X logout, somehow related to zsh
Status: RESOLVED WORKSFORME
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: All All
: medium normal
Assignee: Havoc Pennington
QA Contact:
URL: https://bugzilla.novell.com/show_bug....
Whiteboard:
Keywords: NEEDINFO
Depends on:
Blocks:
 
Reported: 2007-02-05 10:14 UTC by Jan Houtsma
Modified: 2014-09-10 15:56 UTC (History)
5 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Jan Houtsma 2007-02-05 10:14:21 UTC
Using Fedora Core 6 here with Gnome 2.16. For every user that logs in and out the 'dbus-daemon' and 'gnome-vfs-daemon' remain in the processlist. After a month of users logging in and out i have hundereds of these processes in ps!!

It's launched from xinitrc(-common) as follows:

[ -x /usr/bin/dbus-launch -a -z "$DBUS_SESSION_BUS_ADDRESS" ] && DBUS_LAUNCH="/usr/bin/dbus-launch --exit-with-session" 

I found out that it is related to what shell has been defined for the use in /etc/passwd. If it is /bin/bash all is fine and the dbus-daemon gets killed when the users exits from X. However for users that use /bin/zsh as their default shell the process is still there after logout from X.

Here you go. Now woth another user (ramon). B.t.w. the system is completely up2date to the latest updates. I did 4 things here:
1. Before login to X:  ps -ef|grep -E 'ramon|dbus'
2. During the login: ps -ef|grep -E 'ramon|dbus'  followed by only ps -ef|grep -E 'ramon|dbus'
3. After logout:  ps -ef|grep -E 'ramon|dbus'

root:/etc/X11/xinit> rpm -qa|grep dbus
dbus-devel-1.0.1-9.fc6
dbus-glib-0.70-6.fc6
dbus-x11-1.0.1-9.fc6
dbus-glib-devel-0.70-6.fc6
dbus-1.0.1-9.fc6
dbus-sharp-0.63-6.fc6
dbus-python-0.70-6

# BEFORE LOGIN
root:/etc/X11/xinit> ps -ef|grep dbus
dbus      2243     1  0 Jan19 ?        00:00:02 dbus-daemon --system

# WHILE LOGGED IN
root:/etc/X11/xinit> ps -ef|grep dbus
dbus      2243     1  0 Jan19 ?        00:00:02 dbus-daemon --system
ramon    27092  2681  0 08:28 ?        00:00:00 -/bin/zsh -c /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients
ramon    27137 27136  0 08:28 ?        00:00:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients
ramon    27140     1  0 08:28 ?        00:00:00 /usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients
ramon    27141     1  0 08:28 ?        00:00:00 /bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session

# AFTER LOGOUT
root:/etc/X11/xinit> ps -ef|grep -E 'ramon|dbus'
dbus      2243     1  0 Jan19 ?        00:00:02 dbus-daemon --system
ramon    27141     1  0 08:28 ?        00:00:00 /bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session
ramon    27184     1  0 08:28 ?        00:00:00 /usr/libexec/gnome-vfs-daemon

Note the -/bin/zsh before the dbus-launch call above while logged in. This shell call is not there when using /bin/bash. Then that line looks as followed:

# DURING LOGIN
root:/etc/X11/xinit> ps -ef|grep -E 'ramon|dbus'
dbus      2243     1  0 Jan19 ?        00:00:02 dbus-daemon --system
ramon    27327  2681  1 08:45 ?        00:00:00 /usr/bin/gnome-session
ramon    27378 27327  0 08:45 ?        00:00:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients
ramon    27381     1  0 08:45 ?        00:00:00 /bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session
ramon    27382     1  0 08:45 ?        00:00:00 /usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients 

So WITHOUT an explicit shell call. And then after logout from X the dbus-daemon correctly exits. Just not when using a different shell than /bin/bash (like zsh for example).

I think the dbus-daemon should exit also when using non-bash shells!
Comment 1 Harri 2009-04-13 11:20:12 UTC
I get the same problem using bash, so I would assume the shell is innocent. I start dbus-launch right from within .bash_profile together with xinit (i.e. the traditional way):

if [ "`tty`" = "/dev/tty1" ]; then
    startx="xinit -- :4 -br -quiet"
    test -x /usr/bin/dbus-launch && \
        startx="/usr/bin/dbus-launch --exit-with-session $startx"
    $startx >& .xinitrc.log
fi

Distro is Debian sid (amd64).

How comes that this bug report staid in status "NEW" for almost 2 years? Could nobody from the core developers reproduce this problem? 

Please mail if I can help.
Comment 2 Havoc Pennington 2009-04-13 14:46:27 UTC
I don't think this happens for most people. It looks like you're starting dbus before X, so dbus can't connect to X, which makes --exit-with-session not able to exit when the X server does. Most distributions are not configured that way.

Comment 3 Harri 2009-04-13 22:37:31 UTC
I am just starting dbus-launcher with "--exit-with-session xinit ...". I do not see what is happening inside, but dbus-launcher seems to start dbus-daemon, and then it starts xinit. It could terminate dbus-daemon when xinit terminates (watching both via wait(2) or sigaction(2) as usual), and then exit with xinit's exit value.

Actually I don't see any reason why Dbus should work with XWindow only. Wouldn't you agree that Dbus could be used for all kinds of applications?
Comment 4 Havoc Pennington 2009-04-14 05:17:18 UTC
--exit-with-session optionally connects to the X server, so it can exit when the X server does. This is the most reliable way to do things. But if you start --exit-with-session *before* you start X, then it can't connect to the X server.


dbus-launch could terminate when the launched child does, but it doesn't do that now and isn't designed/documented to do that now, iirc. It probably is not a compatible change so would be a new feature like --exit-with-launched-child

Comment 5 Harri 2009-04-14 23:22:13 UTC
I doubt that Xwindow's IPC is more reliable than a SIGCHLD sent by the kernel. 

AFAICS there are at least 3 problems with --exit-with-session:

The XWindow server is supposed to do a reset if the last client connection goes away. If dbus-launch keeps that last connection active (as the man page seems to indicate), then X never does a reset.

Even though the XWindow server might be running, the authentication scheme between Xserver and the clients might not be setup yet when dbus-launch comes into the game.

Since --exit-with-session polls stdin it keeps your terminal busy. This has the "nice" effect that if you run the Xwindow client script as a background process, dbus-launch eats up every second char you type on the terminal. (At least this annoyance is reliable.)

Talking about a new command line option: I could live with that.
Comment 6 Kitof 2010-01-31 08:33:44 UTC
Bug is still here, and really annoying in my case.
Comment 7 Leho Kraav (:macmaN :lkraav) 2011-01-12 15:32:51 UTC
(In reply to comment #5) 
> Since --exit-with-session polls stdin it keeps your terminal busy. This has the
> "nice" effect that if you run the Xwindow client script as a background
> process, dbus-launch eats up every second char you type on the terminal. (At
> least this annoyance is reliable.)

(running dbus-1.41 on gentoo)

i think this is my confirmation that this is the bug i also care about. trying to work with dbus with no X seems to be a bit of a hassle.

if i do "dbus-launch --exit-with-session" over ssh (because i would like dbus-daemon to quit when i log out or get disconnected), i get the nifty character eating phenomenon for a bit, and after a timeout, dbus-launch just gives up on trying to reach X (i think) and doesn't give me a dbus-daemon at all.

if i do the regular "eval `dbus-launch --sh-syntax`" dance, i get a properly working dbus-daemon, except none of "dbus-daemon --fork --session" instances will ever quit without me manually killing them. they stay running indefinitely irregardless of me logging out of the ssh bash session. is there a limit to how many of these idling dbus-daemon's it is possible to pile up?

on top of this, there seems to be no well known way to use a user's pre-existing dbus-daemon, conclusion reached after a few hours of googling. i for one am not able to figure out when exactly ~/.dbus/session-bus directory gets a session id in it and whether this id is reliable for exporting as $DBUS_SESSION_BUS_ADDRESS for another session or how long it'll last. trying to find processes that *might* be involved in a previous dbus session with /proc/PID/environ just doesn't sound right to me.

(granted i have not peeked dbus source yet)

this effectively leaves me with no properly working automated way to automatically launch dbus with no X to provide for things like gnome-keyring-daemon, subversion + whatever else.

please let me know if i'm missing something substantial here.
Comment 8 Simon McVittie 2011-01-19 11:00:19 UTC
I think there are (at least) two related bugs here:

(In reply to comment #4)
> dbus-launch could terminate when the launched child does, but it doesn't do
> that now and isn't designed/documented to do that now, iirc. It probably is not
> a compatible change so would be a new feature like --exit-with-launched-child

and

(In reply to comment #5)
> Since --exit-with-session polls stdin it keeps your terminal busy. This has the
> "nice" effect that if you run the Xwindow client script as a background
> process, dbus-launch eats up every second char you type on the terminal.

http://bugs.debian.org/453755 is the same thing as this. xdm and gdm avoid this because they redirect stdin from /dev/null, but slim doesn't; I've been able to reproduce this in a virtual machine with slim installed.

I'm sure I've seen another bug report here in which someone mentioned that --exit-with-session's stdin polling didn't really work either, and suggested removing it, but I can't find it right now.

Bug #19997 is vaguely related.
Comment 9 Simon McVittie 2011-07-14 09:50:52 UTC
Replying to the original bug:

(In reply to comment #0)
> It's launched from xinitrc(-common) as follows:
> 
> [ -x /usr/bin/dbus-launch -a -z "$DBUS_SESSION_BUS_ADDRESS" ] &&
> DBUS_LAUNCH="/usr/bin/dbus-launch --exit-with-session"

That just sets a variable. How is that variable (DBUS_LAUNCH) used?

Does this still happen with current Fedora packaging of current D-Bus?

This may have been fixed by this commit:

> commit 7d409700c354e7a35989053ba037750d320a308a
> Author: John (J5) Palmieri <johnp@redhat.com>
> Date:   2008-02-21 12:02:58 -0500
> 
>     fixes dbus-launch so the bus goes away when X does (Red Hat Bug #430412)
Comment 10 Simon McVittie 2011-07-14 09:58:25 UTC
(In reply to comment #1)
> I start dbus-launch right from within .bash_profile together with xinit
> (i.e. the traditional way):
> 
> if [ "`tty`" = "/dev/tty1" ]; then
>     startx="xinit -- :4 -br -quiet"
>     test -x /usr/bin/dbus-launch && \
>         startx="/usr/bin/dbus-launch --exit-with-session $startx"
>     $startx >& .xinitrc.log
> fi

This isn't right. To make dbus-launch exit reliably with your X session (i.e. make --exit-with-session work), you should start it from within X, so instead of:

    dbus-launch --exit-with-session xinit -- :4 -br -quiet

you should wrap dbus-launch around your initial X client, something like:

    xinit dbus-launch --exit-with-session ~/.xinitrc -- :4 -br -quiet

or run dbus-launch from within your .xinitrc:

    #!/bin/sh
    # .xinitrc
    dbus-launch --exit-with-session openbox

or just let the /etc/X11/Xsession machinery that Debian provides do its job - if you don't have a .xinitrc, Debian's default sources /etc/X11/Xsession, which runs things from /etc/X11/Xsession.d (including dbus-launch), then runs your ~/.xsession. Renaming your ~/.xinitrc to ~/.xsession will probably do the right thing.
Comment 11 Simon McVittie 2011-07-14 10:01:32 UTC
(In reply to comment #4)
> dbus-launch could terminate when the launched child does, but it doesn't do
> that now and isn't designed/documented to do that now, iirc.

Its code structure actually prevents it from doing that in a reliable way (it isn't the parent of the launched child, so it won't get SIGCHLD; and you want the launched child to be at the top of the process hierarchy so job control works).

Having something that *does* terminate with the launched child is basically a feature request, which I've cloned to <https://bugs.freedesktop.org/show_bug.cgi?id=39196>.
Comment 12 Simon McVittie 2011-07-14 10:12:25 UTC
(In reply to comment #5)
> The XWindow server is supposed to do a reset if the last client connection goes
> away. If dbus-launch keeps that last connection active (as the man page seems
> to indicate), then X never does a reset.

dbus-launch is designed to be used with an xinit-like arrangement, which terminates when the exec'd child process (a window manager or gnome-session or something) terminates.

> Even though the XWindow server might be running, the authentication scheme
> between Xserver and the clients might not be setup yet when dbus-launch comes
> into the game.

When used with X, dbus-launch is not designed to be run before X is functional.

> Since --exit-with-session polls stdin it keeps your terminal busy.

This is <https://bugs.freedesktop.org/show_bug.cgi?id=39197>

(In reply to comment #7)
> if i do "dbus-launch --exit-with-session" over ssh (because i would like
> dbus-daemon to quit when i log out or get disconnected)

You want "exec dbus-run-session bash" or some such, once my patches from Bug #39196 (adding dbus-run-session) have been merged. There doesn't seem to be any reliable way to detect logout/disconnection without either being in the foreground (like dbus-run-session would) or polling the terminal.

> if i do the regular "eval `dbus-launch --sh-syntax`" dance, i get a properly
> working dbus-daemon, except none of "dbus-daemon --fork --session" instances
> will ever quit without me manually killing them.

Yes, this is working as intended. You're running them in a way that isn't scoped to a particular session (although the only reliable indication of a session is X, which you don't have; the unwanted stdin polling is a side-effect of a mostly-failed attempt to detect tty session lifetime). So, they can only assume that the session lasts forever, until you indicate otherwise (by killing the dbus-daemon).

> on top of this, there seems to be no well known way to use a user's
> pre-existing dbus-daemon

Your new shell is not part of the previous session, so, no, there isn't.
Comment 13 Simon McVittie 2011-07-14 10:16:47 UTC
It looks as though this bug as initially filed (by Jan Houtsma) is a bug in either D-Bus from 2007, or Fedora's packaging of it. I'll close it if this can be resolved.

Subsequent comments from Harri and from Leho Kraav appear to be either separate bugs, missing features, or using dbus-launch incorrectly, which would be addressed by either fixing Bug #39196, fixing Bug #39197, or starting the X session differently. For those, please follow up on Bug #39196 or Bug #39197, as appropriate.
Comment 14 Simon McVittie 2012-02-08 06:50:13 UTC
(In reply to comment #13)
> It looks as though this bug as initially filed (by Jan Houtsma) is a bug in
> either D-Bus from 2007, or Fedora's packaging of it. I'll close it if this can
> be resolved.

Jan, is this bug still present? If not, please say so so we can close it.
Comment 15 John Galloway 2013-09-23 22:42:37 UTC
I think this problem still does exist (or at least we hit it quite often running Ubuntu 12.04 (so not the latest), dbus 1.4.18, kernel 3.2.0-52).
Comment 16 Jan Houtsma 2013-09-24 06:28:35 UTC
(In reply to comment #14)
> (In reply to comment #13)
> > It looks as though this bug as initially filed (by Jan Houtsma) is a bug in
> > either D-Bus from 2007, or Fedora's packaging of it. I'll close it if this can
> > be resolved.
> 
> Jan, is this bug still present? If not, please say so so we can close it.

I can not comment on this, because i don't run this server anymore. 

Regards, Jan
Comment 17 Simon McVittie 2014-09-10 15:54:42 UTC
(In reply to comment #15)
> I think this problem still does exist (or at least we hit it quite often
> running Ubuntu 12.04 (so not the latest), dbus 1.4.18, kernel 3.2.0-52).

Please open a separate bug for this with:

- steps that reproduce the bug
  (ideally starting with "install Ubuntu 12.04 (desktop) in a virtual
  machine" to rule out misconfiguration)
- what you expected to happen
- what happened
- details of how your distribution starts dbus

I don't think trying to track this together with a 7.5 year old bug that happens to have similar symptoms is really going to benefit anyone.
Comment 18 Simon McVittie 2014-09-10 15:56:19 UTC
(In reply to comment #16)
> I can not comment on this, because i don't run this server anymore. 

Then we can never know whether this bug has been fixed, so I don't think there's a great deal of value in having it in the bug-list. Resolving WORKSFORME; please open a new bug with details (like those requested in Comment #17) if the same symptoms are reproducible in a modern version of dbus.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.