Package: x2goserver
Version: 4.0.1.19
failure to complete connection when profile files on server contain bashisms
On a group of servers using Debian Stretch, X2Go server (version
4.0.1.19-0x2go2+git20160621.1064+stretch.main.1) was not accepting
incoming connections. Namely, SSH logging in succeeded, X2go client
would open a black window, but the window would close by itself in 1-2
seconds.
I found that, during the login process, the server was sourcing Bash
profile files assuming they were POSIX-compliant. At the first encounter
of a bashism, such as an array, the script would crash, and the whole
session would be killed.
I tracked the issue down by inserting in /etc/x2go/Xsession (a /bin/sh
file) a logging line:
# Load profile
for file in "/etc/profile" "$HOME/.profile" "/etc/xprofile"
"$HOME/.xprofile"; do
echo "$file" | /usr/bin/logger -t x2goloading
..blabla..
done
In the log I found:
Jul 22 21:32:43 mycomputer /usr/bin/x2goruncommand: launching session
with Xsession-x2go mechanism, using STARTUP="xfce4-session"
Jul 22 21:32:43 mycomputer x2goloading: /etc/profile
Jul 22 21:32:43 mycomputer x2goloading: /home/user/.profile
Jul 22 21:32:43 mycomputer /usr/bin/x2goruncommand: command
/usr/bin/xfce4-session has finished
What happened was that I had my /home/user/.profile source another
script that I wrote
$ tail /home/user/.profile
...blabla...
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
. /etc/mybashsettings.sh
$ cat /etc/mybashsettings.sh
#!/bin/bash
somefunc()
{
local INPUTLINES
INPUTLINES=()
}
return 0
$ . /etc/mybashsettings.sh
$ sh /etc/mybashsettings.sh
/etc/mybashsettings.sh: 5: /etc/mybashsettings.sh: Syntax error: "("
unexpected (expecting "}")
This is a minimally crashing example.
Now, I believe that having bash scripts in one's profile should not be
unexpected. In fact, on the aforementioned distro, it seems it is part
of bash. I ave:
$ head /home/user/.profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.