Mercurial > hg > nginx
comparison src/http/modules/perl/ngx_http_perl_module.c @ 3175:cad19e8e0cc8
allow several perl_modules
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 30 Sep 2009 11:46:01 +0000 |
parents | 479fd46cd1c4 |
children | 67da53a19e02 |
comparison
equal
deleted
inserted
replaced
3174:479fd46cd1c4 | 3175:cad19e8e0cc8 |
---|---|
11 | 11 |
12 | 12 |
13 typedef struct { | 13 typedef struct { |
14 PerlInterpreter *perl; | 14 PerlInterpreter *perl; |
15 HV *nginx; | 15 HV *nginx; |
16 ngx_str_t modules; | 16 ngx_array_t *modules; |
17 ngx_array_t *requires; | 17 ngx_array_t *requires; |
18 } ngx_http_perl_main_conf_t; | 18 } ngx_http_perl_main_conf_t; |
19 | 19 |
20 | 20 |
21 typedef struct { | 21 typedef struct { |
70 | 70 |
71 static ngx_command_t ngx_http_perl_commands[] = { | 71 static ngx_command_t ngx_http_perl_commands[] = { |
72 | 72 |
73 { ngx_string("perl_modules"), | 73 { ngx_string("perl_modules"), |
74 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | 74 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, |
75 ngx_conf_set_str_slot, | 75 ngx_conf_set_str_array_slot, |
76 NGX_HTTP_MAIN_CONF_OFFSET, | 76 NGX_HTTP_MAIN_CONF_OFFSET, |
77 offsetof(ngx_http_perl_main_conf_t, modules), | 77 offsetof(ngx_http_perl_main_conf_t, modules), |
78 NULL }, | 78 NULL }, |
79 | 79 |
80 { ngx_string("perl_require"), | 80 { ngx_string("perl_require"), |
459 | 459 |
460 | 460 |
461 static char * | 461 static char * |
462 ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf) | 462 ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf) |
463 { | 463 { |
464 ngx_str_t *m; | |
465 ngx_uint_t i; | |
464 #if (NGX_HAVE_PERL_MULTIPLICITY) | 466 #if (NGX_HAVE_PERL_MULTIPLICITY) |
465 ngx_pool_cleanup_t *cln; | 467 ngx_pool_cleanup_t *cln; |
466 | 468 |
467 cln = ngx_pool_cleanup_add(cf->pool, 0); | 469 cln = ngx_pool_cleanup_add(cf->pool, 0); |
468 if (cln == NULL) { | 470 if (cln == NULL) { |
469 return NGX_CONF_ERROR; | 471 return NGX_CONF_ERROR; |
470 } | 472 } |
472 #else | 474 #else |
473 static PerlInterpreter *perl; | 475 static PerlInterpreter *perl; |
474 #endif | 476 #endif |
475 | 477 |
476 #ifdef NGX_PERL_MODULES | 478 #ifdef NGX_PERL_MODULES |
477 if (pmcf->modules.data == NULL) { | 479 if (pmcf->modules == NGX_CONF_UNSET_PTR) { |
478 pmcf->modules.data = NGX_PERL_MODULES; | 480 |
479 } | 481 pmcf->modules = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t)); |
480 #endif | 482 if (pmcf->modules == NULL) { |
481 | |
482 if (pmcf->modules.data) { | |
483 if (ngx_conf_full_name(cf->cycle, &pmcf->modules, 0) != NGX_OK) { | |
484 return NGX_CONF_ERROR; | 483 return NGX_CONF_ERROR; |
484 } | |
485 | |
486 m = ngx_array_push(pmcf->modules); | |
487 if (m == NULL) { | |
488 return NGX_CONF_ERROR; | |
489 } | |
490 | |
491 m->len = sizeof(NGX_PERL_MODULES) - 1; | |
492 m->data = NGX_PERL_MODULES; | |
493 } | |
494 #endif | |
495 | |
496 if (pmcf->modules != NGX_CONF_UNSET_PTR) { | |
497 m = pmcf->modules->elts; | |
498 for (i = 0; i < pmcf->modules->nelts; i++) { | |
499 if (ngx_conf_full_name(cf->cycle, &m[i], 0) != NGX_OK) { | |
500 return NGX_CONF_ERROR; | |
501 } | |
485 } | 502 } |
486 } | 503 } |
487 | 504 |
488 #if !(NGX_HAVE_PERL_MULTIPLICITY) | 505 #if !(NGX_HAVE_PERL_MULTIPLICITY) |
489 | 506 |
539 ngx_http_perl_main_conf_t *pmcf) | 556 ngx_http_perl_main_conf_t *pmcf) |
540 { | 557 { |
541 int n; | 558 int n; |
542 STRLEN len; | 559 STRLEN len; |
543 SV *sv; | 560 SV *sv; |
544 char *ver, *embedding[6]; | 561 char *ver, **embedding; |
562 ngx_str_t *m; | |
563 ngx_uint_t i; | |
545 PerlInterpreter *perl; | 564 PerlInterpreter *perl; |
546 | 565 |
547 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "create perl interpreter"); | 566 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "create perl interpreter"); |
548 | 567 |
549 if (ngx_set_environment(cf->cycle, NULL) == NULL) { | 568 if (ngx_set_environment(cf->cycle, NULL) == NULL) { |
565 | 584 |
566 #ifdef PERL_EXIT_DESTRUCT_END | 585 #ifdef PERL_EXIT_DESTRUCT_END |
567 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; | 586 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
568 #endif | 587 #endif |
569 | 588 |
589 n = (pmcf->modules != NGX_CONF_UNSET_PTR) ? pmcf->modules->nelts * 2 : 0; | |
590 | |
591 embedding = ngx_palloc(cf->pool, (4 + n) * sizeof(char *)); | |
592 if (embedding == NULL) { | |
593 goto fail; | |
594 } | |
595 | |
570 embedding[0] = ""; | 596 embedding[0] = ""; |
571 | 597 |
572 if (pmcf->modules.data) { | 598 if (n++) { |
573 embedding[1] = "-I"; | 599 m = pmcf->modules->elts; |
574 embedding[2] = (char *) pmcf->modules.data; | 600 for (i = 0; i < pmcf->modules->nelts; i++) { |
575 n = 3; | 601 embedding[2 * i + 1] = "-I"; |
576 | 602 embedding[2 * i + 2] = (char *) m[i].data; |
577 } else { | 603 } |
578 n = 1; | |
579 } | 604 } |
580 | 605 |
581 embedding[n++] = "-Mnginx"; | 606 embedding[n++] = "-Mnginx"; |
582 embedding[n++] = "-e"; | 607 embedding[n++] = "-e"; |
583 embedding[n++] = "0"; | 608 embedding[n++] = "0"; |
781 pmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_perl_main_conf_t)); | 806 pmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_perl_main_conf_t)); |
782 if (pmcf == NULL) { | 807 if (pmcf == NULL) { |
783 return NULL; | 808 return NULL; |
784 } | 809 } |
785 | 810 |
811 pmcf->modules = NGX_CONF_UNSET_PTR; | |
786 pmcf->requires = NGX_CONF_UNSET_PTR; | 812 pmcf->requires = NGX_CONF_UNSET_PTR; |
787 | 813 |
788 return pmcf; | 814 return pmcf; |
789 } | 815 } |
790 | 816 |