summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2008-07-15 13:10:07 +0000
committerDmitry Stogov <dmitry@php.net>2008-07-15 13:10:07 +0000
commit51619fa391e05f1ce6199dece5170a8d2d9a9cea (patch)
tree643d588021b3e619eba46fccf88e8df456a6b483
parent0bccc60ec2db01de1b9ca4a9fcdd051bd4975939 (diff)
downloadphp-git-51619fa391e05f1ce6199dece5170a8d2d9a9cea.tar.gz
Fixed bug #45423 (fastcgi parent process doesn't invoke php_module_shutdown before shutdown) (basant dot kukreja at sun dot com)
-rw-r--r--NEWS2
-rw-r--r--sapi/cgi/cgi_main.c43
-rw-r--r--sapi/cgi/fastcgi.c29
3 files changed, 54 insertions, 20 deletions
diff --git a/NEWS b/NEWS
index cce2c9eebd..8c54470b0d 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ PHP NEWS
accept lengths of 1024). (Felipe, andrew at lifescale dot com)
- Fixed bug #45449 (filesize() regression using ftp wrapper).
(crrodriguez at suse dot de)
+- Fixed bug #45423 (fastcgi parent process doesn't invoke php_module_shutdown
+ before shutdown) (basant dot kukreja at sun dot com)
- Fixed bug #45352 (Segmentation fault because of tick function on second
request). (Dmitry)
- Fixed bug #45312 (Segmentation fault on second request for array functions).
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index a584dab515..a7abf09823 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -103,6 +103,12 @@ static int children = 0;
*/
static int parent = 1;
+/* Did parent received exit signals SIG_TERM/SIG_INT/SIG_QUIT */
+static int exit_signal = 0;
+
+/* Is Parent waiting for children to exit */
+static int parent_waiting = 0;
+
/**
* Process group
*/
@@ -1135,7 +1141,7 @@ static void init_request_info(TSRMLS_D)
}
/* }}} */
-#if PHP_FASTCGI
+#if PHP_FASTCGI && !defined(PHP_WIN32)
/**
* Clean up child processes upon exit
*/
@@ -1145,15 +1151,16 @@ void fastcgi_cleanup(int signal)
fprintf(stderr, "FastCGI shutdown, pid %d\n", getpid());
#endif
-#ifndef PHP_WIN32
sigaction(SIGTERM, &old_term, 0);
/* Kill all the processes in our process group */
kill(-pgroup, SIGTERM);
-#endif
- /* We should exit at this point, but MacOSX doesn't seem to */
- exit(0);
+ if (parent && parent_waiting) {
+ exit_signal = 1;
+ } else {
+ exit(0);
+ }
}
#endif
@@ -1520,7 +1527,7 @@ consult the installation file that came with this distribution, or visit \n\
}
if (fcgi_in_shutdown()) {
- exit(0);
+ goto parent_out;
}
while (parent) {
@@ -1557,9 +1564,25 @@ consult the installation file that came with this distribution, or visit \n\
#ifdef DEBUG_FASTCGI
fprintf(stderr, "Wait for kids, pid %d\n", getpid());
#endif
- while (wait(&status) < 0) {
+ parent_waiting = 1;
+ while (1) {
+ if (wait(&status) >= 0) {
+ running--;
+ break;
+ } else if (exit_signal) {
+ break;
+ }
+ }
+ if (exit_signal) {
+#if 0
+ while (running > 0) {
+ while (wait(&status) < 0) {
+ }
+ running--;
+ }
+#endif
+ goto parent_out;
}
- running--;
}
}
} else {
@@ -2061,6 +2084,10 @@ out:
}
#endif
+#ifndef PHP_WIN32
+parent_out:
+#endif
+
SG(server_context) = NULL;
php_module_shutdown(TSRMLS_C);
sapi_shutdown();
diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c
index cb51c81e50..6ea334449d 100644
--- a/sapi/cgi/fastcgi.c
+++ b/sapi/cgi/fastcgi.c
@@ -170,6 +170,20 @@ static void fcgi_signal_handler(int signo)
}
}
+static void fcgi_setup_signals(void)
+{
+ struct sigaction new_sa, old_sa;
+
+ sigemptyset(&new_sa.sa_mask);
+ new_sa.sa_flags = 0;
+ new_sa.sa_handler = fcgi_signal_handler;
+ sigaction(SIGUSR1, &new_sa, NULL);
+ sigaction(SIGTERM, &new_sa, NULL);
+ sigaction(SIGPIPE, NULL, &old_sa);
+ if (old_sa.sa_handler == SIG_DFL) {
+ sigaction(SIGPIPE, &new_sa, NULL);
+ }
+}
#endif
int fcgi_in_shutdown(void)
@@ -224,18 +238,7 @@ int fcgi_init(void)
is_initialized = 1;
errno = 0;
if (getpeername(0, (struct sockaddr *)&sa, &len) != 0 && errno == ENOTCONN) {
- struct sigaction new_sa, old_sa;
-
- sigemptyset(&new_sa.sa_mask);
- new_sa.sa_flags = 0;
- new_sa.sa_handler = fcgi_signal_handler;
- sigaction(SIGUSR1, &new_sa, NULL);
- sigaction(SIGTERM, &new_sa, NULL);
- sigaction(SIGPIPE, NULL, &old_sa);
- if (old_sa.sa_handler == SIG_DFL) {
- sigaction(SIGPIPE, &new_sa, NULL);
- }
-
+ fcgi_setup_signals();
return is_fastcgi = 1;
} else {
return is_fastcgi = 0;
@@ -501,6 +504,8 @@ int fcgi_listen(const char *path, int backlog)
if (tcp) {
listen_socket = _open_osfhandle((long)listen_socket, 0);
}
+#else
+ fcgi_setup_signals();
#endif
return listen_socket;
}