8000 [Process] Add workaround for PHP's internal sigchild failing to retur… · symfony/symfony@7b63428 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b63428

Browse files
committed
[Process] Add workaround for PHP's internal sigchild failing to return proper exit codes
1 parent 2c0e851 commit 7b63428

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Process
3939
private $timeout;
4040
private $options;
4141
private $exitcode;
42+
private $fallbackExitcode;
4243
private $processInformation;
4344
private $stdout;
4445
private $stderr;
@@ -211,7 +212,13 @@ public function start($callback = null)
211212
);
212213
$descriptors = array(array('pipe', 'r'), $this->fileHandles[self::STDOUT], array('pipe', 'w'));
213214
} else {
214-
$descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));
215+
$descriptors = array(
216+
array('pipe', 'r'), // stdin
217+
array('pipe', 'w'), // stdout
218+
array('pipe', 'w'), // stderr
219+
array('pipe', 'w') // last exit code is output on the fourth pipe and caught to work around --enable-sigchild
220+
);
221+
$this->commandline = '('.$this->commandline.') 3>/dev/null; echo $? >&3';
215222
}
216223

217224
$commandline = $this->commandline;
@@ -336,8 +343,14 @@ public function wait($callback = null)
336343
foreach ($r as $pipe) {
337344
$type = array_search($pipe, $this->pipes);
338345
$data = fread($pipe, 8192);
346+
339347
if (strlen($data) > 0) {
340-
call_user_func($callback, $type == 1 ? self::OUT : self::ERR, $data);
348+
// last exit code is output and caught to work around --enable-sigchild
349+
if (3 == $type) {
350+
$this->fallbackExitcode = (int) $data;
351+
} else {
352+
call_user_func($callback, $type == 1 ? self::OUT : self::ERR, $data);
353+
}
341354
}
342355
if (false === $data || feof($pipe)) {
343356
fclose($pipe);
@@ -363,7 +376,13 @@ public function wait($callback = null)
363376
throw new \RuntimeException(sprintf('The process stopped because of a "%s" signal.', $this->processInformation['stopsig']));
364377
}
365378

366-
return $this->exitcode = $this->processInformation['running'] ? $exitcode : $this->processInformation['exitcode'];
379+
$this->exitcode = $this->processInformation['running'] ? $exitcode : $this->processInformation['exitcode'];
380+
381+
if (-1 == $this->exitcode && null !== $this->fallbackExitcode) {
382+
$this->exitcode = $this->fallbackExitcode;
383+
}
384+
385+
return $this->exitcode;
367386
}
368387

369388
/**
< 3281 div class="d-flex flex-column gap-2 pt-3 react-comments-container Comment-module__commit-discussion-comments--WaMOe" id="comments">

0 commit comments

Comments
 (0)
0