1 --- php5.3-200711071330/sapi/cgi/cgi_main.c 2007-11-01 13:32:38.000000000 +0200
2 +++ php5.3-200711071330-graceful/sapi/cgi/cgi_main.c 2007-11-07 17:40:37.884171760 +0200
7 +/* Socket we are listening on incoming connections */
8 +static int fcgi_fd = -1;
14 static char *php_optarg = NULL;
15 static int php_optind = 1;
16 static zend_module_entry cgi_module_entry;
17 +static int accept_socket = -1;
19 static const opt_struct OPTIONS[] = {
20 {'a', 0, "interactive"},
21 @@ -1211,16 +1215,38 @@
25 - sigaction(SIGTERM, &old_term, 0);
27 /* Kill all the processes in our process group */
28 - kill(-pgroup, SIGTERM);
29 + if (signal == SIGINT) {
30 + sigaction(SIGTERM, &old_int, 0);
31 + kill(-pgroup, SIGINT);
33 + sigaction(SIGTERM, &old_term, 0);
34 + kill(-pgroup, SIGTERM);
38 /* We should exit at this point, but MacOSX doesn't seem to */
43 + * Graceful shutdown. Close listening sockets.
45 +void fastcgi_graceful_shutdown(int signal)
48 + fprintf(stderr, "FastCGI graceful shutdown, pid %d\n", getpid());
51 + /* This will make FCGI shutdown itself later in the loop, however we should finish our request cleanly */
54 + /* Whoever we also close the listeing socket (which PHP itself doesn't seem to do?!) */
55 + closesocket(fcgi_fd);
61 STD_PHP_INI_ENTRY("cgi.rfc2616_headers", "0", PHP_INI_ALL, OnUpdateBool, rfc2616_headers, php_cgi_globals_struct, php_cgi_globals)
62 STD_PHP_INI_ENTRY("cgi.nph", "0", PHP_INI_ALL, OnUpdateBool, nph, php_cgi_globals_struct, php_cgi_globals)
65 int fastcgi = fcgi_is_fastcgi();
66 char *bindpath = NULL;
71 @@ -1581,7 +1606,10 @@
72 /* don't catch our signals */
73 sigaction(SIGTERM, &old_term, 0);
74 sigaction(SIGQUIT, &old_quit, 0);
75 - sigaction(SIGINT, &old_int, 0);
76 + /* handler for SIGINT */
78 + act.sa_handler = fastcgi_graceful_shutdown;
79 + sigaction(SIGINT, &act, &old_int);
82 perror("php (pre-forking)");