You are not logged in.

#1 2022-05-14 18:16:25

Zoddo
Member
Registered: 2021-06-11
Posts: 2

[SOLVED] LightDM: Trouble setting environment variable

Hi,

I have LightDM used to launch Budgie.

I'm trying to define a few environment variables (to redirect some files out of my home folder).
I'm exporting these variables in ~/.profile. This works well when I log in from a TTY, but not when I log in from LightDM.

LightDM is configured to use the shipped session wrapper which load $HOME/.profile:

session-wrapper=/etc/lightdm/Xsession

But for some reason, the environment variables I define in .profile aren't defined for programs started from the DE.
Checking /proc/PID/environ of the gnome-session-binary process (the one seemingly started by lightdm) doesn't show my envs either.

I believe I've missed something obvious, but I can't find what.

Any help is appreciated.

Last edited by Zoddo (2022-05-14 20:50:05)

Offline

#2 2022-05-14 20:01:49

seth
Member
Registered: 2012-09-03
Posts: 52,068

Re: [SOLVED] LightDM: Trouble setting environment variable

Are the variable picked up by eg. an openbox session? (Cause the other explanation would be that Budgie nukes them)
/bin/sh symlinks bash?

Offline

#3 2022-05-14 20:35:23

tucuxi
Member
From: Switzerland
Registered: 2020-03-08
Posts: 291

Re: [SOLVED] LightDM: Trouble setting environment variable

Do you find the output from the session wrapper in your log?

Running X session wrapper
Loading profile from /home/xyz/.profile
...
X session wrapper complete, running session budgie

Offline

#4 2022-05-14 20:49:43

Zoddo
Member
Registered: 2021-06-11
Posts: 2

Re: [SOLVED] LightDM: Trouble setting environment variable

Ok, so I just found the issue.

Since I wasn't able to find lines echo'd by Xsession in logs, someone suggested that I add this at the end of my .profile to confirm that it's correctly sourced by Xsession:

printenv >> /home/zoddo/env.log

This confirmed that .profile was indeed sourced when the session was started by LightDM but the environment logged in the file didn't contain my new variables.
Manually sourcing .profile in an interactive shell correctly exported them.

So, to better understand the issue, I did export the variables in .profile with this:

cat $HOME/.config/environment.d/* | while read -r line; do
    eval export "$line"
done

I do this to have the environment declared to both user services started by systemd and in my session without having to duplicate them in two places.

The issue here is that bash/sh (the shell used to execute the Xsession wrapper) spawns a subshell when you pipe to while, exporting the variables only in the subshell.
However, zsh (my everyday shell on which I did my tests) behaves differently and does not seem to use a subshell in this case, exporting variables correctly.

I fixed this by using process substitution instead of a pipe:

while read -r line; do
    eval export "$line"
done < <(cat $HOME/.config/environment.d/*)

That's literally the first time I got an actual issue due to a difference in behavior between zsh and bash hmm

Sorry for the noise sad

Offline

Board footer

Powered by FluxBB