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 759388 - mutter should allow the user to set XDG_SESSION_TYPE manually with an environment variable
mutter should allow the user to set XDG_SESSION_TYPE manually with an environ...
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: general
git master
Other Linux
: Normal enhancement
: ---
Assigned To: mutter-maint
mutter-maint
: 765053 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-12-12 20:53 UTC by bluescreen_avenger
Modified: 2016-07-22 02:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Allow the XDG_SESSION_TYPE to be set with an environment variable (477 bytes, patch)
2015-12-12 20:53 UTC, bluescreen_avenger
none Details | Review
Allow the XDG_SESSION_TYPE to be set with an environment variable (477 bytes, patch)
2015-12-17 00:29 UTC, bluescreen_avenger
none Details | Review
Allow the XDG_SESSION_TYPE to be set with an environment variable (532 bytes, patch)
2015-12-17 00:59 UTC, bluescreen_avenger
none Details | Review
Allow the XDG_SESSION_TYPE to be set with an environment variable (800 bytes, patch)
2015-12-17 01:35 UTC, bluescreen_avenger
none Details | Review
Sensible session type logic (3.31 KB, patch)
2016-04-20 09:02 UTC, Jouke Witteveen
none Details | Review
Sensible session type logic (4.55 KB, patch)
2016-06-14 10:34 UTC, Jouke Witteveen
none Details | Review
Sensible session type logic (4.51 KB, patch)
2016-06-14 15:41 UTC, Jouke Witteveen
none Details | Review
Well-defined session type logic (3.97 KB, patch)
2016-06-27 12:23 UTC, Jouke Witteveen
committed Details | Review

Description bluescreen_avenger 2015-12-12 20:53:09 UTC
Created attachment 317253 [details] [review]
Allow the XDG_SESSION_TYPE to be set with an environment variable

Currently to call gnome-shell directly with gnome-session, you can't call it as a display server on a TTY unless logind sets the XDG_SESSION_TYPE. You either need to call gnome-shell directly with --wayland --display-server (which causes the logoff button to not work), or modify .desktop files directly

I've submitted a patch to allow the XDG_SESSION_TYPE to be overridden by an environment variable
Comment 1 Jasper St. Pierre (not reading bugmail) 2015-12-15 17:28:23 UTC
Review of attachment 317253 [details] [review]:

::: src/core/main.c
@@ +352,3 @@
   gboolean is_wayland = FALSE;
 
+  session_type = g_strdup (g_getenv ("XDG_SESSION_TYPE"));

Does g_strdup even work on a NULL string?
Comment 2 bluescreen_avenger 2015-12-15 22:50:42 UTC
It seems to work... with out the env var set, within my weston session (where the session type is NOT set from logind), it starts it nested.
Comment 3 bluescreen_avenger 2015-12-15 23:03:42 UTC
I did it so that it could be something that wouldn't crash with free(), and so that I didn't have to put free() in an if statement
Comment 4 Matthias Clasen 2015-12-16 20:31:28 UTC
both g_strdup() and g_free() are NULL safe
Comment 5 Matthias Clasen 2015-12-16 20:33:49 UTC
That being said, I'm not in favor of adding an environment variable for this.
Comment 6 Jasper St. Pierre (not reading bugmail) 2015-12-16 20:34:01 UTC
Review of attachment 317253 [details] [review]:

