Subject: please set DESKTOP_SESSION and XDG_CURRENT_DESKTOP like local sessions

From: Ryan Tandy <[email-masked]>
Date: Thu, 29 Jan 2015 10:17:40 -0800

Package: x2goserver
Version: 4.1.0.0-0~1215~ubuntu14.04.1
Severity: wishlist

Hi,

In Ubuntu before 15.04, and Debian jessie, the DESKTOP_SESSION for GNOME 
Flashback is actually "gnome-fallback". In particular, this name is 
found in /etc/upstart-xsessions while "gnome-flashback" is not, which 
prevents Upstart user sessions from being enabled. ("gnome-session 
--session=gnome-flashback is still the correct command, though.)

Furthermore, recent (Ubuntu >= 13.10, Debian jessie) login managers also 
export XDG_CURRENT_DESKTOP using the value of the DesktopNames field 
from the session file. This variable is starting to gain wide use by 
applications that care about the desktop environment they run under.

I can write a patch that adds all this information to x2goruncommand in 
the existing format. However it occurs to me that it might make more 
sense to parse the files in /usr/share/xsessions and use the information 
directly instead of duplicating it. Please let me know which you'd 
prefer to see.

-- 
Ryan Tandy - Programmer/Analyst                      [email-masked]
School District 63 (Saanich)                           +1 250 652 7385

---

From: Mike Gabriel <[email-masked]>
Date: Thu, 05 Feb 2015 11:31:05 +0000

Hi Ryan,

On  Do 29 Jan 2015 19:17:40 CET, Ryan Tandy wrote:

> In Ubuntu before 15.04, and Debian jessie, the DESKTOP_SESSION for  
> GNOME Flashback is actually "gnome-fallback". In particular, this  
> name is found in /etc/upstart-xsessions while "gnome-flashback" is  
> not, which prevents Upstart user sessions from being enabled.  
> ("gnome-session --session=gnome-flashback is still the correct  
> command, though.)
>
> Furthermore, recent (Ubuntu >= 13.10, Debian jessie) login managers  
> also export XDG_CURRENT_DESKTOP using the value of the DesktopNames  
> field from the session file. This variable is starting to gain wide  
> use by applications that care about the desktop environment they run  
> under.
>
> I can write a patch that adds all this information to x2goruncommand  
> in the existing format. However it occurs to me that it might make  
> more sense to parse the files in /usr/share/xsessions and use the  
> information directly instead of duplicating it. Please let me know  
> which you'd prefer to see.

x2goruncommand actually requires a complete rewrite (and has to be  
based on freedesktop.org specs).

Until that happens, let's hard-code this stuff. Please provide your patch.

Thanks!
Mike
-- 

DAS-NETZWERKTEAM
mike gabriel, herweg 7, 24357 fleckeby
fon: +49 (1520) 1976 148

GnuPG Key ID 0x25771B31
mail: [email-masked], http://das-netzwerkteam.de

freeBusy:
https://mail.das-netzwerkteam.de/freebusy/m.gabriel%40das-netzwerkteam.de.xfb

---

From: Ryan Tandy <[email-masked]>
Date: Tue, 17 Mar 2015 12:11:51 -0700

Control: tags -1 + patch

Hi! Sorry it's taken me so long to get back to you about this.

>Until that happens, let's hard-code this stuff. Please provide your patch.

Well, I started doing that, but it ended up being a lot less work (and a 
lot shorter code) to just take the settings from the session files. :)

Please consider the attached patch. It makes x2goruncommand behave more 
like GDM/LightDM for GNOME-ish sessions.

Testing GNOME Flashback on recent Ubuntu requires a couple of patches to 
Ubuntu packages, which I'm working on getting accepted. Details on 
Launchpad:

https://bugs.launchpad.net/ubuntu/+source/gnome-session/+bug/1251281/comments/46
https://launchpad.net/~rtandy/+archive/ubuntu/flashback/+packages

