The initial environment for application launches

Hi, in some experiments, I’m seeing that if I launch an application from Gnome Shell (i.e., from a .desktop definition) the application has environment variables that I set in .bashrc or .bash_profile, but not in .profile. I am wondering why Gnome Shell sources these files, since in principle they are specific to bash. Is this based on the user’s choice of login shell? Would it source other files if a different shell was selected?

On a related note, does the EXEC line in a .desktop definition get called directly, or passed to a shell, like “bash -c”?

Hello! If there is a DBusActivatable=true line in the .desktop file and there is DBus, then the Exec line is not executed. Instead, DBus looks for a .service file to launch the application. In this case, the application gets the invironment of the DBus process, which, in case of systemd, is detemined by systemd. It can be configured for all processes per the manual page of systemd-system.conf, usually by ManagerEnvironment option since systemd version 256.1.

To check the DBus user session environment, which is passed to user-launched applications, I would look up the DBus service PID in the output of systemctl --user status dbus and then look up the invornment with strings /proc/$PID/environ, where $PID needs to be replaced by the looked-up PID.

For posterity:

I see that on my Guix system, none of the .desktop files use the DBus line. Also, I see that the Dbus daemon has a very simple environment, consisting of simply “PATH=/run/current-system/profile/bin”.

I see also that the Exec lines all point to files in the Guix store which are in fact bash shell scripts, which set up the environment, and then launch the real binary with a bash exec call. So I think this explains how the applications are getting variables from my .bashrc and .bash_profile.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.