Question about the env

Hey, I noticed that the “env” directive in the main module is not an
equivalent of “export” in bash or “putenv” in C stdlib. The variables
defined by “env” seems only can be used by the embeded Perl module,
right?

The wiki doc for this directive is a little hard to understand. Let’s
make it simple. In which cases, the variables defined by “env” can be
considered equivalent to the variables in bash?

Thanks.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,150046,150046#msg-150046

On Fri, Nov 12, 2010 at 02:09:11AM -0500, speedfirst wrote:

Hey, I noticed that the “env” directive in the main module is not an
equivalent of “export” in bash or “putenv” in C stdlib. The variables
defined by “env” seems only can be used by the embeded Perl module,
right?

Not only.
For example, “env OPENSSL_ALLOW_PROXY_CERTS=1;” controls OpenSSL.
“env MALLOC_OPTIONS;” controls FreeBSD malloc().

The wiki doc for this directive is a little hard to understand. Let’s
make it simple. In which cases, the variables defined by “env” can be
considered equivalent to the variables in bash?

By default, nginx wipes all its environment variables expect TZ
variable.
“env NAME” allows to keep NAME variable value got from parent process,
i.e., shell. “env NAME=val” sets NAME variable value.


Igor S.
http://sysoev.ru/en/

On Fri, Nov 12, 2010 at 10:18:54PM +0300, Igor S. wrote:

On Fri, Nov 12, 2010 at 02:09:11AM -0500, speedfirst wrote:

Hey, I noticed that the “env” directive in the main module is not an
equivalent of “export” in bash or “putenv” in C stdlib. The variables
defined by “env” seems only can be used by the embeded Perl module,
right?

Not only.
For example, “env OPENSSL_ALLOW_PROXY_CERTS=1;” controls OpenSSL.
“env MALLOC_OPTIONS;” controls FreeBSD malloc().

However, setting FreeBSD MALLOC_OPTIONS using “env” is useless, because
malloc() analyzes MALLOC_OPTIONS on the very start before event main()
is called. Nevertheless “env MALLOC_OPTIONS;” is useful during online
upgrade: a new nginx is run with inherited MALLOC_OPTIONS.


Igor S.
http://sysoev.ru/en/

I carefully read the code of “ngx_set_env” and “ngx_set_environment”.
And I found that once “ngx_set_environment” is invoked, the arguments of
“env” directive is put into “envrion”, which makes those variables
effective.

However, this works well only when ngx_set_environment is invoked. And
ngx_set_environment will be invoked only when new worker process is
initiated. But in the developement/debug mode (daemon off,
master_process off), the variables will never be put into environ, which
may incur some inconsistent bug when nginx is running in dev mode and
production mode.

Therefore, I think this is a bug.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,150046,150461#msg-150461