Fixed bug #36158 (SIGTERM is not handled correctly when running as a FastCGI server)

This commit is contained in:
Dmitry Stogov 2006-02-03 16:30:09 +00:00
parent 52232a7f7a
commit aa1142eded
3 changed files with 14 additions and 4 deletions

2
NEWS
View file

@ -33,6 +33,8 @@ PHP NEWS
- Fixed bug #36185 (str_rot13() crash on non-string parameter). (Pierre) - Fixed bug #36185 (str_rot13() crash on non-string parameter). (Pierre)
- Fixed bug #36176 (PDO_PGSQL - PDO::exec() does not return number of rows - Fixed bug #36176 (PDO_PGSQL - PDO::exec() does not return number of rows
affected by the operation). (Ilia) affected by the operation). (Ilia)
- Fixed bug #36158 (SIGTERM is not handled correctly when running as a FastCGI
server). (Dmitry)
- Fixed bug #36152 (problems with curl+ssl and pgsql+ssl in same PHP). (Mike) - Fixed bug #36152 (problems with curl+ssl and pgsql+ssl in same PHP). (Mike)
- Fixed bug #36148 (unpack("H*hex", $data) is adding an extra character to the - Fixed bug #36148 (unpack("H*hex", $data) is adding an extra character to the
end of the string). (Ilia) end of the string). (Ilia)

View file

@ -274,7 +274,7 @@ static void sapi_cgibin_flush(void *server_context)
#ifndef PHP_WIN32 #ifndef PHP_WIN32
!parent && !parent &&
#endif #endif
(!request || FCGX_FFlush(request->out) == -1)) { request && FCGX_FFlush(request->out) == -1) {
php_handle_aborted_connection(); php_handle_aborted_connection();
} }
return; return;
@ -1242,7 +1242,8 @@ consult the installation file that came with this distribution, or visit \n\
#ifdef DEBUG_FASTCGI #ifdef DEBUG_FASTCGI
fprintf(stderr, "Wait for kids, pid %d\n", getpid()); fprintf(stderr, "Wait for kids, pid %d\n", getpid());
#endif #endif
wait(&status); while (wait(&status) < 0) {
}
running--; running--;
} }
} }
@ -1656,6 +1657,7 @@ fastcgi_request_done:
exit_status = 255; exit_status = 255;
} zend_end_try(); } zend_end_try();
SG(server_context) = NULL;
php_module_shutdown(TSRMLS_C); php_module_shutdown(TSRMLS_C);
sapi_shutdown(); sapi_shutdown();

View file

@ -157,7 +157,7 @@ static DWORD WINAPI fcgi_shutdown_thread(LPVOID arg)
static void fcgi_signal_handler(int signo) static void fcgi_signal_handler(int signo)
{ {
if (signo == SIGUSR1) { if (signo == SIGUSR1 || signo == SIGTERM) {
in_shutdown = 1; in_shutdown = 1;
} }
} }
@ -217,6 +217,7 @@ int fcgi_init(void)
new_sa.sa_flags = 0; new_sa.sa_flags = 0;
new_sa.sa_handler = fcgi_signal_handler; new_sa.sa_handler = fcgi_signal_handler;
sigaction(SIGUSR1, &new_sa, NULL); sigaction(SIGUSR1, &new_sa, NULL);
sigaction(SIGTERM, &new_sa, NULL);
sigaction(SIGPIPE, NULL, &old_sa); sigaction(SIGPIPE, NULL, &old_sa);
if (old_sa.sa_handler == SIG_DFL) { if (old_sa.sa_handler == SIG_DFL) {
sigaction(SIGPIPE, &new_sa, NULL); sigaction(SIGPIPE, &new_sa, NULL);
@ -627,6 +628,9 @@ int fcgi_accept_request(fcgi_request *req)
while (1) { while (1) {
if (req->fd < 0) { if (req->fd < 0) {
while (1) { while (1) {
if (in_shutdown) {
return -1;
}
#ifdef _WIN32 #ifdef _WIN32
HANDLE pipe = (HANDLE)_get_osfhandle(req->listen_socket); HANDLE pipe = (HANDLE)_get_osfhandle(req->listen_socket);
OVERLAPPED ov; OVERLAPPED ov;
@ -663,7 +667,7 @@ int fcgi_accept_request(fcgi_request *req)
FCGI_UNLOCK(req->listen_socket); FCGI_UNLOCK(req->listen_socket);
#endif #endif
if (in_shutdown || (req->fd < 0 && errno != EINTR)) { if (req->fd < 0 && (in_shutdown || errno != EINTR)) {
return -1; return -1;
} }
@ -686,6 +690,8 @@ try_again:
} }
#endif #endif
} }
} else if (in_shutdown) {
return -1;
} }
if (fcgi_read_request(req)) { if (fcgi_read_request(req)) {
return req->fd; return req->fd;