Project

General

Profile

[UE] Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working

Added by JacobBai almost 2 years ago

Hi there,

I am running lighttpd 1.4.58 on my Linux built by Buildroot. I have set up the LD_LIBRARY_PATH (/mnt/lib) variable globally, and needed it when API (cgi) get called.

Here is what I added into lighttpd.conf file:

setenv.add-environment = ( "PATH" => env.PATH,
                           "LD_LIBRARY_PATH" => env.LD_LIBRARY_PATH )

I can see the PATH variable showed up after this, but LD_LIBRARY_PATH (/mnt/lib) not showing.

Then, I tried this setting:

setenv.add-environment = ( "PATH" => env.PATH,
                           "HOME" => env.LD_LIBRARY_PATH )

I can see the HOME variable showing up with the actual value of LD_LIBRARY_PATH (/mnt/lib).

After that, I tried another one:

setenv.add-environment = ( "PATH" => env.PATH,
                           "LD_LIBRARY_PATH" => env.HOME )

Then only PATH here, no LD_LIBRARY_PATH.

But if I go:

setenv.add-environment = ( "PATH" => env.PATH,
                           "LD_LIBRARY_PATH_TEST" => env.LD_LIBRARY_PATH)

I will be able to see LD_LIBRARY_PATH_TEST coming with the actual value of LD_LIBRARY_PATH (/mnt/lib).

It turns out that LD_LIBRARY_PATH variable is hidden on purpose, why is that? How can I get it working?

Many thanks in advance!
Jacob


Replies (15)

RE: Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by gstrauss almost 2 years ago

At server startup, lighttpd mod_cgi saves LD_LIBRARY_PATH, LD_PRELOAD, and (on Cygwin) SYSTEMROOT, so if any of those variables are set in the environment in which the lighttpd server is started, then those variables which are set will be included in the CGI environment.

RE: Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by gstrauss almost 2 years ago

Using what you used also works for me with lighttpd 1.4.64, the latest lighttpd release:

setenv.add-environment = ( "PATH" => env.PATH,
                           "LD_LIBRARY_PATH" => env.LD_LIBRARY_PATH )

Note that env.LD_LIBRARY_PATH is read from the environment in which lighttpd is started and is replaced in the config at startup.

Have you tested setting an explicit path?:

setenv.add-environment = ( "PATH" => env.PATH,
                           "LD_LIBRARY_PATH" => "/my/library/path" )

RE: Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by gstrauss almost 2 years ago

I tested with lighttpd 1.4.58 and the original works for me, too:

setenv.add-environment = ( "PATH" => env.PATH,
                           "LD_LIBRARY_PATH" => env.LD_LIBRARY_PATH )

Perhaps LD_LIBRARY_PATH is being set in the environment outside your Buildroot, so lighttpd does not see the environment variable when lighttpd starts up inside the Buildroot.

You should test your lighttpd config in a test environment outside your Buildroot to establish that your issue is your Buildroot config.

RE: Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by JacobBai almost 2 years ago

Hi gstrauss,

According to the src file (mod_cgi.c), it shows that lighttpd saves LD_LIBRARY_PATH, LD_PRELOAD, and (on Cygwin) SYSTEMROOT, like you said in the first reply.

I tried with explicit path, and still can't see LD_LIBRARY_PATH when do printenv.

You mentioned that the LD_LIBRARY_PATH been set outside Buildroot, and lighttpd doesn't see it. But my last test in the original post shows a different thing. Which is that, if I do this:
setenv.add-environment = ( "PATH" => env.PATH,
"LD_LIBRARY_PATH_TEST" => env.LD_LIBRARY_PATH)

I can see LD_LIBRARY_PATH_TEST when printenv with the correct path I set to LD_LIBRARY_PATH.
It means the LD_LIBRARY_PATH already set inthe buildroot and lighttpd can see it, but somehow it ignores it.

RE: Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by JacobBai almost 2 years ago

Here is another test.
The setting:
setenv.add-environment = ( "PATH" => env.PATH,
"LD_LIBRARY_PATH" => env.LD_LIBRARY_PATH,
"LD_LIBRARY_PATH_TEST" => env.LD_LIBRARY_PATH )

I printenv into cgi_error.log when api called, here is the result:

As you can see, the LD_LIBRARY_PATH_TEST shows with the value set to LD_LIBRARY_PATH.

RE: Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by gstrauss almost 2 years ago

Is your CGI script setuid? setuid scripts will ignore LD_LIBRARY_PATH and other sensitive environment variables.
Does your script clear its environment?

I have tested the original setenv.add-environment posted at top along with a simple CGI script:

#!/bin/sh
printf "Status: 200\n\n" 
env | sort

RE: Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by gstrauss almost 2 years ago

BTW, the lighttpd.conf you attached is an incomplete configuration. It is missing the contents of include "/etc/lighttpd/conf-enabled/*.conf"

Print the entire lighttpd config with lighttpd -f /etc/lighttpd/lighttpd.conf -p

RE: Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by JacobBai almost 2 years ago

Thanks for your quick reply.

I created a simple cgi, and I found if just echo $LD_LIBRARY_PATH, then can see the variable has been set up, but it's just not showing when do printenv. I am going to do more test, see if my binaries can work even not printing out with printenv.

RE: [UE] Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by JacobBai almost 2 years ago

Hi gstrauss,

Thanks for your help.

The $LD_LIBRARY_PATH was defined and works fine even it's not showing with `printenv` or `env`.

But I really wonder why is that. Since I am using `sudo` in api, and try to keep $LD_LIBRARY_PATH when sudo get called (I have set up in /etc/sudoers, and works fine everywhere else), but `sudo` won't be able to keep it because it's not showing with printenv and env.

RE: [UE] Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by JacobBai almost 2 years ago

Just saw the last message, please check the complete config below.

RE: [UE] Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by JacobBai almost 2 years ago

sorry, i commented out the "LD_LIBRARY_PATH" => env.LD_LIBRARY_PATH in the last config, since it doesn't make any difference.
Please check this one, I updated it with LD_LIBRARY_PATH

RE: [UE] Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by gstrauss almost 2 years ago

This is not an issue with lighttpd.

I do not think that you have read the manual page for sudo

RE: [UE] Added LD_LIBRARY_PATH environment variable into lighttpd.conf but not working - Added by JacobBai almost 2 years ago

Hi gstrauss,

I got same api and environment working on lighttpd with raspbian, and it works fine. The lighttpd reserved LD_LIBRARY_PATH, also print it out with printenv and env.

Think I'll check with busybox regarding this, probably the shell didn't manage the environment properly.

Anyway, thanks for your support and appreciate the time u spent on this!

BR,
Jacob

    (1-15/15)