[Process] Do feat test before enabling TTY mode

This commit is contained in:
Nicolas Grekas 2016-11-21 09:40:36 +01:00
parent e968d0ff5d
commit 69bfbbf8c2
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);
}
/**