Skip to content

Commit 46bc094

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fixed bug #76948 Failed shutdown/reboot or end session in Windows
2 parents 9f3ea20 + dc48e01 commit 46bc094

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

sapi/cgi/cgi_main.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,10 @@ static php_cgi_globals_struct php_cgi_globals;
228228
#ifdef PHP_WIN32
229229
#define WIN32_MAX_SPAWN_CHILDREN 64
230230
HANDLE kid_cgi_ps[WIN32_MAX_SPAWN_CHILDREN];
231-
int kids;
231+
int kids, cleaning_up = 0;
232232
HANDLE job = NULL;
233233
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = { 0 };
234+
CRITICAL_SECTION cleanup_lock;
234235
#endif
235236

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

1497+
EnterCriticalSection(&cleanup_lock);
1498+
cleaning_up = 1;
1499+
LeaveCriticalSection(&cleanup_lock);
1500+
14961501
while (0 < i--) {
14971502
if (NULL == kid_cgi_ps[i]) {
14981503
continue;
@@ -2129,8 +2134,9 @@ consult the installation file that came with this distribution, or visit \n\
21292134
int i;
21302135

21312136
ZeroMemory(&kid_cgi_ps, sizeof(kid_cgi_ps));
2132-
kids = children < WIN32_MAX_SPAWN_CHILDREN ? children : WIN32_MAX_SPAWN_CHILDREN;
2133-
2137+
kids = children < WIN32_MAX_SPAWN_CHILDREN ? children : WIN32_MAX_SPAWN_CHILDREN;
2138+
2139+
InitializeCriticalSection(&cleanup_lock);
21342140
SetConsoleCtrlHandler(fastcgi_cleanup, TRUE);
21352141

21362142
/* kids will inherit the env, don't let them spawn */
@@ -2179,6 +2185,13 @@ consult the installation file that came with this distribution, or visit \n\
21792185
}
21802186

21812187
while (parent) {
2188+
EnterCriticalSection(&cleanup_lock);
2189+
if (cleaning_up) {
2190+
DeleteCriticalSection(&cleanup_lock);
2191+
goto parent_out;
2192+
}
2193+
LeaveCriticalSection(&cleanup_lock);
2194+
21822195
i = kids;
21832196
while (0 < i--) {
21842197
DWORD status;
@@ -2234,6 +2247,8 @@ consult the installation file that came with this distribution, or visit \n\
22342247
/* restore my env */
22352248
SetEnvironmentVariable("PHP_FCGI_CHILDREN", kid_buf);
22362249

2250+
DeleteCriticalSection(&cleanup_lock);
2251+
22372252
goto parent_out;
22382253
} else {
22392254
parent = 0;

0 commit comments

Comments
 (0)