Is there a way to inject/enable LD_PRELOAD just for new sessions (ie:
The easiest solution is probably to replace
bash with a shell script that performs the
LD_PRELOAD logic, then calls the actual (renamed)
That is, move
/bin/bash.original, then create a script
/bin/bash with the following contents:
#!/bin/sh LD_PRELOAD=/path/to/my/library.so export LD_PRELOAD exec /bin/bash.original "$@"
You could include logic here (e.g., "is stdout a tty") if you want to only perform the
LD_PRELOAD when connected to an interactive session. Trying to perform any sort of terminal manipulation when bash isn't connected to a tty will probably yield weird results.