Skip to content

Commit b0547a3

Browse files
committed
Fixed bug #76948 Failed shutdown/reboot or end session in Windows
1 parent 945f315 commit b0547a3

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
@@ -226,9 +226,10 @@ static php_cgi_globals_struct php_cgi_globals;
226226
#ifdef PHP_WIN32
227227
#define WIN32_MAX_SPAWN_CHILDREN 64
228228
HANDLE kid_cgi_ps[WIN32_MAX_SPAWN_CHILDREN];
229-
int kids;
229+
int kids, cleaning_up = 0;
230230
HANDLE job = NULL;
231231
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = { 0 };
232+
CRITICAL_SECTION cleanup_lock;
232233
#endif
233234

234235
#ifndef HAVE_ATTRIBUTE_WEAK
@@ -1492,6 +1493,10 @@ BOOL WINAPI fastcgi_cleanup(DWORD sig)
14921493
{
14931494
int i = kids;
14941495

1496+
EnterCriticalSection(&cleanup_lock);
1497+
cleaning_up = 1;
1498+
LeaveCriticalSection(&cleanup_lock);
1499+
14951500
while (0 < i--) {
14961501
if (NULL == kid_cgi_ps[i]) {
14971502
continue;
@@ -2186,6 +2191,7 @@ consult the installation file that came with this distribution, or visit \n\
21862191
ZeroMemory(&kid_cgi_ps, sizeof(kid_cgi_ps));
21872192
kids = children < WIN32_MAX_SPAWN_CHILDREN ? children : WIN32_MAX_SPAWN_CHILDREN;
21882193

2194+
InitializeCriticalSection(&cleanup_lock);
21892195
SetConsoleCtrlHandler(fastcgi_cleanup, TRUE);
21902196

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

22362242
while (parent) {
2243+
EnterCriticalSection(&cleanup_lock);
2244+
if (cleaning_up) {
2245+
DeleteCriticalSection(&cleanup_lock);
2246+
goto parent_out;
2247+
}
2248+
LeaveCriticalSection(&cleanup_lock);
2249+
22372250
i = kids;
22382251
while (0 < i--) {
22392252
DWORD status;
@@ -2289,6 +2302,8 @@ consult the installation file that came with this distribution, or visit \n\
22892302
/* restore my env */
22902303
SetEnvironmentVariable("PHP_FCGI_CHILDREN", kid_buf);
22912304

2305+
DeleteCriticalSection(&cleanup_lock);
2306+
22922307
goto parent_out;
22932308
} else {
22942309
parent = 0;

0 commit comments

Comments
 (0)