1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-06 21:26:43 +02:00

Merge pull request #1252 from RGustBardon/rgb/fix-restart-syscalls-master

Fix the property for restarting syscalls (#1251)
This commit is contained in:
Jordi Boggiano
2018-12-11 11:11:47 +01:00
committed by GitHub

View File

@@ -60,29 +60,23 @@ class SignalHandler
return $this;
}
public function handleSignal($signo, array $siginfo = null)
public function handleSignal($signo, array $siginfo = null): void
{
static $signals = [];
if (!$signals && extension_loaded('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)) {
$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);
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')
&& 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_sigprocmask(SIG_UNBLOCK, [$signo], $oldset);
posix_kill(posix_getpid(), $signo);