mercredi 8 avril 2015

LD_LIBRARY_PATH annoyances

Hey, we don't need no ld_library_path ?
though I did  code an élégant script :
#reorder front path items matching ie(PATH,/opt:/usr:/sbin:/bin) R_PATH
reorderpath()
{
A_PATH=$1
P_BEFORES=$2
A_PATH=`echo "$A_PATH"|sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'`
if [ "$A_PATH" = "" ];then return;fi
if [ "$P_BEFORES" = "" ];then return;fi
for P_BEFORE in `echo $P_BEFORES|sed -e 's/:/ /g'`;do
R_PATH=""
for I_PATH in `echo $A_PATH|sed -e 's/:/ /g'`;do
J_PATH=`echo $I_PATH|sed -e "s:^$P_BEFORE::"`
if [ "$I_PATH" = "$J_PATH" ];then
R_PATH="$R_PATH:$I_PATH"
else
R_PATH="$I_PATH:$R_PATH"
fi
done
R_PATH=`echo "$R_PATH"|sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'`
A_PATH=$R_PATH
done
}

but on AIX, impossible to conciliate chef-solo and rpm
reorderpath $LD_LIBRARY_PATH /usr:/lib:/opt/freeware
puts rpm in front, rpm works, but not chef-solo who uses libs (zlib) in /lib instead of /opt/chef/embedded ;
same way round, rpm needs  libs zlib from /lib ;
and as rpm is started by chef, they should share the same LD_LIBRARY_PATH.
no solution, well indeed :
solution lies in compiled files , they have hardcoded the location of the lib
  1. Never ever set LD_LIBRARY_PATH globally.
  2. If you must ship binaries that use shared libraries and want to allow your clients to install the program outside a ‘standard’ location, do one of the following:
    • Ship your binaries as .o files, and as part of the install process relink them with the correct installation library path. (like oracle..)
    • Ship executables with a very long “dummy” run-time library path, and as part of the install process use a binary editor to substitute the correct install library path in the executable. (whaou, hacky!+1!)
  3. If you are forced to set LD_LIBRARY_PATH, do so only as part of a wrapper.

so (redhat/solaris/aix):
unset LD_LIBRARY_PATH LD_RUN_PATH LIBPATH
and everything works..
PS: my company re-opened blogger in the firewall, so I am back, 
I'll put english articles here, french here blog.kastenbaum.net

Aucun commentaire: