[mod_cgi] simplify mod_cgi_handle_subrequest()
wait for CGI to close stdout, so we read EOF on pipe to end CGI response remove extra call to waitpid() which will occur after process exits if it has not already been explicitly closed by CGI (and has not been inherited by CGI forked children) (If CGI forks, then it should close its stdout response pipe when response is done, especially if it intends to perform lengthy post-processing in the background.) From: Glenn Strauss <gstrauss@gluelogic.com> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3091 152afb58-edef-0310-8abb-c4023f1b3aa9svn/heads/lighttpd-1.4.x
parent
e5e66f791f
commit
f2cbd0a3aa
1
NEWS
1
NEWS
|
@ -21,6 +21,7 @@ NEWS
|
|||
* [mod_fastcgi] 404 for X-Sendfile file not found (fixes #2474)
|
||||
* [mod_cgi] send 500 if CGI ends and there is no response (fixes #2542)
|
||||
* [mod_cgi] consolidate CGI cleanup code
|
||||
* [mod_cgi] simplify mod_cgi_handle_subrequest()
|
||||
|
||||
- 1.4.39 - 2016-01-02
|
||||
* [core] fix memset_s call (fixes #2698)
|
||||
|
|
|
@ -1338,9 +1338,9 @@ TRIGGER_FUNC(cgi_trigger) {
|
|||
* - HANDLER_WAIT_FOR_EVENT: waiting for response
|
||||
*/
|
||||
SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
|
||||
int status;
|
||||
plugin_data *p = p_d;
|
||||
handler_ctx *hctx = con->plugin_ctx[p->id];
|
||||
UNUSED(srv);
|
||||
|
||||
if (con->mode != p->id) return HANDLER_GO_ON;
|
||||
if (NULL == hctx) return HANDLER_GO_ON;
|
||||
|
@ -1349,42 +1349,8 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
|
|||
log_error_write(srv, __FILE__, __LINE__, "sdd", "subrequest, pid =", hctx, hctx->pid);
|
||||
#endif
|
||||
|
||||
#ifndef __WIN32
|
||||
switch(waitpid(hctx->pid, &status, WNOHANG)) {
|
||||
case 0:
|
||||
return HANDLER_WAIT_FOR_EVENT;
|
||||
|
||||
case -1:
|
||||
if (errno == EINTR) return HANDLER_WAIT_FOR_EVENT;
|
||||
|
||||
hctx->pid = 0;
|
||||
if (errno != ECHILD) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "ss", "waitpid failed: ", strerror(errno));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/* cgi process exited
|
||||
*/
|
||||
|
||||
hctx->pid = 0;
|
||||
|
||||
if (!WIFEXITED(status)) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "s", "cgi died ?");
|
||||
}
|
||||
|
||||
if (cgi_demux_response(srv, hctx) == FDEVENT_HANDLED_ERROR) {
|
||||
log_error_write(srv, __FILE__, __LINE__, "s", "demuxer failed: ");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
cgi_connection_close(srv, hctx);
|
||||
return HANDLER_FINISHED;
|
||||
#else
|
||||
return HANDLER_ERROR;
|
||||
#endif
|
||||
/* if not done, wait for CGI to close stdout, so we read EOF on pipe */
|
||||
return con->file_finished ? HANDLER_FINISHED : HANDLER_WAIT_FOR_EVENT;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue