comparison src/http/modules/perl/ngx_http_perl_module.c @ 258:6ae1357b7b7c NGINX_0_4_14

nginx 0.4.14 *) Feature: the "proxy_pass_error_message" directive in IMAP/POP3 proxy. *) Feature: now configure detects system PCRE library on FreeBSD, Linux, and NetBSD. *) Bugfix: ngx_http_perl_module did not work with perl built with the threads support; bug appeared in 0.3.38. *) Bugfix: ngx_http_perl_module did not work if perl was called recursively. *) Bugfix: nginx ignored a host name in an request line. *) Bugfix: a worker process may got caught in an endless loop, if a FastCGI server sent too many data to the stderr. *) Bugfix: the $upstream_response_time variable may be negative if the system time was changed backward. *) Bugfix: the "Auth-Login-Attempt" parameter was not sent to IMAP/POP3 proxy authentication server when POP3 was used. *) Bugfix: a segmentation fault might occur if connect to IMAP/POP3 proxy authentication server failed.
author Igor Sysoev <http://sysoev.ru>
date Mon, 27 Nov 2006 00:00:00 +0300
parents acd2ec3541cb
children 251bcd11a5b8
comparison
equal deleted inserted replaced
257:0e566ee1bcd5 258:6ae1357b7b7c
9 #include <ngx_http.h> 9 #include <ngx_http.h>
10 #include <ngx_http_perl_module.h> 10 #include <ngx_http_perl_module.h>
11 11
12 12
13 typedef struct { 13 typedef struct {
14 PerlInterpreter **free_perls;
15 ngx_uint_t interp;
16 ngx_uint_t nalloc;
17 ngx_uint_t interp_max;
18
19 PerlInterpreter *perl; 14 PerlInterpreter *perl;
15 HV *nginx;
20 ngx_str_t modules; 16 ngx_str_t modules;
21 ngx_array_t requires; 17 ngx_array_t requires;
22 } ngx_http_perl_main_conf_t; 18 } ngx_http_perl_main_conf_t;
23 19
24 20
43 #if (NGX_HTTP_SSI) 39 #if (NGX_HTTP_SSI)
44 static ngx_int_t ngx_http_perl_ssi(ngx_http_request_t *r, 40 static ngx_int_t ngx_http_perl_ssi(ngx_http_request_t *r,
45 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params); 41 ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params);
46 #endif 42 #endif
47 43
48 static ngx_int_t
49 ngx_http_perl_get_interpreter(ngx_http_perl_main_conf_t *pmcf,
50 PerlInterpreter **perl, ngx_log_t *log);
51 static ngx_inline void
52 ngx_http_perl_free_interpreter(ngx_http_perl_main_conf_t *pmcf,
53 PerlInterpreter *perl);
54 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf, 44 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf,
55 ngx_http_perl_main_conf_t *pmcf); 45 ngx_http_perl_main_conf_t *pmcf);
56 static PerlInterpreter * 46 static PerlInterpreter *
57 ngx_http_perl_create_interpreter(ngx_http_perl_main_conf_t *pmcf, 47 ngx_http_perl_create_interpreter(ngx_http_perl_main_conf_t *pmcf,
58 ngx_log_t *log); 48 ngx_log_t *log);
59 static ngx_int_t ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, 49 static ngx_int_t ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires,
60 ngx_log_t *log); 50 ngx_log_t *log);
61 static ngx_int_t ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, 51 static ngx_int_t ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r,
62 SV *sub, ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv); 52 HV *nginx, SV *sub, ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv);
63 static void ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv); 53 static void ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv);
64 54
65 static ngx_int_t ngx_http_perl_preconfiguration(ngx_conf_t *cf); 55 static ngx_int_t ngx_http_perl_preconfiguration(ngx_conf_t *cf);
66 static void *ngx_http_perl_create_main_conf(ngx_conf_t *cf); 56 static void *ngx_http_perl_create_main_conf(ngx_conf_t *cf);
67 static char *ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf); 57 static char *ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf);
70 void *child); 60 void *child);
71 static char *ngx_http_perl_require(ngx_conf_t *cf, ngx_command_t *cmd, 61 static char *ngx_http_perl_require(ngx_conf_t *cf, ngx_command_t *cmd,
72 void *conf); 62 void *conf);
73 static char *ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 63 static char *ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
74 static char *ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 64 static char *ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
75 static char *ngx_http_perl_interp_max_unsupported(ngx_conf_t *cf, void *post, 65 static void ngx_http_perl_cleanup_sv(void *data);
76 void *data); 66
77 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY) 67 #if (NGX_HAVE_PERL_MULTIPLICITY)
78 static void ngx_http_perl_cleanup_perl(void *data); 68 static void ngx_http_perl_cleanup_perl(void *data);
79 #endif 69 #endif
80 static void ngx_http_perl_cleanup_sv(void *data);
81
82
83 static ngx_conf_post_handler_pt ngx_http_perl_interp_max_p =
84 ngx_http_perl_interp_max_unsupported;
85 70
86 71
87 static ngx_command_t ngx_http_perl_commands[] = { 72 static ngx_command_t ngx_http_perl_commands[] = {
88 73
89 { ngx_string("perl_modules"), 74 { ngx_string("perl_modules"),
97 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, 82 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
98 ngx_http_perl_require, 83 ngx_http_perl_require,
99 NGX_HTTP_MAIN_CONF_OFFSET, 84 NGX_HTTP_MAIN_CONF_OFFSET,
100 0, 85 0,
101 NULL }, 86 NULL },
102
103 { ngx_string("perl_interp_max"),
104 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
105 ngx_conf_set_num_slot,
106 NGX_HTTP_MAIN_CONF_OFFSET,
107 offsetof(ngx_http_perl_main_conf_t, interp_max),
108 &ngx_http_perl_interp_max_p },
109 87
110 { ngx_string("perl"), 88 { ngx_string("perl"),
111 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 89 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
112 ngx_http_perl, 90 ngx_http_perl,
113 NGX_HTTP_LOC_CONF_OFFSET, 91 NGX_HTTP_LOC_CONF_OFFSET,
198 } 176 }
199 177
200 ngx_http_perl_handle_request(r); 178 ngx_http_perl_handle_request(r);
201 179
202 return NGX_DONE; 180 return NGX_DONE;
203
204 #if 0
205 r->request_body_in_single_buf = 1;
206 r->request_body_in_persistent_file = 1;
207 r->request_body_delete_incomplete_file = 1;
208
209 if (r->request_body_in_file_only) {
210 r->request_body_file_log_level = 0;
211 }
212
213 rc = ngx_http_read_client_request_body(r, ngx_http_perl_handle_request);
214
215 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
216 return rc;
217 }
218
219 return NGX_DONE;
220 #endif
221 } 181 }
222 182
223 183
224 void 184 void
225 ngx_http_perl_handle_request(ngx_http_request_t *r) 185 ngx_http_perl_handle_request(ngx_http_request_t *r)
245 ngx_http_set_ctx(r, ctx, ngx_http_perl_module); 205 ngx_http_set_ctx(r, ctx, ngx_http_perl_module);
246 } 206 }
247 207
248 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module); 208 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module);
249 209
250 rc = ngx_http_perl_get_interpreter(pmcf, &ctx->perl, r->connection->log);
251
252 if (rc != NGX_OK) {
253 ngx_http_finalize_request(r, rc);
254 return;
255 }
256
257 { 210 {
258 211
259 dTHXa(ctx->perl); 212 dTHXa(pmcf->perl);
213 PERL_SET_CONTEXT(pmcf->perl);
260 214
261 if (ctx->next == NULL) { 215 if (ctx->next == NULL) {
262 plcf = ngx_http_get_module_loc_conf(r, ngx_http_perl_module); 216 plcf = ngx_http_get_module_loc_conf(r, ngx_http_perl_module);
263 sub = plcf->sub; 217 sub = plcf->sub;
264 handler = &plcf->handler; 218 handler = &plcf->handler;
267 sub = ctx->next; 221 sub = ctx->next;
268 handler = &ngx_null_name; 222 handler = &ngx_null_name;
269 ctx->next = NULL; 223 ctx->next = NULL;
270 } 224 }
271 225
272 rc = ngx_http_perl_call_handler(aTHX_ r, sub, NULL, handler, NULL); 226 rc = ngx_http_perl_call_handler(aTHX_ r, pmcf->nginx, sub, NULL, handler,
273 227 NULL);
274 } 228
275 229 }
276 ngx_http_perl_free_interpreter(pmcf, ctx->perl);
277 230
278 if (rc > 600) { 231 if (rc > 600) {
279 rc = NGX_OK; 232 rc = NGX_OK;
280 } 233 }
281 234
336 ngx_http_set_ctx(r, ctx, ngx_http_perl_module); 289 ngx_http_set_ctx(r, ctx, ngx_http_perl_module);
337 } 290 }
338 291
339 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module); 292 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module);
340 293
341 rc = ngx_http_perl_get_interpreter(pmcf, &ctx->perl, r->connection->log);
342
343 if (rc != NGX_OK) {
344 return rc;
345 }
346
347 value.data = NULL; 294 value.data = NULL;
348 295
349 { 296 {
350 297
351 dTHXa(ctx->perl); 298 dTHXa(pmcf->perl);
352 299 PERL_SET_CONTEXT(pmcf->perl);
353 rc = ngx_http_perl_call_handler(aTHX_ r, pv->sub, NULL, 300
301 rc = ngx_http_perl_call_handler(aTHX_ r, pmcf->nginx, pv->sub, NULL,
354 &pv->handler, &value); 302 &pv->handler, &value);
355 303
356 } 304 }
357
358 ngx_http_perl_free_interpreter(pmcf, ctx->perl);
359 305
360 if (value.data) { 306 if (value.data) {
361 v->len = value.len; 307 v->len = value.len;
362 v->valid = 1; 308 v->valid = 1;
363 v->no_cachable = 0; 309 v->no_cachable = 0;
369 } 315 }
370 316
371 ctx->filename.data = NULL; 317 ctx->filename.data = NULL;
372 ctx->redirect_uri.len = 0; 318 ctx->redirect_uri.len = 0;
373 319
320 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
321 "perl variable done");
322
374 return rc; 323 return rc;
375 } 324 }
376 325
377 326
378 #if (NGX_HTTP_SSI) 327 #if (NGX_HTTP_SSI)
388 ngx_http_perl_main_conf_t *pmcf; 337 ngx_http_perl_main_conf_t *pmcf;
389 338
390 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 339 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
391 "perl ssi handler"); 340 "perl ssi handler");
392 341
393 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module);
394
395 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); 342 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
396 343
397 if (ctx == NULL) { 344 if (ctx == NULL) {
398 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t)); 345 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t));
399 if (ctx == NULL) { 346 if (ctx == NULL) {
401 } 348 }
402 349
403 ngx_http_set_ctx(r, ctx, ngx_http_perl_module); 350 ngx_http_set_ctx(r, ctx, ngx_http_perl_module);
404 } 351 }
405 352
406 rc = ngx_http_perl_get_interpreter(pmcf, &ctx->perl, r->connection->log); 353 pmcf = ngx_http_get_module_main_conf(r, ngx_http_perl_module);
407
408 if (rc != NGX_OK) {
409 return rc;
410 }
411 354
412 ctx->ssi = ssi_ctx; 355 ctx->ssi = ssi_ctx;
413 356
414 handler = params[NGX_HTTP_PERL_SSI_SUB]; 357 handler = params[NGX_HTTP_PERL_SSI_SUB];
415 handler->data[handler->len] = '\0'; 358 handler->data[handler->len] = '\0';
416 359
417 { 360 {
418 361
419 dTHXa(ctx->perl); 362 dTHXa(pmcf->perl);
363 PERL_SET_CONTEXT(pmcf->perl);
420 364
421 #if 0 365 #if 0
422 366
423 /* the code is disabled to force the precompiled perl code using only */ 367 /* the code is disabled to force the precompiled perl code using only */
424 368
436 380
437 #endif 381 #endif
438 382
439 sv = newSVpvn((char *) handler->data, handler->len); 383 sv = newSVpvn((char *) handler->data, handler->len);
440 384
441 rc = ngx_http_perl_call_handler(aTHX_ r, sv, &params[NGX_HTTP_PERL_SSI_ARG], 385 rc = ngx_http_perl_call_handler(aTHX_ r, pmcf->nginx, sv,
386 &params[NGX_HTTP_PERL_SSI_ARG],
442 handler, NULL); 387 handler, NULL);
443 388
444 SvREFCNT_dec(sv); 389 SvREFCNT_dec(sv);
445 390
446 } 391 }
447
448 ngx_http_perl_free_interpreter(pmcf, ctx->perl);
449 392
450 ctx->filename.data = NULL; 393 ctx->filename.data = NULL;
451 ctx->redirect_uri.len = 0; 394 ctx->redirect_uri.len = 0;
452 ctx->ssi = NULL; 395 ctx->ssi = NULL;
453 396
397 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "perl ssi done");
398
454 return rc; 399 return rc;
455 } 400 }
456 401
457 #endif 402 #endif
458
459
460 static ngx_int_t
461 ngx_http_perl_get_interpreter(ngx_http_perl_main_conf_t *pmcf,
462 PerlInterpreter **perl, ngx_log_t *log)
463 {
464 if (pmcf->interp) {
465 pmcf->interp--;
466
467 *perl = pmcf->free_perls[pmcf->interp];
468
469 return NGX_OK;
470 }
471
472 if (pmcf->nalloc < pmcf->interp_max) {
473 *perl = ngx_http_perl_create_interpreter(pmcf, log);
474
475 if (*perl) {
476 return NGX_OK;
477 }
478
479 return NGX_HTTP_INTERNAL_SERVER_ERROR;
480 }
481
482 ngx_log_error(NGX_LOG_ALERT, log, 0, "no free perl interpreter");
483
484 return NGX_HTTP_SERVICE_UNAVAILABLE;
485 }
486
487
488 static ngx_inline void
489 ngx_http_perl_free_interpreter(ngx_http_perl_main_conf_t *pmcf,
490 PerlInterpreter *perl)
491 {
492 pmcf->free_perls[pmcf->interp++] = perl;
493 }
494 403
495 404
496 static char * 405 static char *
497 ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf) 406 ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf)
498 { 407 {
499 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY) 408 #if (NGX_HAVE_PERL_MULTIPLICITY)
500 ngx_pool_cleanup_t *cln; 409 ngx_pool_cleanup_t *cln;
501 410
502 cln = ngx_pool_cleanup_add(cf->pool, 0); 411 cln = ngx_pool_cleanup_add(cf->pool, 0);
503 if (cln == NULL) { 412 if (cln == NULL) {
504 return NGX_CONF_ERROR; 413 return NGX_CONF_ERROR;
518 if (ngx_conf_full_name(cf->cycle, &pmcf->modules) != NGX_OK) { 427 if (ngx_conf_full_name(cf->cycle, &pmcf->modules) != NGX_OK) {
519 return NGX_CONF_ERROR; 428 return NGX_CONF_ERROR;
520 } 429 }
521 } 430 }
522 431
523 #if !(NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY) 432 #if !(NGX_HAVE_PERL_MULTIPLICITY)
524 433
525 if (perl) { 434 if (perl) {
526 if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, cf->log) 435 if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, cf->log)
527 != NGX_OK) 436 != NGX_OK)
528 { 437 {
543 if (pmcf->perl == NULL) { 452 if (pmcf->perl == NULL) {
544 PERL_SYS_TERM(); 453 PERL_SYS_TERM();
545 return NGX_CONF_ERROR; 454 return NGX_CONF_ERROR;
546 } 455 }
547 456
548 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY) 457 pmcf->nginx = nginx_stash;
458
459 #if (NGX_HAVE_PERL_MULTIPLICITY)
549 460
550 cln->handler = ngx_http_perl_cleanup_perl; 461 cln->handler = ngx_http_perl_cleanup_perl;
551 cln->data = pmcf->perl; 462 cln->data = pmcf->perl;
552 463
553 #else 464 #else
570 char *ver, *embedding[6]; 481 char *ver, *embedding[6];
571 PerlInterpreter *perl; 482 PerlInterpreter *perl;
572 483
573 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "create perl interpreter"); 484 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "create perl interpreter");
574 485
575 #if (NGX_HAVE_PERL_CLONE)
576
577 if (pmcf->perl) {
578
579 perl = perl_clone(pmcf->perl, CLONEf_KEEP_PTR_TABLE);
580 if (perl == NULL) {
581 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_clone() failed");
582 return NULL;
583 }
584
585 {
586
587 dTHXa(perl);
588
589 ptr_table_free(PL_ptr_table);
590 PL_ptr_table = NULL;
591
592 }
593
594 pmcf->nalloc++;
595
596 return perl;
597 }
598
599 #endif
600
601 perl = perl_alloc(); 486 perl = perl_alloc();
602 if (perl == NULL) { 487 if (perl == NULL) {
603 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_alloc() failed"); 488 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_alloc() failed");
604 return NULL; 489 return NULL;
605 } 490 }
606 491
492 {
493
494 dTHXa(perl);
495 PERL_SET_CONTEXT(perl);
496
607 perl_construct(perl); 497 perl_construct(perl);
608
609 {
610
611 dTHXa(perl);
612 498
613 #ifdef PERL_EXIT_DESTRUCT_END 499 #ifdef PERL_EXIT_DESTRUCT_END
614 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 500 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
615 #endif 501 #endif
616 502
650 goto fail; 536 goto fail;
651 } 537 }
652 538
653 } 539 }
654 540
655 pmcf->nalloc++;
656
657 return perl; 541 return perl;
658 542
659 fail: 543 fail:
660 544
661 (void) perl_destruct(perl); 545 (void) perl_destruct(perl);
697 return NGX_OK; 581 return NGX_OK;
698 } 582 }
699 583
700 584
701 static ngx_int_t 585 static ngx_int_t
702 ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, SV *sub, 586 ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, HV *nginx, SV *sub,
703 ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv) 587 ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv)
704 { 588 {
705 SV *sv; 589 SV *sv;
706 int n, status; 590 int n, status;
707 char *line; 591 char *line;
716 ENTER; 600 ENTER;
717 SAVETMPS; 601 SAVETMPS;
718 602
719 PUSHMARK(sp); 603 PUSHMARK(sp);
720 604
721 sv = sv_2mortal(sv_bless(newRV_noinc(newSViv(PTR2IV(r))), nginx_stash)); 605 sv = sv_2mortal(sv_bless(newRV_noinc(newSViv(PTR2IV(r))), nginx));
722 XPUSHs(sv); 606 XPUSHs(sv);
723 607
724 if (args) { 608 if (args) {
725 for (i = 0; args[i]; i++) { /* void */ } 609 for (i = 0; args[i]; i++) { /* void */ }
726 610
808 } 692 }
809 } 693 }
810 694
811 if (ngx_strncmp(p, "sub ", 4) == 0 || ngx_strncmp(p, "use ", 4) == 0) { 695 if (ngx_strncmp(p, "sub ", 4) == 0 || ngx_strncmp(p, "use ", 4) == 0) {
812 *sv = eval_pv((char *) p, FALSE); 696 *sv = eval_pv((char *) p, FALSE);
697
698 /* eval_pv() does not set ERRSV on failure */
699
813 return; 700 return;
814 } 701 }
815 702
816 *sv = NULL; 703 *sv = NULL;
817 } 704 }
824 711
825 pmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_perl_main_conf_t)); 712 pmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_perl_main_conf_t));
826 if (pmcf == NULL) { 713 if (pmcf == NULL) {
827 return NGX_CONF_ERROR; 714 return NGX_CONF_ERROR;
828 } 715 }
829
830 pmcf->interp_max = NGX_CONF_UNSET_UINT;
831 716
832 if (ngx_array_init(&pmcf->requires, cf->pool, 1, sizeof(u_char *)) 717 if (ngx_array_init(&pmcf->requires, cf->pool, 1, sizeof(u_char *))
833 != NGX_OK) 718 != NGX_OK)
834 { 719 {
835 return NULL; 720 return NULL;
842 static char * 727 static char *
843 ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf) 728 ngx_http_perl_init_main_conf(ngx_conf_t *cf, void *conf)
844 { 729 {
845 ngx_http_perl_main_conf_t *pmcf = conf; 730 ngx_http_perl_main_conf_t *pmcf = conf;
846 731
847 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
848 ngx_conf_init_uint_value(pmcf->interp_max, 10);
849 #else
850 ngx_conf_init_uint_value(pmcf->interp_max, 1);
851 #endif
852
853 pmcf->free_perls = ngx_pcalloc(cf->pool,
854 pmcf->interp_max * sizeof(PerlInterpreter *));
855 if (pmcf->free_perls == NULL) {
856 return NGX_CONF_ERROR;
857 }
858
859 if (pmcf->perl == NULL) { 732 if (pmcf->perl == NULL) {
860 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) { 733 if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK) {
861 return NGX_CONF_ERROR; 734 return NGX_CONF_ERROR;
862 } 735 }
863 } 736 }
864 737
865 #if !(NGX_HAVE_PERL_CLONE)
866 ngx_http_perl_free_interpreter(pmcf, pmcf->perl);
867 #endif
868
869 return NGX_CONF_OK; 738 return NGX_CONF_OK;
870 } 739 }
871 740
872 741
873 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY) 742 #if (NGX_HAVE_PERL_MULTIPLICITY)
874 743
875 static void 744 static void
876 ngx_http_perl_cleanup_perl(void *data) 745 ngx_http_perl_cleanup_perl(void *data)
877 { 746 {
878 PerlInterpreter *perl = data; 747 PerlInterpreter *perl = data;
879 748
749 PERL_SET_CONTEXT(perl);
750
880 (void) perl_destruct(perl); 751 (void) perl_destruct(perl);
881 752
882 perl_free(perl); 753 perl_free(perl);
883 754
884 PERL_SYS_TERM(); 755 PERL_SYS_TERM();
891 ngx_http_perl_cleanup_sv(void *data) 762 ngx_http_perl_cleanup_sv(void *data)
892 { 763 {
893 ngx_http_perl_cleanup_t *cln = data; 764 ngx_http_perl_cleanup_t *cln = data;
894 765
895 dTHXa(cln->perl); 766 dTHXa(cln->perl);
767 PERL_SET_CONTEXT(cln->perl);
896 768
897 SvREFCNT_dec(cln->sv); 769 SvREFCNT_dec(cln->sv);
898 } 770 }
899 771
900 772
1017 plcf->handler = value[1]; 889 plcf->handler = value[1];
1018 890
1019 { 891 {
1020 892
1021 dTHXa(pmcf->perl); 893 dTHXa(pmcf->perl);
894 PERL_SET_CONTEXT(pmcf->perl);
1022 895
1023 ngx_http_perl_eval_anon_sub(aTHX_ &value[1], &plcf->sub); 896 ngx_http_perl_eval_anon_sub(aTHX_ &value[1], &plcf->sub);
1024 897
1025 if (plcf->sub == &PL_sv_undef) { 898 if (plcf->sub == &PL_sv_undef) {
1026 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, 899 ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
1099 pv->handler = value[2]; 972 pv->handler = value[2];
1100 973
1101 { 974 {
1102 975
1103 dTHXa(pmcf->perl); 976 dTHXa(pmcf->perl);
977 PERL_SET_CONTEXT(pmcf->perl);
1104 978
1105 ngx_http_perl_eval_anon_sub(aTHX_ &value[2], &pv->sub); 979 ngx_http_perl_eval_anon_sub(aTHX_ &value[2], &pv->sub);
1106 980
1107 if (pv->sub == &PL_sv_undef) { 981 if (pv->sub == &PL_sv_undef) {
1108 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, 982 ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
1124 v->get_handler = ngx_http_perl_variable; 998 v->get_handler = ngx_http_perl_variable;
1125 v->data = (uintptr_t) pv; 999 v->data = (uintptr_t) pv;
1126 1000
1127 return NGX_CONF_OK; 1001 return NGX_CONF_OK;
1128 } 1002 }
1129
1130
1131 static char *
1132 ngx_http_perl_interp_max_unsupported(ngx_conf_t *cf, void *post, void *data)
1133 {
1134 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
1135
1136 return NGX_CONF_OK;
1137
1138 #else
1139
1140 return "to use perl_interp_max you have to build perl with "
1141 "-Dusemultiplicity or -Dusethreads options";
1142
1143 #endif
1144 }