1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 09:02:59 +00:00

Capture signals and wait until child process exits to also exit, fixes #6059

This commit is contained in:
Jordi Boggiano 2022-07-20 22:08:44 +02:00
parent 1a4f2174e4
commit 07645b9895
No known key found for this signature in database
GPG key ID: 7BBD42C429EC80BC
3 changed files with 33 additions and 7 deletions

View file

@ -17,6 +17,7 @@ use Composer\Util\Filesystem;
use Composer\Util\Platform;
use Composer\Util\Silencer;
use LogicException;
use Seld\Signal\SignalHandler;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\Console\Helper\HelperSet;
@ -93,7 +94,15 @@ class Application extends BaseApplication
date_default_timezone_set(Silencer::call('date_default_timezone_get'));
}
$this->io = new NullIO();
if (!$shutdownRegistered) {
$signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) {
$this->io->writeError('Received '.$signal.', aborting', true, IOInterface::DEBUG);
$handler->exitWithLastSignal();
});
$shutdownRegistered = true;
register_shutdown_function(static function (): void {
@ -107,8 +116,6 @@ class Application extends BaseApplication
});
}
$this->io = new NullIO();
$this->initialWorkingDirectory = getcwd();
parent::__construct('Composer', Composer::getVersion());