The gnome-session patch is applicable to Jessie too, but I think it's 
too late in the freeze to get it accepted now. :(

Many thanks for your work on X2Go!

-- 
Ryan Tandy - Programmer/Analyst                        [email-masked]
School District 63 (Saanich)                                250-652-7385
>From 9d84e88f7a7f4b0d47bfcf933796b2ca7cfd179f Mon Sep 17 00:00:00 2001
From: Ryan Tandy <[email-masked]>
Date: Tue, 17 Mar 2015 10:39:29 -0700
Subject: [PATCH] Launch gnome-session using settings from the session file.

Taking the settings from the session file should be more reliable and
future-proof than hard-coding them. This makes X2Go behave more like GDM
or LightDM in several cases.

Setting DESKTOP_SESSION and XDG_CURRENT_DESKTOP correctly allows Upstart
to manage the user session on Ubuntu 13.10 and later. That in turn means
GTK_MODULES no longer has to be set manually, since there is an Upstart
session job that sets it.

Passing the startup command as an argument to the session wrapper is
necessary on Ubuntu 15.04 and later.
---
 x2goserver/bin/x2goruncommand | 137 ++++++++++++------------------------------
 1 file changed, 39 insertions(+), 98 deletions(-)

diff --git a/x2goserver/bin/x2goruncommand b/x2goserver/bin/x2goruncommand
index ac7ff7f..c28ada1 100755
--- a/x2goserver/bin/x2goruncommand
+++ b/x2goserver/bin/x2goruncommand
@@ -83,108 +83,48 @@ elif [ "$sndsys" == "arts" ]; then
 	export ARTS_SERVER="localhost:$4"
 fi
 
-# detect Ubuntu version via /etc/lsb-release (not supported by Debian)
-if [ -e "/etc/lsb-release" ]; then
-	source /etc/lsb-release
-fi
-
 # let x2goruncommand choose what command to use for a given desktop shell name (GNOME, UNITY, KDE, XFCE4, LXDE, TRINITY, MATE, OPENBOX, ICEWM)
 
-# NOTES on GNOME startup behaviour in different distributions
-# ===========================================================
-
-# Debian and every other non-Ubuntu distro launchs GNOME3 (in accelerated mode) when calling gnome-session
-
-# Ubuntu launches Unity (in accelerated mode) when calling gnome-session.
-# To make the GNOME variants start up properly on Ubuntu, we have to make the following differentiations
-
-# Ubuntu 10.10 and earlier (maverick):
-#		 GNOME -> gnome-session
-#		 (would start GNOME2)
-# Ubuntu 11.04 (natty):
-#		 GNOME -> gnome-session --session=2d-gnome
-#		 UNITY -> gnome-session --session=2d-ubuntu
-#		 (GNOME3 based desktop shells)
-# Ubuntu 11.10 (oneiric) & 12.04 (precise):
-#		 GNOME -> gnome-session --session=gnome-fallback
-#		 UNITY -> gnome-session --session=ubuntu-2d
-#		 (GNOME3 based desktop shells)
-# Ubuntu 12.10 (quantal):
-#		 GNOME -> gnome-session --session=gnome-fallback
-#		 UNITY -> gnome-session --session=ubuntu
-#		 (GNOME3 based desktop shells)
-# Ubuntu 13.10 (raring) and later:
-#		 GNOME -> gnome-session --session=gnome-flashback
-#		 UNITY -> gnome-session --session=ubuntu
-#		 (GNOME3 based desktop shells)
-#		 Additionally, $GTK_MODULES must include "unity-gtk-module".
-#		 $GTK_MODULES does not need tha value for any other distro
-#                or any earlier release of Ubuntu.
-#
-#		 The logic for launching GNOME should be generic enough
-#                to work with every other distro.
-#
-#		 Also, it appears that some Linux GNOME2 distros need DESKTOP_SESSION="gnome"
-#                while others do not.
+# Use the gnome-session logic to launch a Unity 2D or Cinnamon 2D session.
+# Fall back to GNOME if the chosen session isn't available.
+if [ "$cmd" == "UNITY" ] || [ "$cmd" == "unity" ]; then
+	x2go_xsession=ubuntu-2d
+	cmd="gnome-session"
+elif [ "$cmd" == "CINNAMON" ] || [ "$cmd" == "cinnamon" ]; then
+	x2go_xsession=cinnamon2d
+	cmd="gnome-session"
+fi
 
 if [ "$cmd" == "GNOME" ] || [ "$cmd" == "gnome-session" ]; then
-	cmd="/usr/bin/gnome-session"
-	if [ "$DISTRIB_ID" == "Ubuntu" ] && [ "$(echo "$DISTRIB_RELEASE >= 13.10" | bc)" == "1" ]; then
-		export DESKTOP_SESSION="gnome-flashback"
-		if [ -z "$GTK_MODULES" ] ; then
-			export GTK_MODULES="unity-gtk-module"
-		else
-			export GTK_MODULES="$GTK_MODULES:unity-gtk-module"
+	# Try to pick an appropriate session file, and take settings from it.
+	for session in "$x2go_xsession" gnome-flashback-metacity gnome-fallback gnome-2d gnome; do
+		session_desktop=/usr/share/xsessions/"$session".desktop
+		if [ -f "$session_desktop" ]; then
+			# Run the command specified in the session file.
+			cmd="$(sed -n 's/^Exec=//p' "$session_desktop")"
+
+			# Use gnome-session's --disable-acceleration-check option if available.
+			# The Exec= line might already include it. That's OK.
+			if $cmd --help | grep -q -- --disable-acceleration-check; then
+				cmd="$cmd --disable-acceleration-check"
+			fi
+
+			# Set DESKTOP_SESSION and GDMSESSION to the base name of the session file.
+			export DESKTOP_SESSION="$session"
+			export GDMSESSION="$session"
+
+			# Try to set a reasonable XDG_CURRENT_DESKTOP.
+			# gnome-session will overwrite this, but on recent Ubuntu, some helpers are started by upstart instead of gnome-session.
+			# DesktopNames field is ;-separated. XDG_CURRENT_DESKTOP should be :-separated.
+			export XDG_CURRENT_DESKTOP="$(sed -n '/^DesktopNames=/ { s/^DesktopNames=//; s/;/:/g; s/:$//; p; }' "$session_desktop")"
+			# Before DesktopNames was standardized, a few Ubuntu releases used X-LightDM-DesktopName.
+			if [ -z "$XDG_CURRENT_DESKTOP" ]; then
+				export XDG_CURRENT_DESKTOP="$(sed -n 's/^X-LightDM-DesktopName=//p' "$session_desktop")"
+			fi
+
+			break
 		fi
-		args=" --session=$DESKTOP_SESSION"
-        elif [ -e /usr/share/gnome-session/sessions/gnome-flashback.session ]; then
-                export DESKTOP_SESSION="gnome-flashback"
-                args=" --session=$DESKTOP_SESSION"
-        elif [ -e /usr/share/gnome-session/sessions/gnome-fallback.session ]; then
-                export DESKTOP_SESSION="gnome-fallback"
-                args=" --session=$DESKTOP_SESSION"
-        elif [ -e /usr/share/gnome-session/sessions/2d-gnome.session ]; then
-                export DESKTOP_SESSION="2d-gnome"
-                args=" --session=$DESKTOP_SESSION"
-        elif [ "$DISTRIB_ID" == "Ubuntu" ] && [ "$(echo "$DISTRIB_RELEASE <= 10.10" | bc)" == "1" ]; then
-                export DESKTOP_SESSION="gnome"
-	elif cat /etc/debian_version | egrep "^(squeeze|6\.).*" >/dev/null; then
-                export DESKTOP_SESSION="gnome"
-        fi
-
-elif ([ "$cmd" == "UNITY" ] || [ "$cmd" == "unity" ]); then
-	cmd="/usr/bin/gnome-session"
-	if [ "$DISTRIB_ID" == "Ubuntu" ] && [ "$(echo "$DISTRIB_RELEASE >= 12.10" | bc)" == "1" ]; then
-		export DESKTOP_SESSION="ubuntu"
-		args=" --session=$DESKTOP_SESSION"
-	elif [ "$DISTRIB_ID" == "Ubuntu" ] && [ "$(echo "$DISTRIB_RELEASE == 11.10" | bc)" == "1" -o "$(echo "$DISTRIB_RELEASE == 12.04" | bc)" == "1" ]; then
-		export DESKTOP_SESSION="ubuntu-2d"
-		args=" --session=$DESKTOP_SESSION"
-	elif [ "$DISTRIB_ID" == "Ubuntu" ] && [ "$(echo "$DISTRIB_RELEASE == 11.04" | bc)" == "1" ]; then
-		export DESKTOP_SESSION="2d-ubuntu"
-		args=" --session=$DESKTOP_SESSION"
-	fi
-	# on earlier Ubuntu versions or with non-Ubuntu Distros the ,,UNITY'' command in X2Go will launch the GNOME2 desktop shell
-
-elif ([ "$cmd" == "CINNAMON" ] || [ "$cmd" == "cinnamon" ]); then
-	# Cinnamon 2.0 and newer
-	# The cmd is a script that calls the "cinnamon-session" binary.
-	if [ -e /usr/bin/cinnamon-session-cinnamon2d ]; then
-		cmd="/usr/bin/cinnamon-session-cinnamon2d"
-	# Cinnamon 1.6 & 1.8
-	# The cmd is a script that calls the "gnome-session" binary.
-	elif [ -e /usr/bin/gnome-session-cinnamon2d ]; then
-		cmd="/usr/bin/gnome-session-cinnamon2d"
-	# Cinnamon 1.4
-	# The cmd is a script that calls the "gnome-session" binary.
-	elif [ -e /usr/bin/gnome-session-cinnamon ]; then
-		cmd="/usr/bin/gnome-session-cinnamon"
-	# Fallback to the old behavior.
-	else
-		cmd="/usr/bin/gnome-session"
-		export DESKTOP_SESSION="cinnamon2d"
-		args=" --session=$DESKTOP_SESSION"
-	fi
+	done
 
 elif [ "$cmd" == "MATE" ]; then
 	cmd="/usr/bin/mate-session"
@@ -293,7 +233,8 @@ if [ "$EXEC" != "" ] && [ -x "$EXEC" ]; then
 	if x2gofeature X2GO_XSESSION &>/dev/null && [ "x$X2GO_SESS_TYPE" = "xD" ]; then
 		STARTUP="$cmd$args"
 		"$X2GO_LIB_PATH/x2gosyslog" "$0" "notice" "launching session with Xsession-x2go mechanism, using STARTUP=\"$STARTUP\""
-		XSESSION_EXEC="$cmd" STARTUP="/usr/bin/env LD_LIBRARY_PATH=${LD_LIBRARY_PATH} ${STARTUP}" /etc/x2go/Xsession
+		# LightDM passes the session command as an argument to the session wrapper. Some Ubuntu Xsession.d scripts depend on that.
+		XSESSION_EXEC="$cmd" STARTUP="/usr/bin/env LD_LIBRARY_PATH=${LD_LIBRARY_PATH} ${STARTUP}" /etc/x2go/Xsession "$cmd"
 	else
 		"$X2GO_LIB_PATH/x2gosyslog" "$0" "debug" "executing command \"$cmd$args\"..."
 
-- 
1.9.1

---

From: Mihai Moldovan <[email-masked]>
Date: Fri, 20 Mar 2015 05:48:49 +0100

On 17.03.2015 08:11 PM, Ryan Tandy wrote:
> Well, I started doing that, but it ended up being a lot less work (and
> a lot shorter code) to just take the settings from the session files. :)
>
> Please consider the attached patch. It makes x2goruncommand behave
> more like GDM/LightDM for GNOME-ish sessions.

