Mercurial > hg > nginx
comparison src/http/modules/perl/ngx_http_perl_module.c @ 1069:e6fc18f1a032
env
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 20 Jan 2007 19:26:48 +0000 |
parents | f88651afad40 |
children | 8288459f15c9 |
comparison
equal
deleted
inserted
replaced
1068:b88395feb707 | 1069:e6fc18f1a032 |
---|---|
42 #endif | 42 #endif |
43 | 43 |
44 static void ngx_http_perl_sleep_handler(ngx_http_request_t *r); | 44 static void ngx_http_perl_sleep_handler(ngx_http_request_t *r); |
45 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf, | 45 static char *ngx_http_perl_init_interpreter(ngx_conf_t *cf, |
46 ngx_http_perl_main_conf_t *pmcf); | 46 ngx_http_perl_main_conf_t *pmcf); |
47 static PerlInterpreter * | 47 static PerlInterpreter *ngx_http_perl_create_interpreter(ngx_conf_t *cf, |
48 ngx_http_perl_create_interpreter(ngx_http_perl_main_conf_t *pmcf, | 48 ngx_http_perl_main_conf_t *pmcf); |
49 ngx_log_t *log); | |
50 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, |
51 ngx_log_t *log); | 50 ngx_log_t *log); |
52 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, |
53 HV *nginx, 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); |
54 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); |
473 | 472 |
474 #endif | 473 #endif |
475 | 474 |
476 PERL_SYS_INIT(&ngx_argc, &ngx_argv); | 475 PERL_SYS_INIT(&ngx_argc, &ngx_argv); |
477 | 476 |
478 pmcf->perl = ngx_http_perl_create_interpreter(pmcf, cf->log); | 477 pmcf->perl = ngx_http_perl_create_interpreter(cf, pmcf); |
479 | 478 |
480 if (pmcf->perl == NULL) { | 479 if (pmcf->perl == NULL) { |
481 PERL_SYS_TERM(); | 480 PERL_SYS_TERM(); |
482 return NGX_CONF_ERROR; | 481 return NGX_CONF_ERROR; |
483 } | 482 } |
498 return NGX_CONF_OK; | 497 return NGX_CONF_OK; |
499 } | 498 } |
500 | 499 |
501 | 500 |
502 static PerlInterpreter * | 501 static PerlInterpreter * |
503 ngx_http_perl_create_interpreter(ngx_http_perl_main_conf_t *pmcf, | 502 ngx_http_perl_create_interpreter(ngx_conf_t *cf, |
504 ngx_log_t *log) | 503 ngx_http_perl_main_conf_t *pmcf) |
505 { | 504 { |
506 int n; | 505 int n; |
507 STRLEN len; | 506 STRLEN len; |
508 SV *sv; | 507 SV *sv; |
509 char *ver, *embedding[6]; | 508 char *ver, *embedding[6]; |
510 PerlInterpreter *perl; | 509 PerlInterpreter *perl; |
511 | 510 |
512 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "create perl interpreter"); | 511 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "create perl interpreter"); |
512 | |
513 if (ngx_set_environment(cf->cycle, NULL) == NULL) { | |
514 return NULL; | |
515 } | |
513 | 516 |
514 perl = perl_alloc(); | 517 perl = perl_alloc(); |
515 if (perl == NULL) { | 518 if (perl == NULL) { |
516 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_alloc() failed"); | 519 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, "perl_alloc() failed"); |
517 return NULL; | 520 return NULL; |
518 } | 521 } |
519 | 522 |
520 { | 523 { |
521 | 524 |
544 embedding[n++] = "0"; | 547 embedding[n++] = "0"; |
545 | 548 |
546 n = perl_parse(perl, ngx_http_perl_xs_init, n, embedding, NULL); | 549 n = perl_parse(perl, ngx_http_perl_xs_init, n, embedding, NULL); |
547 | 550 |
548 if (n != 0) { | 551 if (n != 0) { |
549 ngx_log_error(NGX_LOG_ALERT, log, 0, "perl_parse() failed: %d", n); | 552 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, "perl_parse() failed: %d", n); |
550 goto fail; | 553 goto fail; |
551 } | 554 } |
552 | 555 |
553 sv = get_sv("nginx::VERSION", FALSE); | 556 sv = get_sv("nginx::VERSION", FALSE); |
554 ver = SvPV(sv, len); | 557 ver = SvPV(sv, len); |
555 | 558 |
556 if (ngx_strcmp(ver, NGINX_VERSION) != 0) { | 559 if (ngx_strcmp(ver, NGINX_VERSION) != 0) { |
557 ngx_log_error(NGX_LOG_ALERT, log, 0, | 560 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, |
558 "version " NGINX_VERSION " of nginx.pm is required, " | 561 "version " NGINX_VERSION " of nginx.pm is required, " |
559 "but %s was found", ver); | 562 "but %s was found", ver); |
560 goto fail; | 563 goto fail; |
561 } | 564 } |
562 | 565 |
563 if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, log) != NGX_OK) { | 566 if (ngx_http_perl_run_requires(aTHX_ &pmcf->requires, cf->log) != NGX_OK) { |
564 goto fail; | 567 goto fail; |
565 } | 568 } |
566 | 569 |
567 } | 570 } |
568 | 571 |