Monday, 27 August 2012

Screwing up Solaris linker with crle

DISCLAMER: DO NOT BLINDLY APPLY ANY CONFIGS IN THIS POST, BEFORE FULLY UNDERSTANDING THE IMPACT. YOU HAVE BEEN WARNED!!

-- At the risk of ruining the punchline use LD_NOCONFIG if you mess up your runtime linker path using crle on solaris --

I was setting up a software package provided to me which wanted to install in /opt/environmentname/packagename/[etc, bin, lib, log] and soforth. It was compiled in a way which required the linker to know to search /opt/environmentname/packagename/lib .

So the basic steps were

  1. install software
  2. setup linker
  3. test
Heres what i did:
  • Install software "pkgadd -d packagename"
  • export LD_LIBRARY_PATH=/opt/environmentname/packagename/lib
  • /opt/environmentname/packagename/bin/packagename
  • SUCCESS
But then i thought isnt LD_LIBRARY_PATH evil.. And isnt this software going to be on the majority of my machines. Lets go ahead and update the system-wide library search path.
  • Did a quick man crle and found the -l option , you see where this is going right.
  • export LD_LIBRARY_PATH=""
  • sudo crle -l /opt/environmentname/packagename/lib
  • /opt/environmentname/packagename/bin/packagename # Once again SUCCESS!
  • ls however is now giving me "ld.so.1: ls: fatal: libc.so.1: open failed: No such file or directory" , EPIC FAIL!
It quickly becomes apparent that crle -l overwrites the runtime linker search path, rather than appending to it.. Lets revert to something sane.

~> sudo crle -l /lib -l /usr/lib -l /usr/sfw/libld.so.1:
sudo: fatal: libc.so.1: open failed: No such file or directory

Uh oh... sudo needs a correct environment to do its thing.. Thats OK i'll just update LD_LIBRARY_PATH so sudo can do its thing.

~> export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/sfw/lib 
~> sudo crle -l /lib -l /usr/lib -l /usr/sfw/lib 
ld.so.1: sudo: fatal: libc.so.1: open failed: No such file or directory

Ahh yes.. So isnt sudo secure in that it filters most environment variables from the sudo environment.. So how do i fix things now? LD_NOCONFIG is your friend.

~> LD_NOCONFIG=1  
~> sudo crle -l /lib -l /usr/lib -l /usr/sfw/lib
~> ls 
.    ..

Wohoo it works again! Now i just need to go back and set the search path i originally wanted to but this time append rather than overwrite.
~> sudo crle -u /opt/environmentname/packagename/lib 
~> /opt/environmentname/packagename/bin/packagename # SUCCESS!
From the man page:
man ld.so.1 
...      
LD_NOCONFIG, LD_NOCONFIG_32, and LD_NOCONFIG_64 

         By default the runtime linker attempts to open and  pro-         cess  a  configuration  file. When LD_NOCONFIG is set to         any non-null value, the  runtime  linker  disables  this         configuration file processing.


No comments: