Skip to content

Commit

Permalink
Perl: added PERL_SET_INTERP().
Browse files Browse the repository at this point in the history
For Perl compiled with threads, without PERL_SET_INTERP() the PL_curinterp
remains set to the first interpreter created (that is, one created at
original start).  As a result after a reload Perl thinks that operations
are done withing a thread, and, most notably, denies to change environment.

For example, the following code properly works on original start,
but fails after a reload:

    perl 'sub {
        my $r = shift;

        $r->send_http_header("text/plain");

        $ENV{TZ} = "UTC";
        $r->print("tz: " . $ENV{TZ} . " (localtime " . (localtime()) . ")\n");
        $ENV{TZ} = "Europe/Moscow";
        $r->print("tz: " . $ENV{TZ} . " (localtime " . (localtime()) . ")\n");

        return OK;
    }';

To fix this, PERL_SET_INTERP() added anywhere where PERL_SET_CONTEXT()
was previously used.

Note that PERL_SET_INTERP() doesn't seem to be documented anywhere.
Yet it is used in some other software, and also seems to be the only
solution possible.
  • Loading branch information
mdounin committed Dec 7, 2016
1 parent fcb2e28 commit 408e49f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/http/modules/perl/ngx_http_perl_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ ngx_http_perl_handle_request(ngx_http_request_t *r)

dTHXa(pmcf->perl);
PERL_SET_CONTEXT(pmcf->perl);
PERL_SET_INTERP(pmcf->perl);

if (ctx->next == NULL) {
plcf = ngx_http_get_module_loc_conf(r, ngx_http_perl_module);
Expand Down Expand Up @@ -322,6 +323,7 @@ ngx_http_perl_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,

dTHXa(pmcf->perl);
PERL_SET_CONTEXT(pmcf->perl);
PERL_SET_INTERP(pmcf->perl);

rc = ngx_http_perl_call_handler(aTHX_ r, pmcf->nginx, pv->sub, NULL,
&pv->handler, &value);
Expand Down Expand Up @@ -387,6 +389,7 @@ ngx_http_perl_ssi(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ssi_ctx,

dTHXa(pmcf->perl);
PERL_SET_CONTEXT(pmcf->perl);
PERL_SET_INTERP(pmcf->perl);

#if 0

Expand Down Expand Up @@ -568,6 +571,7 @@ ngx_http_perl_create_interpreter(ngx_conf_t *cf,

dTHXa(perl);
PERL_SET_CONTEXT(perl);
PERL_SET_INTERP(perl);

perl_construct(perl);

Expand Down Expand Up @@ -828,6 +832,7 @@ ngx_http_perl_cleanup_perl(void *data)
PerlInterpreter *perl = data;

PERL_SET_CONTEXT(perl);
PERL_SET_INTERP(perl);

(void) perl_destruct(perl);

Expand Down Expand Up @@ -936,6 +941,7 @@ ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

dTHXa(pmcf->perl);
PERL_SET_CONTEXT(pmcf->perl);
PERL_SET_INTERP(pmcf->perl);

ngx_http_perl_eval_anon_sub(aTHX_ &value[1], &plcf->sub);

Expand Down Expand Up @@ -1007,6 +1013,7 @@ ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

dTHXa(pmcf->perl);
PERL_SET_CONTEXT(pmcf->perl);
PERL_SET_INTERP(pmcf->perl);

ngx_http_perl_eval_anon_sub(aTHX_ &value[2], &pv->sub);

Expand Down Expand Up @@ -1039,6 +1046,7 @@ ngx_http_perl_init_worker(ngx_cycle_t *cycle)
if (pmcf) {
dTHXa(pmcf->perl);
PERL_SET_CONTEXT(pmcf->perl);
PERL_SET_INTERP(pmcf->perl);

/* set worker's $$ */

Expand Down

0 comments on commit 408e49f

Please sign in to comment.