开发者

Modifying ld.so paths before loading perl modules

开发者 https://www.devze.com 2023-01-28 13:12 出处:网络
I\'m trying to set a specific LD_LIBRARY_PATH to load a modified 开发者_如何学Pythonversion of libpcap instead of the system-wide one.

I'm trying to set a specific LD_LIBRARY_PATH to load a modified 开发者_如何学Pythonversion 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)


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


The reason setting LD_LIBRARY_PATH inside the Perl script has no effect is that by the time Perl is running, the dynamic loader has already read LD_LIBRARY_PATH and does not reread it. Thus, even a BEGIN block is too late - the dynamic loader has already read what it needs.

0

精彩评论

暂无评论...
验证码 换一张
取 消