Skip to content

Commit bbdb09c

Browse files
authored
Handle negative process exit code (#171)
1 parent 8b35686 commit bbdb09c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Process/SymfonyProcessLauncher.php

+22
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,29 @@ private function freeProcess(int $index, Process $process): int
196196

197197
unset($this->runningProcesses[$index]);
198198

199+
return self::getExitCode($process);
200+
}
201+
202+
/**
203+
* @return 0|positive-int
204+
*/
205+
private static function getExitCode(Process $process): int
206+
{
199207
$exitCode = $process->getExitCode();
208+
209+
// @codeCoverageIgnoreStart
210+
if (null !== $exitCode && $exitCode < 0) {
211+
// A negative exit code indicates the process has been terminated by
212+
// a signal.
213+
// Technically it is incorrect to change the exit code sign here.
214+
// However, since we sum up the exit codes here we have no choice but
215+
// to do so as otherwise we could cancel out an exit code. For example
216+
// a child process that has -1 and the other one 1 the result would
217+
// be 0 for the main process exit code which would be incorrect.
218+
return -$exitCode;
219+
}
220+
// @codeCoverageIgnoreEnd
221+
200222
Assert::natural($exitCode, 'Expected the process to be finished and return a valid exit code.');
201223

202224
return $exitCode;

0 commit comments

Comments
 (0)