mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-21 22:32:41 +01:00
When "arc" receives SIGWINCH or other signals during display of a prompt, recover
Summary: Ref T13546. Resizing the terminal window to send SIGWINCH, or other signals, may interrupt "stream_select()" with an error which upgrades to a RuntimeException. When "stream_select()" fails, continue and test the stream itself. Test Plan: Waited for a prompt, resized the window. Before patch: SIGWINCH interruption. After patch: undisturbed prompt. Maniphest Tasks: T13546 Differential Revision: https://secure.phabricator.com/D21317
This commit is contained in:
parent
0da395ffe4
commit
3ed81d35a2
1 changed files with 23 additions and 3 deletions
|
@ -113,12 +113,32 @@ final class ArcanistPrompt
|
|||
$write = array();
|
||||
$except = array();
|
||||
|
||||
$ok = stream_select($read, $write, $except, 1);
|
||||
$ok = @stream_select($read, $write, $except, 1);
|
||||
if ($ok === false) {
|
||||
throw new Exception(pht('stream_select() failed!'));
|
||||
// NOTE: We may be interrupted by a system call, particularly if
|
||||
// the window is resized while a prompt is shown and the terminal
|
||||
// sends SIGWINCH.
|
||||
|
||||
// If we are, just continue below and try to read from stdin. If
|
||||
// we were interrupted, we should read nothing and continue
|
||||
// normally. If the pipe is broken, the read should fail.
|
||||
}
|
||||
|
||||
$response = '';
|
||||
while (true) {
|
||||
$bytes = fread($stdin, 8192);
|
||||
if ($bytes === false) {
|
||||
throw new Exception(
|
||||
pht('fread() from stdin failed with an error.'));
|
||||
}
|
||||
|
||||
if (!strlen($bytes)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$response .= $bytes;
|
||||
}
|
||||
|
||||
$response = fgets($stdin);
|
||||
if (!strlen($response)) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue