Modifying ld.so paths before loading perl modules
I'm trying to set a specific LD_LIBRARY_PATH to load a modified version of libpcap instead of the system-wide one.
This works of course if I run the whole script with LD_LIBRARY_PATH=/blah ./script_name. I want to make this transparent for the user, so I tried setting $ENV{'LD_LIBRARY_PATH'}. This doesn't however change the behaviour. I tried to put it in the BEGIN block to make it work before other use-s, but no luck there either.
I suspect it's because of ld loading all the configs / configuring itself at the beginning of the process before any part of the script is run. Is there some way to make it work?
I'd like to avoid silly things like:
if (check_parent()) { $ENV...=.... ; `$0` ; exit }
(or external wrappers as have been suggested - the less cruft and random wrappers, the better)
Answers
You could replace the top of your script with
#!/bin/sh LD_LIBRARY_PATH="/blah:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH exec perl -x -S "$0" "$@" || exit 1 #!perl # rest of your script