@@ -226,9 +226,10 @@ static php_cgi_globals_struct php_cgi_globals;
226
226
#ifdef PHP_WIN32
227
227
#define WIN32_MAX_SPAWN_CHILDREN 64
228
228
HANDLE kid_cgi_ps [WIN32_MAX_SPAWN_CHILDREN ];
229
- int kids ;
229
+ int kids , cleaning_up = 0 ;
230
230
HANDLE job = NULL ;
231
231
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = { 0 };
232
+ CRITICAL_SECTION cleanup_lock ;
232
233
#endif
233
234
234
235
#ifndef HAVE_ATTRIBUTE_WEAK
@@ -1492,6 +1493,10 @@ BOOL WINAPI fastcgi_cleanup(DWORD sig)
1492
1493
{
1493
1494
int i = kids ;
1494
1495
1496
+ EnterCriticalSection (& cleanup_lock );
1497
+ cleaning_up = 1 ;
1498
+ LeaveCriticalSection (& cleanup_lock );
1499
+
1495
1500
while (0 < i -- ) {
1496
1501
if (NULL == kid_cgi_ps [i ]) {
1497
1502
continue ;
@@ -2186,6 +2191,7 @@ consult the installation file that came with this distribution, or visit \n\
2186
2191
ZeroMemory (& kid_cgi_ps , sizeof (kid_cgi_ps ));
2187
2192
kids = children < WIN32_MAX_SPAWN_CHILDREN ? children : WIN32_MAX_SPAWN_CHILDREN ;
2188
2193
2194
+ InitializeCriticalSection (& cleanup_lock );
2189
2195
SetConsoleCtrlHandler (fastcgi_cleanup , TRUE);
2190
2196
2191
2197
/* 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\
2234
2240
}
2235
2241
2236
2242
while (parent ) {
2243
+ EnterCriticalSection (& cleanup_lock );
2244
+ if (cleaning_up ) {
2245
+ DeleteCriticalSection (& cleanup_lock );
2246
+ goto parent_out ;
2247
+ }
2248
+ LeaveCriticalSection (& cleanup_lock );
2249
+
2237
2250
i = kids ;
2238
2251
while (0 < i -- ) {
2239
2252
DWORD status ;
@@ -2289,6 +2302,8 @@ consult the installation file that came with this distribution, or visit \n\
2289
2302
/* restore my env */
2290
2303
SetEnvironmentVariable ("PHP_FCGI_CHILDREN" , kid_buf );
2291
2304
2305
+ DeleteCriticalSection (& cleanup_lock );
2306
+
2292
2307
goto parent_out ;
2293
2308
} else {
2294
2309
parent = 0 ;
0 commit comments