locked_user sundialsvc4 has asked for the wisdom of the Perl Monks concerning the following question:

In my Apache .htaccess file, I tried the following directive:   “SetEnv LD_LIBRARY_PATH foo”.

But that's not what my program eventually saw!

It saw: REDIRECT_LIBRARY_PATH!

Why?

If I wanted to (oh, gosh... for some reason or another... sigh) specify a setting for LD_LIBRARY_PATH, how would I do it?

Replies are listed 'Best First'.
Re: REDIRECT_LD_LIBRARY_PATH variable?
by Tanktalus (Canon) on Mar 03, 2009 at 23:32 UTC

    Last time I did something like that, I ended up with code like this:

    BEGIN { unless ($ENV{LD_LIBRARY_PATH} =~ m[:/some/path:]) { $ENV{LD_LIBRARY_PATH} .= ':/some/path:'; exec $^X, $0, @ARGV; } }
    I'm not sure it's the best way, but it worked.

Re: REDIRECT_LD_LIBRARY_PATH variable?
by Illuminatus (Curate) on Mar 03, 2009 at 23:31 UTC
    I am not an apache guru, so the rules for precedence in redirection/aliasing/.htaccess processing are black magic to me. Are you sure that you were not already getting the 'REDIRECT_LD_LIBRARY_PATH' variable passed in before you added the SetEnv? Is the server configured to allow you to set environment variables in the .htaccess file?

    Is the path actually fixed? If so, you could (ugh) hard-code it into your script...

      Yeah, the directive is having an effect ... the value of the variable is whatever I set it to be, and otherwise the variable doesn't exist ... but the name is changed.

      Yes, you are absolutely correct that environment-variables can be set with $ENV{}, and that many desirable magickal effects happen when you do so within a BEGIN { } block, because of the (very early...) point in time when Perl considers such blocks. This is an apparently-valid, and therefore very-important, observation. Let us therefore recognize it, and let it stand.

      But my particular question in this post is... where and why does “REDIRECT_” come from? Why is the final name of the environment-variable not the name that I have attempted to set?

        I/m afraid you are in the wrong forum. Have you tried apachemonks.org? :) I believe you are the victim of some unintended consequence of your server's configuration of the mod_alias module. Are you allowed to request changes to the actual virtual server configuration you are using within Apache? Maybe setting at that level will cause it to pass thru unaltered?
Re: REDIRECT_LD_LIBRARY_PATH variable?
by bichonfrise74 (Vicar) on Mar 03, 2009 at 23:29 UTC
    Can you set it like this?
    #!/usr/bin/perl $ENV{'LD_LIBRARY_PATH'} = '/<your_path>'; print $ENV{'LD_LIBRARY_PATH'};
      No, because the LD_LIBRARY_PATH is all about how C is going to link dynamic libraries, and C will use the environment variable that was there when your program was created. So setting it after you're in your program won't cause it to do what you need it to do. See Re: REDIRECT_LD_LIBRARY_PATH variable? for the kind of workarounds that are needed for a standalone program.