bug #20576 [Process] Do feat test before enabling TTY mode (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Process] Do feat test before enabling TTY mode

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20565
| License       | MIT
| Doc PR        | -

Commits
-------

69bfbbf [Process] Do feat test before enabling TTY mode
This commit is contained in:
Fabien Potencier 2016-11-21 15:59:43 -08:00
commit 7047e4d31f
1 changed files with 11 additions and 3 deletions

View File

@ -911,8 +911,16 @@ class Process
if ('\\' === DIRECTORY_SEPARATOR && $tty) {
throw new RuntimeException('TTY mode is not supported on Windows platform.');
}
if ($tty && (!file_exists('/dev/tty') || !is_readable('/dev/tty'))) {
throw new RuntimeException('TTY mode requires /dev/tty to be readable.');
if ($tty) {
static $isTtySupported;
if (null === $isTtySupported) {
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes);
}
if (!$isTtySupported) {
throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
}
}
$this->tty = (bool) $tty;
@ -1214,7 +1222,7 @@ class Process
return $result = false;
}
return $result = (bool) @proc_open('echo 1', array(array('pty'), array('pty'), array('pty')), $pipes);
return $result = (bool) @proc_open('echo 1 >/dev/null', array(array('pty'), array('pty'), array('pty')), $pipes);
}
/**