This looks interesting, but does it work for non-Ubuntu/Debian systems,
too? Especially old(er) ones like SLE{S,D} 11, EPEL 5 etc.?

Mihai

---

From: Ryan Tandy <[email-masked]>
Date: Fri, 20 Mar 2015 15:12:33 -0700

Hi,

>too? Especially old(er) ones like SLE{S,D} 11, EPEL 5 etc.?

Tested on CentOS 5 and 6 successfully. CentOS 7 seems to not include the 
GNOME Flashback components, so I couldn't test there.

I wasn't able to get X2Go working at all on OpenSuSE 11. :/ Looks like 
packages.x2go.org doesn't carry 11 any more? Works on OpenSuSE 12, 
although the GNOME fallback desktop seems to be affected by a few bugs. 
I didn't test OpenSuSE 13, but glancing at the repo it looks like they 
retired the fallback/gnome-panel packages like RHEL7 did.

The patch I sent before exports XDG_CURRENT_DESKTOP needlessly in 
environments that have no value for it (e.g. older GNOME 2). Should be 
harmless, but even so I'm attaching a corrected patch and interdiff 
since the previous one.

The approach probably extends to non-GNOME desktops too, but I don't 
know when I would have time to go through and test them all...

From e184e85cbf28928864fd3d935bced28295e7624f Mon Sep 17 00:00:00 2001

