C dynamic library to add to LD_PRELOAD to clean environment variables that are duplicated.
Both versions contains a list of environment variables that it is allowed to change. Add or remove according to your needs!
The static version cleans all environment variables every time
The dynamic version cleans only the environment variable that is being changed
- To build the static version use:
gcc -shared -fPIC -o libenv_dedup.so env_dedup.c -ldl - To build the dynamic version use:
gcc -shared -fPIC -o libenv_dedup_dynamic.so env_dedup_dynamic.c -ldl - To build the dynamic optimised version, use:
gcc -shared -fPIC -O3 -D_GNU_SOURCE -o libenv_dedup_dynamic_optimised_o3.so env_dedup_dynamic_optimised.c -ldl
Add the dynamic library to LD_PRELOAD like this and test it:
LD_PRELOAD=libenv_dedup_dynamic.so $app
Consider adding exporting it on .bashrc or for KDE to ~/.config/plasma-workspace/env/00-env-dedup.sh
You can add:
environment.variables.LD_PRELOAD = "/etc/nixos/libenv_dedup_dynamic.so";
to make it system wide.
(adjust the location as needed)
Please test carefully first before applying system wide
This code was developed with the help of AI/LLM.