mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/pcntl: fix pcntl_signal_dispatch() stale tail pointer and exception handling.
This commit is contained in:
@@ -1392,6 +1392,7 @@ void pcntl_signal_dispatch(void)
|
||||
|
||||
queue = PCNTL_G(head);
|
||||
PCNTL_G(head) = NULL; /* simple stores are atomic */
|
||||
PCNTL_G(tail) = NULL;
|
||||
|
||||
/* Allocate */
|
||||
while (queue) {
|
||||
@@ -1411,6 +1412,9 @@ void pcntl_signal_dispatch(void)
|
||||
#ifdef HAVE_STRUCT_SIGINFO_T
|
||||
zval_ptr_dtor(¶ms[1]);
|
||||
#endif
|
||||
if (EG(exception)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1420,6 +1424,14 @@ void pcntl_signal_dispatch(void)
|
||||
queue = next;
|
||||
}
|
||||
|
||||
/* drain the remaining in case of exception thrown */
|
||||
while (queue) {
|
||||
next = queue->next;
|
||||
queue->next = PCNTL_G(spares);
|
||||
PCNTL_G(spares) = queue;
|
||||
queue = next;
|
||||
}
|
||||
|
||||
PCNTL_G(pending_signals) = false;
|
||||
|
||||
/* Re-enable queue */
|
||||
|
||||
34
ext/pcntl/tests/pcntl_signal_dispatch_exception.phpt
Normal file
34
ext/pcntl/tests/pcntl_signal_dispatch_exception.phpt
Normal file
@@ -0,0 +1,34 @@
|
||||
--TEST--
|
||||
pcntl_signal_dispatch() stops dispatching after handler throws exception
|
||||
--EXTENSIONS--
|
||||
pcntl
|
||||
posix
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$called = [];
|
||||
|
||||
pcntl_signal(SIGUSR1, function ($signo) use (&$called) {
|
||||
$called[] = 'SIGUSR1';
|
||||
throw new \Exception('Exception in signal handler');
|
||||
});
|
||||
|
||||
pcntl_signal(SIGUSR2, function ($signo) use (&$called) {
|
||||
$called[] = 'SIGUSR2';
|
||||
});
|
||||
|
||||
posix_kill(posix_getpid(), SIGUSR1);
|
||||
posix_kill(posix_getpid(), SIGUSR2);
|
||||
|
||||
try {
|
||||
pcntl_signal_dispatch();
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
echo "Handlers called: " . implode(', ', $called) . "\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Exception in signal handler
|
||||
Handlers called: SIGUSR1
|
||||
Reference in New Issue
Block a user