Environment Variables Behavior On Haiku

The simple solution is to have launch_daemon set some default environment variables. They could be hardcoded to fixed values for a start, and it would already fix most of the problems. The terminal/bash profile can still override them as needed.

This is how it works in other UNIX OS as well. For example on Linux, systemd (as the init process) is responsible for initiaizing the environment, and then the bash profile can add things to it (or even remove things) for programs that are run inside a shell session.

In fact, a quick look at the launch daemon sourcecode will show you that this is already done. The method used is LaunchDaemon::_SetupEnvironment() and there does not seem to be any mistery involved here. It just calls the UNIX setenv function. Additionally in _StartSession it also sets the HOME variable.

So it’s just a matter of adding some more setenv calls in these two places, and removing the corresponding entries from the bash profile. A very simple fix.

What I don’t understand is how a lot of effort can be put into patching many applications to workaround the problem, when the proper fix would take a lot less effort. The same thing happened for the lack of a features.h header file, where people apparently were happy adding -D_BSD_SOURCE to compile flags of thousands of apps, instead of just adding the define in features.h where it should have been from the start. It results in lots of frustration for haikuports maintainers (having to keep these patches working), for 3rd party applications developers (wondering why Haiku behaves differently from all other systems for no reason), and for us Haiku developers (because no one bothers to report the problem up to us, or push us to fix it).

7 Likes