Skip to content

Commit dc48e01

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fixed bug #76948 Failed shutdown/reboot or end session in Windows
2 parents 54aa761 + b0547a3 commit dc48e01

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

sapi/cgi/cgi_main.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,10 @@ static php_cgi_globals_struct php_cgi_globals;
230230
#ifdef PHP_WIN32
231231
#define WIN32_MAX_SPAWN_CHILDREN 64
232232
HANDLE kid_cgi_ps[WIN32_MAX_SPAWN_CHILDREN];
233-
int kids;
233+
int kids, cleaning_up = 0;
234234
HANDLE job = NULL;
235235
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = { 0 };
236+
CRITICAL_SECTION cleanup_lock;
236237
#endif
237238

238239
#ifndef HAVE_ATTRIBUTE_WEAK
@@ -1496,6 +1497,10 @@ BOOL WINAPI fastcgi_cleanup(DWORD sig)
14961497
{
14971498
int i = kids;
14981499

1500+
EnterCriticalSection(&cleanup_lock);
1501+
cleaning_up = 1;
1502+
LeaveCriticalSection(&cleanup_lock);
1503+
14991504
while (0 < i--) {
15001505
if (NULL == kid_cgi_ps[i]) {
15011506
continue;
@@ -2180,6 +2185,7 @@ consult the installation file that came with this distribution, or visit \n\
21802185
ZeroMemory(&kid_cgi_ps, sizeof(kid_cgi_ps));
21812186
kids = children < WIN32_MAX_SPAWN_CHILDREN ? children : WIN32_MAX_SPAWN_CHILDREN;
21822187

2188+
InitializeCriticalSection(&cleanup_lock);
21832189
SetConsoleCtrlHandler(fastcgi_cleanup, TRUE);
21842190

21852191
/* kids will inherit the env, don't let them spawn */
@@ -2228,6 +2234,13 @@ consult the installation file that came with this distribution, or visit \n\
22282234
}
22292235

22302236
while (parent) {
2237+
EnterCriticalSection(&cleanup_lock);
2238+
if (cleaning_up) {
2239+
DeleteCriticalSection(&cleanup_lock);
2240+
goto parent_out;
2241+
}
2242+
LeaveCriticalSection(&cleanup_lock);
2243+
22312244
i = kids;
22322245
while (0 < i--) {
22332246
DWORD status;
@@ -2283,6 +2296,8 @@ consult the installation file that came with this distribution, or visit \n\
22832296
/* restore my env */
22842297
SetEnvironmentVariable("PHP_FCGI_CHILDREN", kid_buf);
22852298

2299+
DeleteCriticalSection(&cleanup_lock);
2300+
22862301
goto parent_out;
22872302
} else {
22882303
parent = 0;

0 commit comments

Comments
 (0)