-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Fix ConsoleEvents::SIGNAL subscriber dispatch #45333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
8000
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -974,22 +974,31 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI | |
} | ||
} | ||
|
||
if ($command instanceof SignalableCommandInterface && ($this->signalsToDispatchEvent || $command->getSubscribedSignals())) { | ||
if (!$this->signalRegistry) { | ||
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.'); | ||
} | ||
if ($this->signalsToDispatchEvent) { | ||
$commandSignals = $command instanceof SignalableCommandInterface ? $command->getSubscribedSignals() : []; | ||
$dispatchSignals = $this->dispatcher && $this->dispatcher->hasListeners(ConsoleEvents::SIGNAL); | ||
|
||
if (Terminal::hasSttyAvailable()) { | ||
$sttyMode = shell_exec('stty -g'); | ||
if ($commandSignals || $dispatchSignals) { | ||
if (!$this->signalRegistry) { | ||
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.'); | ||
} | ||
|
||
foreach ([\SIGINT, \SIGTERM] as $signal) { | ||
$this->signalRegistry->register($signal, static function () use ($sttyMode) { | ||
shell_exec('stty '.$sttyMode); | ||
}); | ||
if (Terminal::hasSttyAvailable()) { | ||
$sttyMode = shell_exec('stty -g'); | ||
|
||
foreach ([\SIGINT, \SIGTERM] as $signal) { | ||
$this->signalRegistry->register($signal, static function () use ($sttyMode) { | ||
shell_exec('stty '.$sttyMode); | ||
}); | ||
} | ||
} | ||
|
||
foreach ($commandSignals as $signal) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any specific reason why the order of registration of signal handlers have been modified? This caused an issue #48205 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't remember my approach/reason at the time, but the test added in this PR should cover the use-case problem I had. Your fix #48210 is most probably correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks you for reviewing. |
||
$this->signalRegistry->register($signal, [$command, 'handleSignal']); | ||
} | ||
} | ||
|
||
if ($this->dispatcher) { | ||
if ($dispatchSignals) { | ||
foreach ($this->signalsToDispatchEvent as $signal) { | ||
$event = new ConsoleSignalEvent($command, $input, $output, $signal); | ||
|
||
|
@@ -1005,10 +1014,6 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI | |
}); | ||
} | ||
} | ||
|
||
foreach ($command->getSubscribedSignals() as $signal) { | ||
lyrixx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$this->signalRegistry->register($signal, [$command, 'handleSignal']); | ||
} | ||
} | ||
|
||
if (null === $this->dispatcher) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->dispatcher is typed to be a
\Symfony\Contracts\EventDispatcher\EventDispatcherInterface
, buthasListeners
is not part of that contract.This leads to our package breaking with the current branch version (5.4.x-dev in our case), since it does not fulfill the
\Symfony\Component\EventDispatcher\EventDispatcherInterface