Skip to content

Commit

Permalink
Handle SIGHUP signal in dontdie (#225)
Browse files Browse the repository at this point in the history
Add a handler for SIGHUP signals in order to intuitive process control.
  • Loading branch information
AuroraYolo authored Nov 16, 2023
1 parent 02faae2 commit 5a1b10b
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions bin/dontdie
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function dontDie(array $command, string $nickname = '', int $maxExecutionTime =
};
$sigintWorker = Coroutine::run($signalProxy, Signal::INT);
$sigtermWorker = Coroutine::run($signalProxy, Signal::TERM);
$sighupWorker = Coroutine::run($signalProxy, Signal::HUP);

$trace('wait for process');
try {
Expand All @@ -118,16 +119,12 @@ function dontDie(array $command, string $nickname = '', int $maxExecutionTime =
$trace('wait for process timeout or canceled');
Signal::kill($status['pid'], Signal::TERM);
}

if ($stderrWorker->isExecuting()) {
$stderrWorker->kill();
}
if ($sigintWorker->isExecuting()) {
$sigintWorker->kill();
}
if ($sigtermWorker->isExecuting()) {
$sigtermWorker->kill();
foreach ([$stderrWorker, $sigintWorker, $sigtermWorker, $sighupWorker] as $worker) {
if ($worker->isExecuting()) {
$worker->kill();
}
}

$trace('wait for process exit');
for ($i = 0; $i < 110; $i++) {
if (!$status['running']) {
Expand Down

0 comments on commit 5a1b10b

Please sign in to comment.