From cb71104f58115fc5d794808ad874428f72543efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederic=20G=2E=20=C3=98stby?= Date: Sat, 26 Oct 2024 23:10:46 +0200 Subject: [PATCH] Ensure propper cleanup if the parent process of a spinner is terminated --- src/mako/application/cli/Application.php | 6 +++--- src/mako/cli/output/helpers/Spinner.php | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mako/application/cli/Application.php b/src/mako/application/cli/Application.php index 9d0038116..edf429ad7 100644 --- a/src/mako/application/cli/Application.php +++ b/src/mako/application/cli/Application.php @@ -158,14 +158,14 @@ protected function startReactor(): void // Ensure that the cursor and stty are restored in case of a SIGINT call if ($signalHandler->canHandleSignals()) { - $signalHandler->addHandler(SIGINT, function ($signal, $isLast) use ($output): void { + $signalHandler->addHandler([SIGINT, SIGTERM], function ($signal, $isLast) use ($output): void { $output->getCursor()->restore(); $output->getEnvironment()->restoreStty(); - // If we're the last handler then we exit with status code 130 (SIGINT) + // If we're the last handler then we exit with status code 130 (SIGINT) or 143 (SIGTERM) if ($isLast) { - exit(130); + exit(128 + $signal); } }); } diff --git a/src/mako/cli/output/helpers/Spinner.php b/src/mako/cli/output/helpers/Spinner.php index f5d0430d0..c0aa953cb 100644 --- a/src/mako/cli/output/helpers/Spinner.php +++ b/src/mako/cli/output/helpers/Spinner.php @@ -73,6 +73,10 @@ protected function spinner(string $message, string $template): void if (posix_kill(posix_getpid(), 0) === false) { break; } + + if (posix_getppid() === 1) { + posix_kill(posix_getpid(), SIGKILL); + } } }