Opened 9 years ago
Last modified 9 years ago
#994 accepted defect
perl_require directive has effect only at first config
| Reported by: | Owned by: | ||
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | other | Version: | 1.2.x |
| Keywords: | Cc: | ||
| uname -a: | Linux backend01.setup-team.net 3.2.0-37-virtual #58-Ubuntu SMP Thu Jan 24 15:48:03 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux | ||
| nginx -V: |
# nginx -V
nginx version: nginx/1.2.7 TLS SNI support enabled configure arguments: --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --with-pcre-jit --with-debug --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.2.7/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.2.7/debian/modules/chunkin-nginx-module --add-module=/build/buildd/nginx-1.2.7/debian/modules/headers-more-nginx-module --add-module=/build/buildd/nginx-1.2.7/debian/modules/nginx-development-kit --add-module=/build/buildd/nginx-1.2.7/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.2.7/debian/modules/nginx-http-push --add-module=/build/buildd/nginx-1.2.7/debian/modules/nginx-lua --add-module=/build/buildd/nginx-1.2.7/debian/modules/nginx-upload-module --add-module=/build/buildd/nginx-1.2.7/debian/modules/nginx-upload-progress --add-module=/build/buildd/nginx-1.2.7/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.2.7/debian/modules/nginx-dav-ext-module |
||
Description
my configs are included as:
include /etc/nginx/sites-enabled/*.conf;
if I want to use 'perl_require' directive I should place it ONLY at first conf file (in alfabetical order)
If I put directive into any other conf file it even does not complain if I try to load unexisting module
Note:
See TracTickets
for help on using tickets.

All
perl_requiresdirectives are processed when nginx creates a Perl interpreter. And this in turn happens when nginx parses firstperlorperl_setdirective (or after configuration parsing in there are noperl/perl_setdirectives in the configuration). That is, with a configuration like:perl_require foo.pm; server { ... location / { perl "..."; }} perl_require bar.pm; server { ... location / { perl "..."; }}only
foo.pmmodule will be loaded.The following patch fixes this by loading required modules before each
perl/perl_setdirective:# HG changeset patch # User Maxim Dounin <mdounin@mdounin.ru> # Date 1480622026 -10800 # Thu Dec 01 22:53:46 2016 +0300 # Node ID 123f22ed6e7a4ff291c62fb17c9ccb5343b3aa02 # Parent 079b7b81c47261ae0de2a48f2bc2d64aa2779ef4 Perl: loading of additional required modules (ticket #994). Previously, in a configuration like perl_require foo.pm; server { ... location / { perl "..."; }} perl_require bar.pm; server { ... location / { perl "..."; }} the "bar.pm" module was completely ignored, as all required modules were only loaded when creating an interpreter during parsing the perl directive in the first server{} block. Fix is to load additional modules, if any, by calling the ngx_http_perl_run_requires() function again on each perl/perl_set parsing. This is relatively cheap even without tracking of what we've already loaded as Perl does it itself and simply ignores attempts to load already loaded modules. diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c --- a/src/http/modules/perl/ngx_http_perl_module.c +++ b/src/http/modules/perl/ngx_http_perl_module.c @@ -943,6 +943,10 @@ ngx_http_perl(ngx_conf_t *cf, ngx_comman PERL_SET_CONTEXT(pmcf->perl); PERL_SET_INTERP(pmcf->perl); + if (ngx_http_perl_run_requires(aTHX_ pmcf->requires, cf->log) != NGX_OK) { + return NGX_CONF_ERROR; + } + ngx_http_perl_eval_anon_sub(aTHX_ &value[1], &plcf->sub); if (plcf->sub == &PL_sv_undef) { @@ -1015,6 +1019,10 @@ ngx_http_perl_set(ngx_conf_t *cf, ngx_co PERL_SET_CONTEXT(pmcf->perl); PERL_SET_INTERP(pmcf->perl); + if (ngx_http_perl_run_requires(aTHX_ pmcf->requires, cf->log) != NGX_OK) { + return NGX_CONF_ERROR; + } + ngx_http_perl_eval_anon_sub(aTHX_ &value[2], &pv->sub); if (pv->sub == &PL_sv_undef) {