Mercurial > hg > nginx-quic
comparison src/http/modules/perl/ngx_http_perl_module.c @ 873:f92ad15c2db1
fix segfaults in future workers those will use old configuration,
if new configuration failed
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 26 Nov 2006 15:35:02 +0000 |
parents | 1c4a5b3f9110 |
children | 98afa13ea7e5 |
comparison
equal
deleted
inserted
replaced
872:1c4a5b3f9110 | 873:f92ad15c2db1 |
---|---|
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 *perl; | 14 PerlInterpreter *perl; |
15 HV *nginx; | |
15 ngx_str_t modules; | 16 ngx_str_t modules; |
16 ngx_array_t requires; | 17 ngx_array_t requires; |
17 } ngx_http_perl_main_conf_t; | 18 } ngx_http_perl_main_conf_t; |
18 | 19 |
19 | 20 |
46 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, |
47 ngx_log_t *log); | 48 ngx_log_t *log); |
48 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, |
49 ngx_log_t *log); | 50 ngx_log_t *log); |
50 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, |
51 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); |
52 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); |
53 | 54 |
54 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); |
55 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); |
56 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); |
207 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); |
208 | 209 |
209 { | 210 { |
210 | 211 |
211 dTHXa(pmcf->perl); | 212 dTHXa(pmcf->perl); |
213 PERL_SET_CONTEXT(pmcf->perl); | |
212 | 214 |
213 if (ctx->next == NULL) { | 215 if (ctx->next == NULL) { |
214 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); |
215 sub = plcf->sub; | 217 sub = plcf->sub; |
216 handler = &plcf->handler; | 218 handler = &plcf->handler; |
219 sub = ctx->next; | 221 sub = ctx->next; |
220 handler = &ngx_null_name; | 222 handler = &ngx_null_name; |
221 ctx->next = NULL; | 223 ctx->next = NULL; |
222 } | 224 } |
223 | 225 |
224 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, |
227 NULL); | |
225 | 228 |
226 } | 229 } |
227 | 230 |
228 if (rc > 600) { | 231 if (rc > 600) { |
229 rc = NGX_OK; | 232 rc = NGX_OK; |
291 value.data = NULL; | 294 value.data = NULL; |
292 | 295 |
293 { | 296 { |
294 | 297 |
295 dTHXa(pmcf->perl); | 298 dTHXa(pmcf->perl); |
296 | 299 PERL_SET_CONTEXT(pmcf->perl); |
297 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, | |
298 &pv->handler, &value); | 302 &pv->handler, &value); |
299 | 303 |
300 } | 304 } |
301 | 305 |
302 if (value.data) { | 306 if (value.data) { |
354 handler->data[handler->len] = '\0'; | 358 handler->data[handler->len] = '\0'; |
355 | 359 |
356 { | 360 { |
357 | 361 |
358 dTHXa(pmcf->perl); | 362 dTHXa(pmcf->perl); |
363 PERL_SET_CONTEXT(pmcf->perl); | |
359 | 364 |
360 #if 0 | 365 #if 0 |
361 | 366 |
362 /* 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 */ |
363 | 368 |
375 | 380 |
376 #endif | 381 #endif |
377 | 382 |
378 sv = newSVpvn((char *) handler->data, handler->len); | 383 sv = newSVpvn((char *) handler->data, handler->len); |
379 | 384 |
380 rc = ngx_http_perl_call_handler(aTHX_ r, sv, ¶ms[NGX_HTTP_PERL_SSI_ARG], | 385 rc = ngx_http_perl_call_handler(aTHX_ r, pmcf->nginx, sv, |
386 ¶ms[NGX_HTTP_PERL_SSI_ARG], | |
381 handler, NULL); | 387 handler, NULL); |
382 | 388 |
383 SvREFCNT_dec(sv); | 389 SvREFCNT_dec(sv); |
384 | 390 |
385 } | 391 } |
446 if (pmcf->perl == NULL) { | 452 if (pmcf->perl == NULL) { |
447 PERL_SYS_TERM(); | 453 PERL_SYS_TERM(); |
448 return NGX_CONF_ERROR; | 454 return NGX_CONF_ERROR; |
449 } | 455 } |
450 | 456 |
457 pmcf->nginx = nginx_stash; | |
458 | |
451 #if (NGX_HAVE_PERL_MULTIPLICITY) | 459 #if (NGX_HAVE_PERL_MULTIPLICITY) |
452 | 460 |
453 cln->handler = ngx_http_perl_cleanup_perl; | 461 cln->handler = ngx_http_perl_cleanup_perl; |
454 cln->data = pmcf->perl; | 462 cln->data = pmcf->perl; |
455 | 463 |
479 if (perl == NULL) { | 487 if (perl == NULL) { |
480 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_alloc() failed"); | 488 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_alloc() failed"); |
481 return NULL; | 489 return NULL; |
482 } | 490 } |
483 | 491 |
492 { | |
493 | |
494 dTHXa(perl); | |
495 PERL_SET_CONTEXT(perl); | |
496 | |
484 perl_construct(perl); | 497 perl_construct(perl); |
485 | |
486 { | |
487 | |
488 dTHXa(perl); | |
489 | 498 |
490 #ifdef PERL_EXIT_DESTRUCT_END | 499 #ifdef PERL_EXIT_DESTRUCT_END |
491 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; | 500 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
492 #endif | 501 #endif |
493 | 502 |
572 return NGX_OK; | 581 return NGX_OK; |
573 } | 582 } |
574 | 583 |
575 | 584 |
576 static ngx_int_t | 585 static ngx_int_t |
577 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, |
578 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) |
579 { | 588 { |
580 SV *sv; | 589 SV *sv; |
581 int n, status; | 590 int n, status; |
582 char *line; | 591 char *line; |
591 ENTER; | 600 ENTER; |
592 SAVETMPS; | 601 SAVETMPS; |
593 | 602 |
594 PUSHMARK(sp); | 603 PUSHMARK(sp); |
595 | 604 |
596 sv = sv_2mortal(sv_bless(newRV_noinc(newSViv(PTR2IV(r))), nginx_stash)); | 605 sv = sv_2mortal(sv_bless(newRV_noinc(newSViv(PTR2IV(r))), nginx)); |
597 XPUSHs(sv); | 606 XPUSHs(sv); |
598 | 607 |
599 if (args) { | 608 if (args) { |
600 for (i = 0; args[i]; i++) { /* void */ } | 609 for (i = 0; args[i]; i++) { /* void */ } |
601 | 610 |
732 static void | 741 static void |
733 ngx_http_perl_cleanup_perl(void *data) | 742 ngx_http_perl_cleanup_perl(void *data) |
734 { | 743 { |
735 PerlInterpreter *perl = data; | 744 PerlInterpreter *perl = data; |
736 | 745 |
746 PERL_SET_CONTEXT(perl); | |
747 | |
737 (void) perl_destruct(perl); | 748 (void) perl_destruct(perl); |
738 | 749 |
739 perl_free(perl); | 750 perl_free(perl); |
740 | 751 |
741 PERL_SYS_TERM(); | 752 PERL_SYS_TERM(); |
748 ngx_http_perl_cleanup_sv(void *data) | 759 ngx_http_perl_cleanup_sv(void *data) |
749 { | 760 { |
750 ngx_http_perl_cleanup_t *cln = data; | 761 ngx_http_perl_cleanup_t *cln = data; |
751 | 762 |
752 dTHXa(cln->perl); | 763 dTHXa(cln->perl); |
764 PERL_SET_CONTEXT(cln->perl); | |
753 | 765 |
754 SvREFCNT_dec(cln->sv); | 766 SvREFCNT_dec(cln->sv); |
755 } | 767 } |
756 | 768 |
757 | 769 |
874 plcf->handler = value[1]; | 886 plcf->handler = value[1]; |
875 | 887 |
876 { | 888 { |
877 | 889 |
878 dTHXa(pmcf->perl); | 890 dTHXa(pmcf->perl); |
891 PERL_SET_CONTEXT(pmcf->perl); | |
879 | 892 |
880 ngx_http_perl_eval_anon_sub(aTHX_ &value[1], &plcf->sub); | 893 ngx_http_perl_eval_anon_sub(aTHX_ &value[1], &plcf->sub); |
881 | 894 |
882 if (plcf->sub == &PL_sv_undef) { | 895 if (plcf->sub == &PL_sv_undef) { |
883 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, | 896 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, |
956 pv->handler = value[2]; | 969 pv->handler = value[2]; |
957 | 970 |
958 { | 971 { |
959 | 972 |
960 dTHXa(pmcf->perl); | 973 dTHXa(pmcf->perl); |
974 PERL_SET_CONTEXT(pmcf->perl); | |
961 | 975 |
962 ngx_http_perl_eval_anon_sub(aTHX_ &value[2], &pv->sub); | 976 ngx_http_perl_eval_anon_sub(aTHX_ &value[2], &pv->sub); |
963 | 977 |
964 if (pv->sub == &PL_sv_undef) { | 978 if (pv->sub == &PL_sv_undef) { |
965 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, | 979 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, |