Skip to content

Commit

Permalink
[Process] Fix the fix for --enable-sigchild php
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Dec 23, 2015
1 parent 5517368 commit 088fcfe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
33 changes: 5 additions & 28 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -65,14 +65,6 @@ class Process
private $latestSignal;

private static $sigchild;
private static $posixSignals = array(
1, // SIGHUP
2, // SIGINT
3, // SIGQUIT
6, // SIGABRT
14, // SIGALRM
15, // SIGTERM
);

/**
* Exit codes translation table.
Expand Down Expand Up @@ -246,14 +238,9 @@ public function start($callback = null)
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
$descriptors[3] = array('pipe', 'w');

$commandline = '';
foreach (self::$posixSignals as $s) {
$commandline .= "trap 'echo s$s >&3' $s;";
}

// See https://unix.stackexchange.com/questions/71205/background-process-pipe-input
$commandline .= '{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
$commandline .= 'pid=$!; echo $pid >&3; wait $pid; code=$?; echo x$code >&3; exit $code';
$commandline = '{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
$commandline .= 'pid=$!; echo $pid >&3; wait $pid; code=$?; echo $code >&3; exit $code';

// Workaround for the bug, when PTS functionality is enabled.
// @see : https://bugs.php.net/69442
Expand Down Expand Up @@ -1086,19 +1073,9 @@ private function readPipes($blocking, $close)
$callback = $this->callback;
foreach ($result as $type => $data) {
if (3 === $type) {
foreach (explode("\n", substr($data, 0, -1)) as $data) {
if ('p' === $data[0]) {
$this->fallbackStatus['pid'] = (int) substr($data, 1);
} elseif ('s' === $data[0]) {
$this->fallbackStatus['signaled'] = true;
$this->fallbackStatus['exitcode'] = -1;
$this->fallbackStatus['termsig'] = (int) substr($data, 1);
} elseif ('x' === $data[0]) {
$this->fallbackStatus['running'] = false;
if (!isset($this->fallbackStatus['signaled'])) {
$this->fallbackStatus['exitcode'] = (int) substr($data, 1);
}
}
$this->fallbackStatus['running'] = false;
if (!isset($this->fallbackStatus['signaled'])) {
$this->fallbackStatus['exitcode'] = (int) $data;
}
} else {
$callback($type === self::STDOUT ? self::OUT : self::ERR, $data);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/Tests/ProcessTest.php
Expand Up @@ -689,7 +689,7 @@ public function testRunProcessWithTimeout()

if ('\\' !== DIRECTORY_SEPARATOR) {
// On Windows, timers are too transient
$maxDuration = $timeout + Process::TIMEOUT_PRECISION;
$maxDuration = $timeout + 2 * Process::TIMEOUT_PRECISION;
$this->assertLessThan($maxDuration, $duration);
}

Expand Down

0 comments on commit 088fcfe

Please sign in to comment.