|
@@ -60,29 +60,23 @@ class SignalHandler
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function handleSignal($signo, array $siginfo = null)
|
|
|
|
|
|
|
+ public function handleSignal($signo, array $siginfo = null): void
|
|
|
{
|
|
{
|
|
|
static $signals = [];
|
|
static $signals = [];
|
|
|
|
|
|
|
|
if (!$signals && extension_loaded('pcntl')) {
|
|
if (!$signals && extension_loaded('pcntl')) {
|
|
|
$pcntl = new ReflectionExtension('pcntl');
|
|
$pcntl = new ReflectionExtension('pcntl');
|
|
|
- $constants = $pcntl->getConstants();
|
|
|
|
|
- if (!$constants) {
|
|
|
|
|
- // HHVM 3.24.2 returns an empty array.
|
|
|
|
|
- $constants = get_defined_constants(true);
|
|
|
|
|
- $constants = $constants['Core'];
|
|
|
|
|
- }
|
|
|
|
|
- foreach ($constants as $name => $value) {
|
|
|
|
|
|
|
+ // HHVM 3.24.2 returns an empty array.
|
|
|
|
|
+ foreach ($pcntl->getConstants() ?: get_defined_constants(true)['Core'] as $name => $value) {
|
|
|
if (substr($name, 0, 3) === 'SIG' && $name[3] !== '_' && is_int($value)) {
|
|
if (substr($name, 0, 3) === 'SIG' && $name[3] !== '_' && is_int($value)) {
|
|
|
$signals[$value] = $name;
|
|
$signals[$value] = $name;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- unset($constants);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $level = isset($this->signalLevelMap[$signo]) ? $this->signalLevelMap[$signo] : LogLevel::CRITICAL;
|
|
|
|
|
- $signal = isset($signals[$signo]) ? $signals[$signo] : $signo;
|
|
|
|
|
- $context = isset($siginfo) ? $siginfo : [];
|
|
|
|
|
|
|
+ $level = $this->signalLevelMap[$signo] ?? LogLevel::CRITICAL;
|
|
|
|
|
+ $signal = $signals[$signo] ?? $signo;
|
|
|
|
|
+ $context = $siginfo ?? [];
|
|
|
$this->logger->log($level, sprintf('Program received signal %s', $signal), $context);
|
|
$this->logger->log($level, sprintf('Program received signal %s', $signal), $context);
|
|
|
|
|
|
|
|
if (!isset($this->previousSignalHandler[$signo])) {
|
|
if (!isset($this->previousSignalHandler[$signo])) {
|
|
@@ -93,7 +87,7 @@ class SignalHandler
|
|
|
if (extension_loaded('pcntl') && function_exists('pcntl_signal') && function_exists('pcntl_sigprocmask') && function_exists('pcntl_signal_dispatch')
|
|
if (extension_loaded('pcntl') && function_exists('pcntl_signal') && function_exists('pcntl_sigprocmask') && function_exists('pcntl_signal_dispatch')
|
|
|
&& extension_loaded('posix') && function_exists('posix_getpid') && function_exists('posix_kill')
|
|
&& extension_loaded('posix') && function_exists('posix_getpid') && function_exists('posix_kill')
|
|
|
) {
|
|
) {
|
|
|
- $restartSyscalls = isset($this->restartSyscalls[$signo]) ? $this->restartSyscalls[$signo] : true;
|
|
|
|
|
|
|
+ $restartSyscalls = $this->signalRestartSyscalls[$signo] ?? true;
|
|
|
pcntl_signal($signo, SIG_DFL, $restartSyscalls);
|
|
pcntl_signal($signo, SIG_DFL, $restartSyscalls);
|
|
|
pcntl_sigprocmask(SIG_UNBLOCK, [$signo], $oldset);
|
|
pcntl_sigprocmask(SIG_UNBLOCK, [$signo], $oldset);
|
|
|
posix_kill(posix_getpid(), $signo);
|
|
posix_kill(posix_getpid(), $signo);
|