8000 bug #20576 [Process] Do feat test before enabling TTY mode (nicolas-g… · symfony/symfony@7047e4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 7047e4d

Browse files
committed
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
2 parents 2af58be + 69bfbbf commit 7047e4d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,16 @@ public function setTty($tty)
911911
if ('\\' === DIRECTORY_SEPARATOR && $tty) {
912912
throw new RuntimeException('TTY mode is not supported on Windows platform.');
913913
}
914-
if ($tty && (!file_exists('/dev/tty') || !is_readable('/dev/tty'))) {
915-
throw new RuntimeException('TTY mode requires /dev/tty to be readable.');
914+
if ($tty) {
915+
static $isTtySupported;
916+
917+
if (null === $isTtySupported) {
918+
$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);
919+
}
920+
921+
if (!$isTtySupported) {
922+
throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
923+
}
916924
}
917925

918926
$this->tty = (bool) $tty;
@@ -1214,7 +1222,7 @@ public static function isPtySupported()
12141222
return $result = false;
12151223
}
12161224

1217-
return $result = (bool) @proc_open('echo 1', array(array('pty'), array('pty'), array('pty')), $pipes);
1225+
return $result = (bool) @proc_open('echo 1 >/dev/null', array(array('pty'), array('pty'), array('pty')), $pipes);
12181226
}
12191227

12201228
/**

0 commit comments

Comments
 (0)
0