After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 360475 - No session management for programs started from g-s-d
No session management for programs started from g-s-d
Status: RESOLVED FIXED
Product: gnome-session
Classification: Core
Component: gnome-session
2.23.x
Other All
: Normal normal
: ---
Assigned To: Session Maintainers
Session Maintainers
: 353157 393869 413723 448659 (view as bug list)
Depends on:
Blocks: 353157 540537
 
 
Reported: 2006-10-07 19:30 UTC by Michael Hofmann
Modified: 2008-08-05 00:21 UTC
See Also:
GNOME target: 2.18.x
GNOME version: 2.17/2.18


Attachments
gnome-session patch to use new dbus api (6.96 KB, patch)
2008-07-13 05:45 UTC, Ray Strode [halfline]
committed Details | Review

Description Michael Hofmann 2006-10-07 19:30:08 UTC
Please describe the problem:
All programs started with g-s-d keybindings get no session management.

Gnome-settings-daemon is now started from dbus and dbus starts gnome-session, so there is no SESSION_MANAGER env variable for dbus and therefore also not for g-s-d.

Steps to reproduce:
- set a hotkey to the email program (gnome-keybinding-properties) 
- press the hotkey - evolution starts


Actual results:
- look at /proc/<evo-pid>/environ -> no SESSION_MANAGER
- startup the session-manager: no entry for evolution

Expected results:
Session management for the started apps. This bug also disables control of the current session, you can't use a shortcut for logout because this calls gnome-session-save --kill.

Does this happen every time?


Other information:
A workaround would be reverting to the old g-s-d startup code without dbus.
Comment 1 Jan de Groot 2006-10-08 13:06:10 UTC
Launching dbus from gnome-session would be the fix for this issue.

