Why are some environment variables not being set within my ThinLinc session?

ThinLinc has a specific mechanism for setting environment variables within a ThinLinc session - the /vsmagent/default_environment parameter. This can be used to set environment variables in users’ ThinLinc sessions, in addition to any system-level (e.g. /etc/profile.d) or user-level (e.g. ~/.bash_profile) configuration which may exist.

However, some environment variables will not make it through to the ThinLinc session. This is because ThinLinc relies on systemd for session creation, and systemd will refuse to import environment variables which don’t match its rules. This includes variables with values which contain characters such as spaces and parentheses; characters which are necessary for implementing Bash functions.

Some software packages still[1] insist on using environment variables to hold Bash functions. Because such functions inevitably contain characters disallowed by systemd, they will not be propogated through to the ThinLinc session.

One common example of this is the software package Lmod, which defines a series of system-wide environment variables as Bash functions in /etc/profile.d. Although these functions are essential for using Lmod, they will be stripped out and not available to users inside their ThinLinc sessions. Instead, the session log file will contain entries like the following:

Ignoring invalid environment variable: 'BASH_FUNC_module%%'
Ignoring invalid environment variable: 'BASH_FUNC_ml%%'

Unfortunately there is nothing that can be done in ThinLinc to resolve this, as systemd will start after ThinLinc has set environment variables via the default_environment mechanism (and also after those defined in profile.d). One workaround is to set the required environment variables in ~/.bashrc instead, so that they are exported each time the user opens a terminal. Even better, they could be implemented as Bash functions rather than variables.

If you have any tips or experience using Lmod within a ThinLinc session, please feel free to comment below.


  1. Using environment variables to hold Bash functions was a major factor in the 2014 Shellshock vulnerability ↩︎

3 Likes