Passing the startup command as an argument to the session wrapper is
necessary on Ubuntu 15.04 and later.
---
 x2goserver/bin/x2goruncommand | 140 +++++++++++++-----------------------------
 1 file changed, 42 insertions(+), 98 deletions(-)

diff --git a/x2goserver/bin/x2goruncommand b/x2goserver/bin/x2goruncommand
index ac7ff7f..f35d159 100755
--- a/x2goserver/bin/x2goruncommand
+++ b/x2goserver/bin/x2goruncommand
@@ -83,108 +83,51 @@ elif [ "$sndsys" == "arts" ]; then
 	export ARTS_SERVER="localhost:$4"
 fi

 
+			desktopname="$(sed -n '/^DesktopNames=/ { s/^DesktopNames=//; s/;/:/g; s/:$//; p; }' "$session_desktop")"
+			if [ -z "$desktopname" ]; then
+				desktopname="$(sed -n 's/^X-LightDM-DesktopName=//p' "$session_desktop")"
+			# Only export the variable if set by some session file.
+			if [ -n "$desktopname" ]; then
+				export XDG_CURRENT_DESKTOP="$desktopname"
 
@@ -293,7 +236,8 @@ if [ "$EXEC" != "" ] && [ -x "$EXEC" ]; then
 
-- 
1.9.1

