Subject: Multiple issues with x2gousbmount

From: Stefan Baur <[email-masked]>
Date: Sat, 14 Jan 2017 13:54:16 +0100

package: x2gousbmount

Hi $LIST, hi Alex, hi Mike#1,

due to a recent bug report on X2Go-User, I needed to take a closer look
at the x2gousbmount package, and the script
/usr/lib/x2go/tce/x2gousbmount in it.

I'll be referencing
http://code.x2go.org/gitweb?p=x2gothinclient.git;a=blob;f=usbmount/x2gousbmount;h=4da1fbd90b14dda1beb230ea4b08441a77d9e4eb;hb=75211b6e724bd896d85d915c754703cabcf37187

for line numbers below, even though that version is more advanced as the
one in the stable x2gousbmount package.

I'm hoping that Alex or someone else that has a clue wrt/ Perl and this
script can shed some light on these issues.

Mike#1, you're in CC due to issue #3, which seems to have been
introduced in your commit.

Feel free to suggest I should turn every issue into a separate bug
report - I'm not filing them separately at the moment because the issues
seem all more or less interconnected, so I figured I should start with
one bug report for "the big picture".

Issue #1:
Lines 88 and 138 contain a call ... expand_filename("~x2gothinclient ...
Now, I understand that this is an attempt to determine the path to the
home directory of the user named "x2gothinclient".
Which, in the classic X2Go-TCE, is "/var/lib/x2gothinclient". So far, so
good.

But: Lines 107 and 148 contain what looks to me like a subtle typo:
 ... expand_filename("~/x2gothinclient ...
Which means, instead of selecting the home directory of the user
x2gothinclient, it would go to the home directory of the user under
which the script is being executed, and a subdirectory "x2gothinclient"
there, so most likely
/root/x2gothinclient (which doesn't exist)
So the script will probably fail whenever it encounters encrypted volumes.
(I can't test this myself, I don't have a setup with encrypted USB media.)

Issue #2:
The user name "x2gothinclient" is hardcoded in several places inside the
script.

This calls at least for a "my $user='x2gothinclient';" at the beginning
of the script, and the replacement of every occurrence of
"x2gothinclient" with "$user".

The reason being that TCE-Live uses a different user name, namely "user"
(and a different home directory, /home/user), so we need to be able to
swap out the name in one central location.

There are two ways of determining that we're running in TCE-Live, I am
not sure which one would be the preferable one:
1) Checking /proc/cmdline for the appearance of (in regex syntax)
"\W*live\W*" or "\W*boot=live\W*" (in case your mail software turns
asterisks into bold type, there's an asterisk after each capital W).
2) Checking if the directory /lib/live or /lib/live/config exists.
If any of these match, then $user should be set to 'user' instead of
'x2gothinclient'.

Issue #3:
Comparing the master branch in git with the version in stable, line 37
is different.

There now is an additional check for the existence of a directory
"/usr/share/doc/x2gothinclient-minidesktop".

Which script/package creates this directory and why is it equivalent to
detecting a running x2gothinclientd?

Looks like
http://code.x2go.org/gitweb?p=x2gothinclient.git;a=commit;h=a458a1ed666eb12b5d856812396ecd31fba01585
introduced that change, see
http://code.x2go.org/gitweb?p=x2gothinclient.git;a=commit;h=a458a1ed666eb12b5d856812396ecd31fba01585
but there's no meaningful commit message. Mike#1?

Issue #4:
I am unhappy with the subroutine check_x2gothinclientd.  Indeed,
grepping for substrings so you don't trigger on the parameters of your
own grep command in the output of ps is a neat hack, but a hack remains
a hack.
The clean way of handling this, IMO, would be to change the subroutine
as follows:

sub check_x2gothinclientmode {
	# check if X2GoClient is running in thinclient mode
	# old code would check if x2gothinclientd was running,
	# which fails on X2Go-TCE-live
	my $x=`ps u -C x2goclient`;
	if ( $x=~m/\W*--thinclient\W*/ )
	{
		return 1;
	}
	return 0;
}

This will no longer detect if x2gothinclientd is running, but if
x2goclient has been called with parameter --thinclient.  Which should be
the case in both TCE-Classic and TCE-Live.

Due to the name change of the subroutine, line 37 needs to be changed to
use check_x2gothinclientmode instead of check_x2gothinclientd.
Maybe the changed check means the || - part in line 37 is no longer
needed as well?

Issue #5:
Lines 88 and 138 silently assume that there is a subdirectory "export".
I can't see it being created anywhere, though.
Same goes for lines 107 and 148 and the subdirectory "logins".

Issue #6:
Why do we need two separate subdirectories "export" and "logins", anyways?

Issue #7:
Somewhere around line 48, I'm missing a comment that explains what this
part of the code is for.
I would suggest adding:
# mntdir is not the directory where the mountpoint will be rooted,
# but where tracking of mount states takes place

Issue #8:
Why do we have to track these mountpoints manually, anyways?  Is the
information in /proc/mounts insufficient?

-Stefan

-- 
BAUR-ITCS UG (haftungsbeschränkt)
Geschäftsführer: Stefan Baur
Eichenäckerweg 10, 89081 Ulm | Registergericht Ulm, HRB 724364
Fon/Fax 0731 40 34 66-36/-35 | USt-IdNr.: DE268653243

---

From: Mike Gabriel <[email-masked]>
Date: Mon, 16 Jan 2017 15:35:21 +0000

Hi Stefan,

> but there's no meaningful commit message. Mike#1?

The mini desktop is a minimal MATE desktop env running on the thin  
client. With that minimal desktop, x2gothinclientd is not used and the  
role is taken over by MATE's session manager.

Simple as that.
Mike
-- 

DAS-NETZWERKTEAM
mike gabriel, herweg 7, 24357 fleckeby
mobile: +49 (1520) 1976 148
landline: +49 (4354) 8390 139

GnuPG Fingerprint: 9BFB AEE8 6C0A A5FF BF22  0782 9AF4 6B30 2577 1B31
mail: [email-masked], http://das-netzwerkteam.de

---

From: Stefan Baur <[email-masked]>
Date: Mon, 16 Jan 2017 16:39:48 +0100

> role is taken over by MATE's session manager.

Does that mean that at the very moment when an USB plug/unplug event is
detected, there is no x2goclient running that has --thinclient set?

Because if you *do* call x2goclient [...] --thinclient [...] for that
minidesktop session, then the new detection in the subroutine
check_x2gothinclientmode will trigger on that as well, so the "|| ..."
part would no longer be needed.

Kind Regards,
Stefan Baur

---

From: Stefan Baur <[email-masked]>
Date: Thu, 19 Jan 2017 10:10:17 +0100

Am 19.01.2017 um 10:02 schrieb Mike Gabriel:
> Not sure what you mean by that.

*sigh* ...

Old code: Checks for presence of x2gothinclientd
          (sub check_x2gothinclientd)

New code: Checks for presence of x2goclient with --thinclient option
          (sub check_x2gothinclientmode)

Old code:
if ( check_x2gothinclientd() ||  ( -d
"/usr/share/doc/x2gothinclient-minidesktop" ) )

-> "Either x2gothinclientd is running or directory
/usr/share/doc/x2gothinclient-minidesktop exists"

If, on the Minidesktop, x2goclient would be called with --thinclient,
that line could be shortened to:
if ( check_x2gothinclientmode() )

Pleas pay attention to this: Your statement

> Basically, you don't want x2gousbmount
> interfere with udisks(2) which is what the MATE session manager uses to
> manage pluggable storage devices.

contradicts what the code currently in the X2Go repo (NOT our latest,
suggested changes) is doing - in other words, the present code DOES run
x2goumount when the minidesktop is detected, so it WILL interfere with
udisks/MATE session manager - so either you are wrong, or you have an
issue there.

-Stefan

---

From: Mike Gabriel <[email-masked]>
Date: Thu, 19 Jan 2017 09:02:05 +0000

> detected, there is no x2goclient running that has --thinclient set?

Exactly. On the Mini-Desktop based TCE variant, X2Go Client runs in  
"normal" mode. It is launched via a desktop icon (and in the temp  
user's XDG autostart folder).

> part would no longer be needed.

Not sure what you mean by that. Basically, you don't want x2gousbmount  
interfere with udisks(2) which is what the MATE session manager uses  
to manage pluggable storage devices.

Mike

-- 

DAS-NETZWERKTEAM