dmitry          Tue Jul 15 13:10:07 2008 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src    NEWS 
    /php-src/sapi/cgi   cgi_main.c fastcgi.c 
  Log:
  Fixed bug #45423 (fastcgi parent process doesn't invoke php_module_shutdown 
before shutdown) (basant dot kukreja at sun dot com)
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.1171&r2=1.2027.2.547.2.1172&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.1171 php-src/NEWS:1.2027.2.547.2.1172
--- php-src/NEWS:1.2027.2.547.2.1171    Sat Jul 12 21:14:57 2008
+++ php-src/NEWS        Tue Jul 15 13:10:07 2008
@@ -13,6 +13,8 @@
   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).
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.267.2.15.2.56&r2=1.267.2.15.2.57&diff_format=u
Index: php-src/sapi/cgi/cgi_main.c
diff -u php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.56 
php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.57
--- php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.56 Wed Apr  9 09:16:40 2008
+++ php-src/sapi/cgi/cgi_main.c Tue Jul 15 13:10:07 2008
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: cgi_main.c,v 1.267.2.15.2.56 2008/04/09 09:16:40 dmitry Exp $ */
+/* $Id: cgi_main.c,v 1.267.2.15.2.57 2008/07/15 13:10:07 dmitry Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -103,6 +103,12 @@
  */
 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 @@
 }
 /* }}} */
 
-#if PHP_FASTCGI
+#if PHP_FASTCGI && !defined(PHP_WIN32)
 /**
  * Clean up child processes upon exit
  */
@@ -1145,15 +1151,16 @@
        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 @@
                }
 
                if (fcgi_in_shutdown()) {
-                       exit(0);
+                       goto parent_out;
                }
 
                while (parent) {
@@ -1557,9 +1564,25 @@
 #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 @@
        }
 #endif
 
+#ifndef PHP_WIN32
+parent_out:
+#endif
+
        SG(server_context) = NULL;
        php_module_shutdown(TSRMLS_C);
        sapi_shutdown();
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.c?r1=1.4.2.13.2.30&r2=1.4.2.13.2.31&diff_format=u
Index: php-src/sapi/cgi/fastcgi.c
diff -u php-src/sapi/cgi/fastcgi.c:1.4.2.13.2.30 
php-src/sapi/cgi/fastcgi.c:1.4.2.13.2.31
--- php-src/sapi/cgi/fastcgi.c:1.4.2.13.2.30    Thu Apr  3 10:24:44 2008
+++ php-src/sapi/cgi/fastcgi.c  Tue Jul 15 13:10:07 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: fastcgi.c,v 1.4.2.13.2.30 2008/04/03 10:24:44 dmitry Exp $ */
+/* $Id: fastcgi.c,v 1.4.2.13.2.31 2008/07/15 13:10:07 dmitry Exp $ */
 
 #include "php.h"
 #include "fastcgi.h"
@@ -170,6 +170,20 @@
        }
 }
 
+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 @@
                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 @@
        if (tcp) {
                listen_socket = _open_osfhandle((long)listen_socket, 0);
        }
+#else
+       fcgi_setup_signals();
 #endif
        return listen_socket;
 }



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to