Mercurial > hg > nginx
comparison src/http/modules/perl/ngx_http_perl_module.c @ 3173:008a3462e1d0
optimize error handling
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 28 Sep 2009 15:57:28 +0000 |
parents | 6cb238e091a9 |
children | 479fd46cd1c4 |
comparison
equal
deleted
inserted
replaced
3172:314301ce7ca2 | 3173:008a3462e1d0 |
---|---|
621 | 621 |
622 static ngx_int_t | 622 static ngx_int_t |
623 ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, ngx_log_t *log) | 623 ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, ngx_log_t *log) |
624 { | 624 { |
625 char **script; | 625 char **script; |
626 u_char *err; | |
626 STRLEN len; | 627 STRLEN len; |
627 ngx_str_t err; | |
628 ngx_uint_t i; | 628 ngx_uint_t i; |
629 | 629 |
630 script = requires->elts; | 630 script = requires->elts; |
631 for (i = 0; i < requires->nelts; i++) { | 631 for (i = 0; i < requires->nelts; i++) { |
632 | 632 |
633 require_pv(script[i]); | 633 require_pv(script[i]); |
634 | 634 |
635 if (SvTRUE(ERRSV)) { | 635 if (SvTRUE(ERRSV)) { |
636 | 636 |
637 err.data = (u_char *) SvPV(ERRSV, len); | 637 err = (u_char *) SvPV(ERRSV, len); |
638 for (len--; err.data[len] == LF || err.data[len] == CR; len--) { | 638 while (--len && (err[len] == CR || err[len] == LF)) { /* void */ } |
639 /* void */ | |
640 } | |
641 err.len = len + 1; | |
642 | 639 |
643 ngx_log_error(NGX_LOG_EMERG, log, 0, | 640 ngx_log_error(NGX_LOG_EMERG, log, 0, |
644 "require_pv(\"%s\") failed: \"%V\"", script[i], &err); | 641 "require_pv(\"%s\") failed: \"%*s\"", |
642 script[i], len + 1, err); | |
645 | 643 |
646 return NGX_ERROR; | 644 return NGX_ERROR; |
647 } | 645 } |
648 } | 646 } |
649 | 647 |
656 SV **args, ngx_str_t *handler, ngx_str_t *rv) | 654 SV **args, ngx_str_t *handler, ngx_str_t *rv) |
657 { | 655 { |
658 SV *sv; | 656 SV *sv; |
659 int n, status; | 657 int n, status; |
660 char *line; | 658 char *line; |
659 u_char *err; | |
661 STRLEN len, n_a; | 660 STRLEN len, n_a; |
662 ngx_str_t err; | |
663 ngx_uint_t i; | 661 ngx_uint_t i; |
664 ngx_connection_t *c; | 662 ngx_connection_t *c; |
665 | 663 |
666 dSP; | 664 dSP; |
667 | 665 |
718 | 716 |
719 /* check $@ */ | 717 /* check $@ */ |
720 | 718 |
721 if (SvTRUE(ERRSV)) { | 719 if (SvTRUE(ERRSV)) { |
722 | 720 |
723 err.data = (u_char *) SvPV(ERRSV, len); | 721 err = (u_char *) SvPV(ERRSV, len); |
724 for (len--; err.data[len] == LF || err.data[len] == CR; len--) { | 722 while (--len && (err[len] == CR || err[len] == LF)) { /* void */ } |
725 /* void */ | |
726 } | |
727 err.len = len + 1; | |
728 | 723 |
729 ngx_log_error(NGX_LOG_ERR, c->log, 0, | 724 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
730 "call_sv(\"%V\") failed: \"%V\"", handler, &err); | 725 "call_sv(\"%V\") failed: \"%*s\"", handler, len + 1, err); |
731 | 726 |
732 if (rv) { | 727 if (rv) { |
733 return NGX_ERROR; | 728 return NGX_ERROR; |
734 } | 729 } |
735 | 730 |