From 7682eec52a3ee27e46ceda43976baf77031a53d7 Mon Sep 17 00:00:00 2001 From: "roberto@natty32" Date: Sun, 1 May 2011 16:42:01 +0200 Subject: [PATCH] do not die on perl die() :P --- plugins/psgi/psgi_plugin.c | 8 +++++--- plugins/psgi/psgi_response.c | 11 +++++++++-- plugins/python/wsgi_handlers.c | 6 +++--- utils.c | 10 +++++----- uwsgi.h | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/plugins/psgi/psgi_plugin.c b/plugins/psgi/psgi_plugin.c index 019f6436..8d60b000 100644 --- a/plugins/psgi/psgi_plugin.c +++ b/plugins/psgi/psgi_plugin.c @@ -382,7 +382,7 @@ int uwsgi_perl_request(struct wsgi_request *wsgi_req) { SV *pi = SvREFCNT_inc(POPs); if (!hv_store(env, "psgi.input", 10, pi, 0)) goto clear; - if (!hv_store(env, "psgix.io", 8, pi, 0)) goto clear; + if (!hv_store(env, "psgix.io", 8, SvREFCNT_inc(pi), 0)) goto clear; if (!hv_store(env, "psgix.input.buffered", 20, &PL_sv_no, 0)) goto clear; @@ -413,10 +413,11 @@ int uwsgi_perl_request(struct wsgi_request *wsgi_req) { PUTBACK; - perl_call_sv(psgi_func, G_SCALAR); + perl_call_sv(psgi_func, G_SCALAR | G_EVAL); if(SvTRUE(ERRSV)) { + internal_server_error(wsgi_req, "exception raised"); uwsgi_log("%s\n", SvPV_nolen(ERRSV)); goto clear; } @@ -434,9 +435,10 @@ int uwsgi_perl_request(struct wsgi_request *wsgi_req) { XPUSHs( newRV((SV*) uperl.stream_responder)); PUTBACK; - perl_call_sv( (SV*)response, G_SCALAR); + perl_call_sv( (SV*)response, G_SCALAR | G_EVAL); if(SvTRUE(ERRSV)) { + internal_server_error(wsgi_req, "exception raised"); uwsgi_log("%s\n", SvPV_nolen(ERRSV)); } diff --git a/plugins/psgi/psgi_response.c b/plugins/psgi/psgi_response.c index 9be3860a..609d76bb 100644 --- a/plugins/psgi/psgi_response.c +++ b/plugins/psgi/psgi_response.c @@ -132,16 +132,17 @@ int psgi_response(struct wsgi_request *wsgi_req, PerlInterpreter *my_perl, AV *r return 1; } - if (SvTYPE(SvRV(*hitem)) == SVt_PVGV || SvTYPE(SvRV(*hitem)) == SVt_PVHV) { + if (SvTYPE(SvRV(*hitem)) == SVt_PVGV || SvTYPE(SvRV(*hitem)) == SVt_PVHV || SvTYPE(SvRV(*hitem)) == SVt_PVMG) { for(;;) { PUSHMARK(SP); XPUSHs(*hitem); PUTBACK; - perl_call_method("getline", G_SCALAR); + perl_call_method("getline", G_SCALAR | G_EVAL); SPAGAIN; if(SvTRUE(ERRSV)) { + internal_server_error(wsgi_req, "exception raised"); uwsgi_log("%s\n", SvPV_nolen(ERRSV)); break; } @@ -154,6 +155,12 @@ int psgi_response(struct wsgi_request *wsgi_req, PerlInterpreter *my_perl, AV *r wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, chitem, hlen); } + PUSHMARK(SP); + XPUSHs(*hitem); + PUTBACK; + perl_call_method("close", G_SCALAR | G_EVAL); + SPAGAIN; + } else if (SvTYPE(SvRV(*hitem)) == SVt_PVAV) { diff --git a/plugins/python/wsgi_handlers.c b/plugins/python/wsgi_handlers.c index 8dc7477e..9ab21023 100644 --- a/plugins/python/wsgi_handlers.c +++ b/plugins/python/wsgi_handlers.c @@ -339,7 +339,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { wsgi_req->app_id = uwsgi.default_app; } else { - internal_server_error(wsgi_req->poll.fd, "wsgi application not found"); + internal_server_error(wsgi_req, "wsgi application not found"); goto clear2; } @@ -361,14 +361,14 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { if (wsgi_req->protocol_len < 5) { uwsgi_log( "INVALID PROTOCOL: %.*s\n", wsgi_req->protocol_len, wsgi_req->protocol); - internal_server_error(wsgi_req->poll.fd, "invalid HTTP protocol !!!"); + internal_server_error(wsgi_req, "invalid HTTP protocol !!!"); goto clear; } if (strncmp(wsgi_req->protocol, "HTTP/", 5)) { uwsgi_log( "INVALID PROTOCOL: %.*s\n", wsgi_req->protocol_len, wsgi_req->protocol); - internal_server_error(wsgi_req->poll.fd, "invalid HTTP protocol !!!"); + internal_server_error(wsgi_req, "invalid HTTP protocol !!!"); goto clear; } diff --git a/utils.c b/utils.c index 4713a7a2..8f081d91 100644 --- a/utils.c +++ b/utils.c @@ -281,17 +281,17 @@ char *uwsgi_get_cwd() { } -void internal_server_error(int fd, char *message) { +void internal_server_error(struct wsgi_request *wsgi_req, char *message) { if (uwsgi.shared->options[UWSGI_OPTION_CGI_MODE] == 0) { - uwsgi.wsgi_req->headers_size = write(fd, "HTTP/1.1 500 Internal Server Error\r\nContent-type: text/html\r\n\r\n", 63); + uwsgi.wsgi_req->headers_size = wsgi_req->socket->proto_write_header(wsgi_req, "HTTP/1.1 500 Internal Server Error\r\nContent-type: text/html\r\n\r\n", 63); } else { - uwsgi.wsgi_req->headers_size = write(fd, "Status: 500 Internal Server Error\r\nContent-type: text/html\r\n\r\n", 62); + uwsgi.wsgi_req->headers_size = wsgi_req->socket->proto_write_header(wsgi_req, "Status: 500 Internal Server Error\r\nContent-type: text/html\r\n\r\n", 62); } uwsgi.wsgi_req->header_cnt = 2; - uwsgi.wsgi_req->response_size = write(fd, "

uWSGI Error

", 20); - uwsgi.wsgi_req->response_size += write(fd, message, strlen(message)); + uwsgi.wsgi_req->response_size = wsgi_req->socket->proto_write(wsgi_req, "

uWSGI Error

", 20); + uwsgi.wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, message, strlen(message)); } void uwsgi_as_root() { diff --git a/uwsgi.h b/uwsgi.h index 221f4ae4..696e2070 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1405,7 +1405,7 @@ void stats(int); void uwsgi_xml_config(char *, struct wsgi_request *, int, char *[]); #endif -void internal_server_error(int, char *); +void internal_server_error(struct wsgi_request *, char *); #ifdef UWSGI_SNMP void manage_snmp(int, uint8_t *, int, struct sockaddr_in *);