http://bugzilla.gnome.org/show_bug.cgi?id=336237 contains patches to fix the problem. The last patch that I uploaded is what we use on archlinux and fixes most regressions we found while upgrading to gnome 2.16.
Comment 2 Sebastien Bacher 2006-10-08 20:07:50 UTC
Ubuntu bug about that: https://launchpad.net/products/control-center/+bug/62163
Comment 3 Jens Granseuer 2007-02-25 16:13:46 UTC
Since the patches in bug 336237 have been committed, this should be fixed now, right?
Comment 4 Bastien Nocera 2007-02-25 22:19:08 UTC
(In reply to comment #3)
> Since the patches in bug 336237 have been committed, this should be fixed now,
> right?

There's a simple check: Does the "log out" keyboard shortcut work?

Comment 5 Jens Granseuer 2007-03-02 16:51:22 UTC
Well, it doesn't...
Comment 6 Jens Granseuer 2007-03-02 16:55:58 UTC
*** Bug 413723 has been marked as a duplicate of this bug. ***
Comment 7 Jan de Groot 2007-03-02 19:02:50 UTC
This bug is fixed partially, but it requires action from the user/distribution side: dbus must be started from within gnome-session. Most distributions start dbus from an xinit script to make sure it is running. Gnome-session only starts a dbus session bus when none is running yet. When dbus is launched before gnome-session, variables like SESSION_MANAGER, GNOME_KEYRING_SOCKET and other environment options set from gnome-session are not available to programs launched from dbus.
Comment 8 Jens Granseuer 2007-03-03 11:18:52 UTC
That doesn't seem to work properly, either, then. If I don't start the session bus myself, g-s-d cannot connect to dbus (and crashes, but that's another bug). Anything else that needs to be done?

That is with control-center and gnome-session both at 2.17.92.
Comment 9 Derek Dolney 2007-03-03 16:13:33 UTC
Works for me, since moving session dbus to g-s-d. My session was dbus starting in an xinit script. It works now that I removed it. I had a crash, too, which I fixed somehow by blowing away my gnome conf and starting over (by removing ~/.gconf*,~/.gnome*, anything gnome related). I suggest adding a new user to try a fresh gnome configuration before you go through that work.

Also, I still have a system dbus started by rc-scripts (dbus-daemon --system). I'm not sure if that's what you need.
Comment 10 Jens Granseuer 2007-03-06 18:32:51 UTC
Not sure what the problem is yet, but when I remove the start of the session bus from my login script, the machine-id file somehow gets removed, making session startup fail.

Should not be related to GNOME in any way, though, so closing as fixed.
Comment 11 Derek Dolney 2007-03-19 16:04:37 UTC
*** Bug 353157 has been marked as a duplicate of this bug. ***
Comment 12 Jens Granseuer 2007-04-28 18:49:53 UTC
*** Bug 393869 has been marked as a duplicate of this bug. ***
Comment 13 Jens Granseuer 2007-06-18 15:37:02 UTC
*** Bug 448659 has been marked as a duplicate of this bug. ***
Comment 14 Ray Strode [halfline] 2008-07-07 15:08:18 UTC
Hey guys, this is causing bug 540537.  Since the session is scoped to the session bus, the session bus has to be started before programs in the session.

We probably need to fix dbus to have a SetActivationEnvironment method or some such that lets things like SESSION_MANAGER get added to activated clients.
Comment 15 Ray Strode [halfline] 2008-07-07 15:22:56 UTC
Barring fixing dbus, we should make sure that dbus daemon is started earlier before bonobo-activation-server could be activated.  So maybe just after getting SESSION_MANAGER and starting keyring daemon.
Comment 16 Ray Strode [halfline] 2008-07-09 15:16:30 UTC
So I looked into this a bit.

I think the reporter in bug 540537 is still using gnome-session 2.22 (I asked so we'll find out shortly). 2.23 actually starts dbus very early, so bug 540537 shouldn't be manifesting itself the way described if the reporter were using 2.23.

That does mean that 2.23 regressed the fix in this report though.  While SESSION_MANAGER gets set before dbus is started, GTK_MODULES and the previously mentioned GNOME_KEYRING_SOCKET won't be.

Those don't get started until later.  We could add another phase before starting dbus to the new gnome-session, say PRESTARTUP or something and set, GTK_MODULES and start keyring then. Since PRESTARTUP would be before the session bus is started, it couldn't use the session bus to set environment.  It'd have to be a dbus peer-to-peer connection or some other ipc mechanism (maybe just print the variables and read them).

But it's really the wrong approach, I think, because dbus should be started before gnome-session.  That's how it was designed.  We should just fix the bug where you can't adjust the activation environment.  I'll look into doing that.
Comment 17 Dan Winship 2008-07-09 16:05:40 UTC
(In reply to comment #16)
> But it's really the wrong approach, I think, because dbus should be started
> before gnome-session.  That's how it was designed.

(Which, IMHO, was a design error; we already had two processes competing over who was the root of the session (gnome-session and bonobo-activation-server). We really didn't need a third. In a perfect world, gnome-session would be like Apple's launchd, except with loadable modules, and dbus-daemon and b-a-s would be libraries that it would load in to handle those kinds of apps...)

> We should just fix the bug
> where you can't adjust the activation environment.

FWIW, that still doesn't fix the problem :-}. If you set the "Run a terminal" keybinding in gnome-keybinding-properties, and then use it, that terminal might not have $SSH_AUTH_SOCK set, because it will be started by gnome-settings-daemon, which might have been started before gnome-keyring-manager was, and so it doesn't matter whether or not gnome-keyring-manager tells dbus-daemon about the variable or not because it's already too late at that point.

IIRC, KDE solves this by having all launching be done by a central launching service. (Eg, when you pressed the "Run a terminal" key, g-s-d would not launch gnome-terminal directly, it would ask gnome-session or dbus-daemon to do it, and they would have the correct environment set up, and so you'd win.) Although they also have a DCOP/D-Bus call to fetch the value of $SESSION_MANAGER from ksmserver for when apps get started without that being set, so apparently the central launcher doesn't solve everything.
Comment 18 Ray Strode [halfline] 2008-07-10 02:10:38 UTC
bonobo-activation-server was never trying to be the root of the session.  Up until the patch from bug 530615 that tied it to the session (via the session bus which led to bug 540537) it was per user, not per session.

I agree we don't need 3 processes competing to try to define the session scope, but I think it needs to be the session bus.  Note some things run in the user session before gnome-session is ever started.  gnome-session is too late in the process to start the session bus.

Why do you think it's a design error to start dbus first?

Your scenario doesn't invalidate the need for adding the session bus interface to adjust the activation environment.  It just means the session manager needs to be careful when ordering what services get started.  That's true anyway, though.  I mean it's true regardless of if the session manager starts dbus or dbus gets started first.
Comment 19 Havoc Pennington 2008-07-10 02:33:45 UTC
The dbus intent was to be the session root and lifecycle "grounding point" for the desktop. When it (or the X server) exits, everything else is supposed to exit.

Can be changed of course, but one advantage is that programs could then set environment variables and launch services in a cross-desktop way.

The other rationale is that environment variables are simply wrong, except for legacy purposes. The main reason they are wrong is that they depend on process inheritance and can't be changed without logging out and back in. 

Dan made the same point in http://lists.freedesktop.org/archives/dbus/2008-May/009759.html

Not that legacy stuff can be summarily dropped, but I would argue that the system design should revolve around the proper way to do things now, which is with bus names not env variables. If using bus names instead of env variables, you need dbus to be the root.

In the end it probably doesn't matter that much, in practice the SM and dbus-daemon have to work as a unified whole and together start up the session.

There was an older thread and I thought a bug about this on the dbus list and bugzilla respectively, but I can't find either one, so maybe my imagination. Not sure there were any big insights anyway other than "yeah, there should be some type of AddEnvVariable thing in the bus API"

The dbus patch should be trivial, afaik.

There's also a possible hack without modifying dbus which is to put a launch helper in the config file like the one the system bus uses to set privileges, but, I don't know why you'd do it that way - it's harder than just putting an AddToEnvironment thing in the bus itself.

Comment 20 Havoc Pennington 2008-07-10 02:51:14 UTC
> (Which, IMHO, was a design error; we already had two processes competing over
> who was the root of the session (gnome-session and bonobo-activation-server).
> We really didn't need a third. In a perfect world, gnome-session would be like
> Apple's launchd, except with loadable modules, and dbus-daemon and b-a-s would
> be libraries that it would load in to handle those kinds of apps...)

Just reading this more slowly, fwiw the historical goal was not to be a third but to replace those two and also dcop and ICE in this role. There was a plan. ;-)

An arbitrary old mail that mentions it offhand:
http://osdir.com/ml/freedesktop.dbus/2004-07/msg00079.html

Hmm, same google search also turned up 2005 discussion of setting env variables:
http://mail.gnome.org/archives/desktop-devel-list/2005-August/msg00024.html

b-a-s was the most broken of the pre-existing ones since it was per-user instead of per-session, while gnome-session didn't have the service-discovery capability.
So at the time the existing stuff did not really solve the problem, and certainly not in a cross-desktop way.

Comment 21 Dan Winship 2008-07-10 10:38:59 UTC
(In reply to comment #18)
> Your scenario doesn't invalidate the need for adding the session bus interface
> to adjust the activation environment.  It just means the session manager needs
> to be careful when ordering what services get started.

My point was that as long as you have arbitrary processes setting environment variables, and arbitrary processes launching child processes, then you can't just "be careful", because there will always be a scenario that will break whatever ordering you chose. (And then from there to "environment variables suck", as Havoc said.)

Anyway, originally I wrote something explicitly agreeing with you that we should still do the dbus Setenv thing anyway, but I guess I deleted that while rewriting the comment. Oops. Anyway, yes, you should write the Setenv thing.

> Why do you think it's a design error to start dbus first?

It's not "starting dbus first" that's the design error, it's the fact that dbus-daemon assumes and requires that it is the session root, but it doesn't actually replace the *other* process in the system that assumes and requires that it is the session root, and so to make things work at all you end up needing a *third* session root (dbus-launch) that does nothing except manage the two other session roots...
Comment 22 Ray Strode [halfline] 2008-07-10 20:19:42 UTC
I've posted the dbus patch here:

http://lists.freedesktop.org/archives/dbus/2008-July/010059.html

We only care about the ordering the few well known legacy environment variables that are causing us problems I think.

We don't need to solve this problem for arbitrary processes and environment variables.
Comment 23 Ray Strode [halfline] 2008-07-13 05:45:25 UTC
Created attachment 114467 [details] [review]
gnome-session patch to use new dbus api

The discussed dbus api is in dbus git master now.  The above patch changes gnome-session to use the api.
Comment 24 Frederic Crozat 2008-07-18 17:14:44 UTC
some comment on the patch : 

-could you merge the ChangeLog (or just drop it), otherwise it doesn't apply directly
-could you remove the warning in gnome-session " WARNING **: dbus-daemon is already running: processes launched by D-Bus won't have access to $SESSION_MANAGER!" since it is becoming false (when dbus supports the new api) ?
Comment 25 Ray Strode [halfline] 2008-07-28 19:28:14 UTC
I honestly think we shouldn't be starting dbus manually at all anyway.

If you call dbus_bus_get () and dbus isn't running, it will get started.  So we should either

1) drop the dbus starting code entirely and rely on distros to start the message bus daemon as it was originally designed

or

2) drop the dbus starting code entirely and set DBUS_SESSION_BUS_ADDRESS to the autolaunched bus address after the dbus_bus_get () call if DBUS_SESSION_BUS_ADDRESS isn't already set (it's a property on the root window iirc)

Either way, I think we should drop the dbus starting code, including the warning you mention.
Comment 26 Havoc Pennington 2008-07-29 03:46:59 UTC
Should do 1) so there's only one codepath, the one in dbus-launch, imo

Plus it's a tiny bit more efficient

The autolaunch stuff is kind of a rube goldberg device, it's a ton of complex code and it's simpler to just say "the daemon should always already be launched"
Comment 27 Frederic Crozat 2008-07-29 09:01:52 UTC
with my distro hat, I concur with Ray and Havoc : one code path is way better to debug dbus stuff :)
Comment 28 Vincent Untz 2008-07-29 10:53:41 UTC
(In reply to comment #25)
> I honestly think we shouldn't be starting dbus manually at all anyway.
> 
> If you call dbus_bus_get () and dbus isn't running, it will get started.  So we
> should either
> 
> 1) drop the dbus starting code entirely and rely on distros to start the
> message bus daemon as it was originally designed

IIRC, the dbus launching code was added at the request of some distributor (don't remember if it's freebsd or debian). So relying on distros who don't want to do this is... weird :-)
Comment 29 Frederic Crozat 2008-07-29 11:35:33 UTC
in that case, it should be disable at compile time.
Comment 30 Dan Winship 2008-07-29 13:37:49 UTC
(In reply to comment #28)
> IIRC, the dbus launching code was added at the request of some distributor
> (don't remember if it's freebsd or debian).

NetBSD. bug 336237.

It seems like an easy solution to the problem there would be to provide a "gnome-dbus-session" wrapper script:

    #!/bin/sh

    exec dbus-launch --exit-with-session gnome-session "$@"

and then OSes/distros that don't want to do any session-startup-wrapping can just use that script as the GNOME session launcher rather than using gnome-session directly.

(Or we could just throw the real gnome-session into $libexecdir and have $bindir/gnome-session be a script, that checks if dbus is already running, and starts it if it isn't, and then everyone could just always use gnome-session, regardless of whether or not their session startup was dbusified or not.)
Comment 31 William Jon McCann 2008-08-05 00:21:44 UTC
Ray's option 1 it is.  Fixed in trunk.  Thanks.