]>
Commit | Line | Data |
---|---|---|
8a71df43 ER |
1 | --- php-4.4.7/sapi/cgi/cgi_main.c 2007-02-16 13:47:20.000000000 +0200 |
2 | +++ php-4.4.7-gracefup/sapi/cgi/cgi_main.c 2007-11-09 17:19:32.722741559 +0200 | |
3 | @@ -105,6 +105,11 @@ | |
4 | */ | |
5 | static int parent = 1; | |
6 | ||
7 | +#if PHP_FASTCGI | |
8 | +/* Socket we are listening on incoming FastCGI connections */ | |
9 | +static int fcgi_fd = 0; | |
10 | +#endif | |
11 | + | |
12 | /** | |
13 | * Process group | |
14 | */ | |
15 | @@ -952,6 +957,22 @@ | |
16 | } | |
17 | #endif | |
18 | ||
19 | +#if PHP_FASTCGI | |
20 | +/** | |
21 | + * Graceful shutdown. Close listening sockets. | |
22 | + */ | |
23 | +void fastcgi_graceful_shutdown(int signal) | |
24 | +{ | |
25 | +#ifdef DEBUG_FASTCGI | |
26 | + fprintf(stderr, "FastCGI graceful shutdown, pid %d\n", getpid()); | |
27 | +#endif | |
28 | + | |
29 | + /* Close the listening socket so new processes can reuse the same port */ | |
30 | + closesocket(fcgi_fd); | |
31 | + fcgi_fd = 0; | |
32 | +} | |
33 | +#endif | |
34 | + | |
35 | /* {{{ main | |
36 | */ | |
37 | int main(int argc, char *argv[]) | |
38 | @@ -990,7 +1011,6 @@ | |
39 | #ifndef PHP_WIN32 | |
40 | char *bindpath = NULL; | |
41 | #endif | |
42 | - int fcgi_fd = 0; | |
43 | FCGX_Request request; | |
44 | #ifdef PHP_WIN32 | |
45 | long impersonate = 0; | |
46 | @@ -1238,9 +1258,17 @@ | |
47 | parent = 0; | |
48 | ||
49 | /* don't catch our signals */ | |
50 | - sigaction( SIGTERM, &old_term, 0 ); | |
51 | sigaction( SIGQUIT, &old_quit, 0 ); | |
52 | sigaction( SIGINT, &old_int, 0 ); | |
53 | +#if PHP_FASTCGI | |
54 | + | |
55 | + /* call graceful shutdown handler for SIGTERM */ | |
56 | + act.sa_flags = 0; | |
57 | + act.sa_handler = fastcgi_graceful_shutdown; | |
58 | + sigaction(SIGTERM, &act, &old_term); | |
59 | +#else | |
60 | + sigaction(SIGTERM, &old_term, 0); | |
61 | +#endif | |
62 | break; | |
63 | case -1: | |
64 | perror( "php (pre-forking)" ); |