diff -u b/x2goserver/bin/x2goruncommand b/x2goserver/bin/x2goruncommand
--- b/x2goserver/bin/x2goruncommand
+++ b/x2goserver/bin/x2goruncommand
@@ -116,12 +116,15 @@
 			# Try to set a reasonable XDG_CURRENT_DESKTOP.
 			# gnome-session will overwrite this, but on recent Ubuntu, some helpers are started by upstart instead of gnome-session.
 			# DesktopNames field is ;-separated. XDG_CURRENT_DESKTOP should be :-separated.
-			export XDG_CURRENT_DESKTOP="$(sed -n '/^DesktopNames=/ { s/^DesktopNames=//; s/;/:/g; s/:$//; p; }' "$session_desktop")"
+			desktopname="$(sed -n '/^DesktopNames=/ { s/^DesktopNames=//; s/;/:/g; s/:$//; p; }' "$session_desktop")"
 			# Before DesktopNames was standardized, a few Ubuntu releases used X-LightDM-DesktopName.
-			if [ -z "$XDG_CURRENT_DESKTOP" ]; then
-				export XDG_CURRENT_DESKTOP="$(sed -n 's/^X-LightDM-DesktopName=//p' "$session_desktop")"
+			if [ -z "$desktopname" ]; then
+				desktopname="$(sed -n 's/^X-LightDM-DesktopName=//p' "$session_desktop")"
+			fi
+			# Only export the variable if set by some session file.
+			if [ -n "$desktopname" ]; then
+				export XDG_CURRENT_DESKTOP="$desktopname"
 			fi
-
 			break
 		fi
 	done