Merge pull request #11990 from sullivan-sean/sandbox-pty-fix

Restore original TTY state after Sandbox
This commit is contained in:
Mike McQuaid 2021-09-08 12:57:21 +01:00 committed by GitHub
commit 4b68787740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,20 +113,31 @@ class Sandbox
[Utils.popen_read("tput", "lines").to_i, Utils.popen_read("tput", "cols").to_i] [Utils.popen_read("tput", "lines").to_i, Utils.popen_read("tput", "cols").to_i]
end end
end end
# Update the window size whenever the parent terminal's window size changes.
old_winch = trap(:WINCH, &winch)
winch.call(nil)
$stdin.raw! if $stdin.tty? write_to_pty = proc do
stdin_thread = Thread.new { IO.copy_stream($stdin, w) } # Update the window size whenever the parent terminal's window size changes.
old_winch = trap(:WINCH, &winch)
winch.call(nil)
r.each_char { |c| print(c) } stdin_thread = Thread.new { IO.copy_stream($stdin, w) }
Process.wait(pid) r.each_char { |c| print(c) }
ensure
stdin_thread&.kill Process.wait(pid)
$stdin.cooked! if $stdin.tty? ensure
trap(:WINCH, old_winch) stdin_thread&.kill
trap(:WINCH, old_winch)
end
if $stdin.tty?
# If stdin is a TTY, use io.raw to set stdin to a raw, passthrough
# mode while we copy the input/output of the process spawned in the
# PTY. After we've finished copying to/from the PTY process, io.raw
# will restore the stdin TTY to its original state.
$stdin.raw(&write_to_pty)
else
write_to_pty.call
end
end end
raise ErrorDuringExecution.new(command, status: $CHILD_STATUS) unless $CHILD_STATUS.success? raise ErrorDuringExecution.new(command, status: $CHILD_STATUS) unless $CHILD_STATUS.success?
rescue rescue