File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -1392,6 +1392,7 @@ void pcntl_signal_dispatch(void)
13921392
13931393 queue = PCNTL_G (head );
13941394 PCNTL_G (head ) = NULL ; /* simple stores are atomic */
1395+ PCNTL_G (tail ) = NULL ;
13951396
13961397 /* Allocate */
13971398 while (queue ) {
@@ -1411,6 +1412,9 @@ void pcntl_signal_dispatch(void)
14111412#ifdef HAVE_STRUCT_SIGINFO_T
14121413 zval_ptr_dtor (& params [1 ]);
14131414#endif
1415+ if (EG (exception )) {
1416+ break ;
1417+ }
14141418 }
14151419 }
14161420
@@ -1420,6 +1424,14 @@ void pcntl_signal_dispatch(void)
14201424 queue = next ;
14211425 }
14221426
1427+ /* drain the remaining in case of exception thrown */
1428+ while (queue ) {
1429+ next = queue -> next ;
1430+ queue -> next = PCNTL_G (spares );
1431+ PCNTL_G (spares ) = queue ;
1432+ queue = next ;
1433+ }
1434+
14231435 PCNTL_G (pending_signals ) = false;
14241436
14251437 /* Re-enable queue */
Original file line number Diff line number Diff line change 1+ --TEST--
2+ pcntl_signal_dispatch() stops dispatching after handler throws exception
3+ --EXTENSIONS--
4+ pcntl
5+ posix
6+ --FILE--
7+ <?php
8+
9+ $ called = [];
10+
11+ pcntl_signal (SIGUSR1 , function ($ signo ) use (&$ called ) {
12+ $ called [] = 'SIGUSR1 ' ;
13+ throw new \Exception ('Exception in signal handler ' );
14+ });
15+
16+ pcntl_signal (SIGUSR2 , function ($ signo ) use (&$ called ) {
17+ $ called [] = 'SIGUSR2 ' ;
18+ });
19+
20+ posix_kill (posix_getpid (), SIGUSR1 );
21+ posix_kill (posix_getpid (), SIGUSR2 );
22+
23+ try {
24+ pcntl_signal_dispatch ();
25+ } catch (\Exception $ e ) {
26+ echo $ e ->getMessage () . "\n" ;
27+ }
28+
29+ echo "Handlers called: " . implode (', ' , $ called ) . "\n" ;
30+
31+ ?>
32+ --EXPECT--
33+ Exception in signal handler
34+ Handlers called: SIGUSR1
You can’t perform that action at this time.
0 commit comments