Skip to content

Commit bcc596a

Browse files
committed
[Console] Don't register signal handlers if pcntl is disabled
1 parent 5d5ff78 commit bcc596a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Application.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Console\Exception\ExceptionInterface;
2525
use Symfony\Component\Console\Exception\LogicException;
2626
use Symfony\Component\Console\Exception\NamespaceNotFoundException;
27+
use Symfony\Component\Console\Exception\RuntimeException;
2728
use Symfony\Component\Console\Formatter\OutputFormatter;
2829
use Symfony\Component\Console\Helper\DebugFormatterHelper;
2930
use Symfony\Component\Console\Helper\FormatterHelper;
@@ -88,8 +89,8 @@ public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN
8889
$this->version = $version;
8990
$this->terminal = new Terminal();
9091
$this->defaultCommand = 'list';
91-
$this->signalRegistry = new SignalRegistry();
92-
if (\defined('SIGINT')) {
92+
if (\defined('SIGINT') && SignalRegistry::isSupported()) {
93+
$this->signalRegistry = new SignalRegistry();
9394
$this->signalsToDispatchEvent = [\SIGINT, \SIGTERM, \SIGUSR1, \SIGUSR2];
9495
}
9596
}
@@ -953,6 +954,9 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
953954
}
954955

955956
if ($command instanceof SignalableCommandInterface) {
957+
if (!$this->signalsToDispatchEvent) {
958+
throw new RuntimeException('Unable to subscribe to signal events. Make sure that the `pcntl` extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.');
959+
}
956960
foreach ($command->getSubscribedSignals() as $signal) {
957961
$this->signalRegistry->register($signal, [$command, 'handleSignal']);
958962
}

SignalRegistry/SignalRegistry.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ public function register(int $signal, callable $signalHandler): void
3737
pcntl_signal($signal, [$this, 'handle']);
3838
}
3939

40+
public static function isSupported(): bool
41+
{
42+
if (!\function_exists('pcntl_signal')) {
43+
return false;
44+
}
45+
46+
if (\in_array('pcntl_signal', explode(',', ini_get('disable_functions')))) {
47+
return false;
48+
}
49+
50+
return true;
51+
}
52+
4053
/**
4154
* @internal
4255
*/

0 commit comments

Comments
 (0)