OK then. Please remove braces around the single-line if, otherwise OK.
Comment 7 Jasper St. Pierre (not reading bugmail) 2015-12-16 20:34:24 UTC
(In reply to Matthias Clasen from comment #5)
> That being said, I'm not in favor of adding an environment variable for this.

I am.
Comment 8 bluescreen_avenger 2015-12-17 00:29:32 UTC
Created attachment 317539 [details] [review]
Allow the XDG_SESSION_TYPE to be set with an environment variable
Comment 9 Jasper St. Pierre (not reading bugmail) 2015-12-17 00:53:13 UTC
Uh, the braces are still in? Still missing a commit message, too.
Comment 10 bluescreen_avenger 2015-12-17 00:59:24 UTC
Created attachment 317541 [details] [review]
Allow the XDG_SESSION_TYPE to be set with an environment variable

Allow the XDG_SESSION_TYPE to be set with an environment variable
Comment 11 bluescreen_avenger 2015-12-17 01:35:36 UTC
Created attachment 317542 [details] [review]
Allow the XDG_SESSION_TYPE to be set with an environment variable
Comment 12 Matthias Clasen 2015-12-17 15:16:05 UTC
How does this overlap/interfere/conflict with the GNOME_SHELL_SESSION_MODE environment variable ?
Comment 13 Florian Müllner 2015-12-17 16:51:31 UTC
(In reply to Matthias Clasen from comment #12)
> How does this overlap/interfere/conflict with the GNOME_SHELL_SESSION_MODE
> environment variable ?

Not at all.

There might be an issue if the session is created with logind and the variable is used to overwrite the session type with something else, but that's probably obscure enough to ignore.
Comment 14 Jasper St. Pierre (not reading bugmail) 2015-12-17 17:27:25 UTC
So, the reason we're doing this is because when someone starts gnome-session from a TTY, the session type will be "tty", which means we always launch in X11 mode.
Comment 15 Florian Müllner 2015-12-17 17:33:55 UTC
Couldn't we handle that by changing the check to session_type != "x11"?
Comment 16 Jasper St. Pierre (not reading bugmail) 2015-12-17 17:37:14 UTC
There are also people who want to launch X11 sessions from a TTY.
Comment 17 Matthias Clasen 2015-12-17 17:55:07 UTC
Launching gnome-session from a TTY is not a supported use case.

Adding random environment variables to make an undefined set of ways to launch something that looks like a session work a little better is not making the overall code base better or more stable or supportable.
Comment 18 bluescreen_avenger 2015-12-18 04:17:30 UTC
IMHO XDG_SESSION_TYPE is not that much of a random environment variable. it's supposed to be set by logind, (but in some cases it's not)
Comment 19 bluescreen_avenger 2015-12-19 22:05:20 UTC
I also think this would be a good workaround for 
https://bugzilla.gnome.org/show_bug.cgi?id=758658
?
Comment 20 bluescreen_avenger 2016-01-05 23:25:38 UTC
Is it decided that this patch won't be merged?
Comment 21 Florian Müllner 2016-04-15 09:06:23 UTC
*** Bug 765053 has been marked as a duplicate of this bug. ***
Comment 22 Jouke Witteveen 2016-04-15 09:11:58 UTC
The patches in 765053 have a slightly different reasoning. Apart from the desire to use XDG_SESSION_TYPE when the logind session type is neither "wayland" nor "x11", it has been expressed that wayland should become the default. The current code does not reflect that.

The first patch in 765053 does not include any reference to XDG_SESSION_TYPE and merely changes the fallback from x11 to wayland, mostly in line with Florian Müllner's comment 15.
Comment 23 Florian Müllner 2016-04-15 10:16:47 UTC
(In reply to Jouke Witteveen from comment #22)
> The patches in 765053 have a slightly different reasoning. Apart from the
> desire to use XDG_SESSION_TYPE when the logind session type is neither
> "wayland" nor "x11", it has been expressed that wayland should become the
> default. The current code does not reflect that.

Well, wayland should become the default in the sense that GDM should open a logind session of type "wayland" by default. Running gnome-session from a logind session that is neither of type "wayland" nor "x11" is not really a supported use case, though there certainly are people who have it in their .xinitrc. If we are going to break that, I'd rather throw an "Unsupported session type" assertion than opening the same can of worms on wayland ...
Comment 24 Jouke Witteveen 2016-04-15 10:33:20 UTC
The problem is that the logind session type is read-only. This means it is impossible to upgrade a text session to a graphical session. There is no technical reason for this limitation and it can be made to work properly given the right semantics.

The patch in this bug gives XDG_SESSION_TYPE precedence over the logind session type which, I think, is a bad idea with potential inconsistent behavior. Precisely because the logind session type is read-only, it should be trusted more than XDG_SESSION_TYPE.
Furthermore, if the XDG_SESSION_TYPE is of no use, the patch in this bug defaults to x11, which is not what we want.

The second patch from Bug 765053 implements well defined logic:
- the logind session type takes precedence over XDG_SESSION_TYPE
- the first of these two places where a usable value ("wayland" or "x11", currently) is found will be used
- the default/fallback is wayland

Support through .xinitrc is easily achieved using the line

  export XDG_SESSION_TYPE=x11

This can also be set in whatever sources the .xinitrc. In many cases it might even be possible to set the right logind session type for sessions using .xinitrc.

In conclusion, I think the second patch of Bug 765053 implements well-defined and maintainable behavior that re-enables use cases that were supported but got broken for no technical reason.
Comment 25 Florian Müllner 2016-04-15 11:12:54 UTC
(In reply to Jouke Witteveen from comment #24)
> The problem is that the logind session type is read-only. This means it is
> impossible to upgrade a text session to a graphical session.

So? It's not possible to "downgrade" a graphical session to a text session, it's not possible to "upgrade" an x11 session to a wayland session, ...

Two system components - logind and mutter/gnome-shell - which assume differing session types has potential for subtle bugs that are hard to debug (because nobody will be able to reproduce the issue when the reporter forgets to mention that the session is launched via "startw").


> Support through .xinitrc is easily achieved using the line
> 
>   export XDG_SESSION_TYPE=x11

Well, I was partly referring to:

(In reply to Jouke Witteveen from comment #22)
> The first patch in 765053 does not include any reference to XDG_SESSION_TYPE
> and merely changes the fallback from x11 to wayland

But even if we start reading XDG_SESSION_TYPE, changing the default "graphical tty" fallback to wayland will break existing setups, so we'll still get the complaints.
Comment 26 Florian Müllner 2016-04-15 11:17:20 UTC
(In reply to Florian Müllner from comment #25)
> Two system components - logind and mutter/gnome-shell - which assume
> differing session types has potential for subtle bugs that are hard to debug

One option around this would be asking the logind developers to support something like:

  loginctl start-session --type=wayland gnome-session
or
  loginctl start-session --type=x11 gnome-session

for starting a graphical session from a text one. There'll probably still be issues with screen locking, but at least logind and GNOME would have the same view of the session type ...
Comment 27 Jouke Witteveen 2016-04-15 13:04:04 UTC
(In reply to Florian Müllner from comment #25)
> (In reply to Jouke Witteveen from comment #24)
> > The problem is that the logind session type is read-only. This means it is
> > impossible to upgrade a text session to a graphical session.
> 
> So? It's not possible to "downgrade" a graphical session to a text session,
> it's not possible to "upgrade" an x11 session to a wayland session, ...

I don't see why not. With any of the proposed patches in place, you can make a text session graphical and by stopping the graphical part you get back the text session. This also has worked for as long as startx has.

> > Two system components - logind and mutter/gnome-shell - which assume
> > differing session types has potential for subtle bugs that are hard to debug
> 
> One option around this would be asking the logind developers to support
> something like:
> 
>   loginctl start-session --type=wayland gnome-session
> or
>   loginctl start-session --type=x11 gnome-session
> 
> for starting a graphical session from a text one. There'll probably still be
> issues with screen locking, but at least logind and GNOME would have the
> same view of the session type ...

Possibly, starting a new session also makes it impossible to shutdown/reboot. I think the use case at hand is really about promoting text sessions to graphical ones.

For all I care the logind session type could be made writable. Of course, this is potentially dangerous, but as far as I can tell it is not _always_ dangerous.

> > Support through .xinitrc is easily achieved using the line
> > 
> >   export XDG_SESSION_TYPE=x11
> 
> Well, I was partly referring to:
> 
> (In reply to Jouke Witteveen from comment #22)
> > The first patch in 765053 does not include any reference to XDG_SESSION_TYPE
> > and merely changes the fallback from x11 to wayland
> 
> But even if we start reading XDG_SESSION_TYPE, changing the default
> "graphical tty" fallback to wayland will break existing setups, so we'll
> still get the complaints.

We should be getting complaints! The status-quo is ugly and at the very least we should indeed throw an "Unsupported session type" when the logind session type is not sane (and maybe XDG_SESSION_TYPE too). Every setup without a proper logind session type should be considered broken in the current state of affairs. The thing with supporting XDG_SESSION_TYPE is that it provides an easy way to fix these broken setups.
Comment 28 Florian Müllner 2016-04-15 13:52:47 UTC
(In reply to Jouke Witteveen from comment #27)
> > So? It's not possible to "downgrade" a graphical session to a text session,
> > it's not possible to "upgrade" an x11 session to a wayland session, ...
> 
> I don't see why not. With any of the proposed patches in place, you can make
> a text session graphical and by stopping the graphical part you get back the
> text session. This also has worked for as long as startx has.

But you can not log into a graphical session and change it to become a text session. My point that "upgrading" the session type isn't something that generally works, but what works and what not is fairly random (or if you prefer, something best filed under "historical baggage") still stands.


> > But even if we start reading XDG_SESSION_TYPE, changing the default
> > "graphical tty" fallback to wayland will break existing setups, so we'll
> > still get the complaints.
> 
> We should be getting complaints! The status-quo is ugly and at the very
> least we should indeed throw an "Unsupported session type" when the logind
> session type is not sane (and maybe XDG_SESSION_TYPE too).

Now I'm confused. Don't you want to change the current ugly behavior of assuming "x11" if the session type is neither "x11" nor "wayland" to assuming "wayland" instead, which is just as ugly?
Comment 29 Jouke Witteveen 2016-04-15 14:10:30 UTC
(In reply to Florian Müllner from comment #28)
> (In reply to Jouke Witteveen from comment #27)
> My point that "upgrading" the session type isn't something that
> generally works, but what works and what not is fairly random (or if you
> prefer, something best filed under "historical baggage") still stands.

Indeed, the fact that it had worked for the past decade(s) counts as historical baggage and might not be a reason to implement it today. I do think the use case (startx) should remain covered, also with wayland (`startw').

The easiest way I can currently think of to have a text login prompt followed by a graphical session is to set the session type to "wayland", already for the textual part of the session. This is of course a terrible hack.

> > > But even if we start reading XDG_SESSION_TYPE, changing the default
> > > "graphical tty" fallback to wayland will break existing setups, so we'll
> > > still get the complaints.
> > 
> > We should be getting complaints! The status-quo is ugly and at the very
> > least we should indeed throw an "Unsupported session type" when the logind
> > session type is not sane (and maybe XDG_SESSION_TYPE too).
> 
> Now I'm confused. Don't you want to change the current ugly behavior of
> assuming "x11" if the session type is neither "x11" nor "wayland" to
> assuming "wayland" instead, which is just as ugly?

After your Comment 23 I can think of only two ways forward:
1) Throw an error whenever the logind session type is not supported
2) Implement a clear logic involving XDG_SESSION_TYPE

For option 2 the question comes up what the default value should be (we could still choose to throw an error if $XDG_SESSION_TYPE is also not supported). Given the behavior of gdm, I think the proper default would be "wayland".

Indeed, in both these cases startx will potentially break, although with the second option there is an easy fix. Any startw case is already broken by the current code, even though it worked with 3.18.
Comment 30 Jouke Witteveen 2016-04-19 09:37:05 UTC
The current code, following Ray Strode's 8ec0c99f, checks the session types of all active sessions of the user if the session type of the current session could not be determined. These sessions may even be on different seats than the current session. Why is this? I still feel the best is to:

1) check whether the current session is of supported type
2) otherwise, check whether XDG_SESSION_TYPE is supported
3) otherwise, throw an error (no fallback)

Any chance of a patch along these lines getting accepted?
Comment 31 Jouke Witteveen 2016-04-20 09:02:09 UTC
Created attachment 326391 [details] [review]
Sensible session type logic

1) check whether the current session is of supported type
2) otherwise, check whether XDG_SESSION_TYPE is supported
3) otherwise, throw an error (no fallback)
Comment 32 Ray Strode [halfline] 2016-04-21 17:29:55 UTC
(In reply to Jouke Witteveen from comment #30)
> The current code, following Ray Strode's 8ec0c99f, checks the session types
> of all active sessions of the user if the session type of the current
> session could not be determined. These sessions may even be on different
> seats than the current session. Why is this?
There's a concerted push to start things in the scope of systemd --user, not in the scope of a session. For instance, these days dbus-daemon is started outside of any given session (so it's "user bus" not a "session bus" now) and likewise anything dbus activated starts that way.  The plan going forward wrt to multi-seat (though it's not yet implemented) is to show a dialog like

   User '%s' is currently logged into another seat. [ Wait ] [ Force Log Out other session ]
Comment 33 Ray Strode [halfline] 2016-04-21 17:50:40 UTC
so my thoughts are:

1) keeping startx working has some legacy value. 
2) i care a lot less about being able to run graphical wayland sessions on VTs that are registered as non-graphical. wayland is supposed to be our chance to break away from weird things like that.
3) Now that doesn't mean we shouldn't be able to trigger a new wayland session on a new VT to start from the command line.  Something like Florian proposes in comment 26 would be useful.  It could be in logind or gdm.  Of course, if GDM isn't running (at least in headless mode) then screen lock won't work.
Comment 34 Jouke Witteveen 2016-04-21 18:28:01 UTC
Does that mean the proposed patch is out of the question? I do think it is an improvement over the current situation. It provides more flexibility, clearer logic and a more explicit attitude regarding startx. It will keep working, but users will be confronted with the fact that things are changing.
Comment 35 Ray Strode [halfline] 2016-04-21 18:57:09 UTC
i don't think startx will continue to work with that patch ? Unless i'm missing something, the user will have to set XDG_SESSION_TYPE=x11 before running startx , right?
Comment 36 Florian Müllner 2016-04-21 19:12:42 UTC
Yes, it's at the same time breaking a legacy feature and bringing it into the wayland world.
Comment 37 Ray Strode [halfline] 2016-04-21 19:48:31 UTC
so, for the time being, we could let getenv ("DISPLAY") != NULL and logind session-type=="tty" imply X backend I guess and otherwise error out?
Comment 38 Jouke Witteveen 2016-04-21 19:50:38 UTC
(In reply to Florian Müllner from comment #23)
> Running gnome-session from a
> logind session that is neither of type "wayland" nor "x11" is not really a
> supported use case, though there certainly are people who have it in their
> .xinitrc. If we are going to break that, I'd rather throw an "Unsupported
> session type" assertion than opening the same can of worms on wayland ...

The alternative, I think, is to accept the patch without the part that pulls in XDG_SESSION_TYPE. If startx is "not really a supported use case" then it should not be supported and throw an error.
Comment 39 Jouke Witteveen 2016-04-21 21:44:58 UTC
By the way, what exactly is this 'can of worms' associated with supporting an XDG_SESSION_TYPE fallback also for Wayland?
Comment 40 Jouke Witteveen 2016-04-24 13:07:53 UTC
It occurred to me that we can install a file with the line

    export XDG_SESSION_TYPE=x11

into /etc/X11/xinit/xinitrc.d/.
That way, startx will keep working for many/most setups.
Comment 41 Jouke Witteveen 2016-06-14 10:34:26 UTC
Created attachment 329772 [details] [review]
Sensible session type logic

This patch has it all.

It has a clear logic for inferring the session type (same as comment #31) and sets it to x11 by default for xinit-based sessions.

All but the most broken legacy setups will remain working and modern (wayland) setups that are broken now get a proper error message.
Comment 42 Ray Strode [halfline] 2016-06-14 15:39:31 UTC
Review of attachment 329772 [details] [review]:

::: data/Makefile.am
@@ +24,3 @@
 convert_DATA = mutter-schemas.convert
 
+xinitrcdir = $(sysconfdir)/X11/xinit/xinitrc.d

this dir is distro specific (won't work on debian for instance). to be honest, we've been trying to get away with loading shell scripts at login.
Comment 43 Ray Strode [halfline] 2016-06-14 15:41:03 UTC
can you give comment 37 a whirl ?
Comment 44 Jouke Witteveen 2016-06-14 15:41:21 UTC
Created attachment 329809 [details] [review]
Sensible session type logic

We should not even bother testing whether XDG_SESSION_TYPE is already set in the xinitrc script: If the variable is not equal to "x11" it is wrong for xinit anyway.
Comment 45 Jouke Witteveen 2016-06-14 15:46:07 UTC
In reply to comment 43 (comment 44 was posted simultaneously):
That would leave no way to start a wayland session from the console, which is precisely what I am after for myself. Until we can upgrade sessions to graphical ones, or start new sessions from running sessions, there appears to be no way to run mutter on wayland without a desktop manager. At least with this patch there is.

Indeed, Debian does not use the xinitrc.d dir. I assume their packagers are familiar with the troubles it can give, since most of the other distros do use it. Mind you: without the xinitrc snippet you can still use it through xinit, you just have to make sure XDG_SESSION_TYPE=x11 is present somewhere else. This is a good idea anyway in such legacy setups.
Comment 46 Jouke Witteveen 2016-06-16 08:42:37 UTC
Note that systemd too installs a script, 50-systemd-user.sh, in $(sysconfdir)/X11/xinit/xinitrc.d.
Comment 47 Jouke Witteveen 2016-06-27 12:23:56 UTC
Created attachment 330432 [details] [review]
Well-defined session type logic

Similar to the previous patch, but instead of mandating xinit sessions to set XDG_SESSION_TYPE, fall back to the X backend when we find

getenv ("DISPLAY") != NULL (or getenv ("MUTTER_DISPLAY") != NULL) and logind session-type=="tty"

As suggested in comment #37.
This does away with the xinitrc script.
Comment 48 Jouke Witteveen 2016-07-19 09:19:42 UTC
After three weeks, what is the verdict on the last patch? Does it satisfy everyone's needs?
Comment 49 Ray Strode [halfline] 2016-07-19 15:11:02 UTC
Review of attachment 330432 [details] [review]:

yea good enough for me. do you have commit access?
Comment 50 Jouke Witteveen 2016-07-20 06:59:30 UTC
Awesome!

Nope, no commit access on my side.