sandbox: restore old WINCH trap

This commit is contained in:
Bo Anderson 2021-08-25 19:56:12 +01:00
parent 3793fcf097
commit be41b12e4c
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65

View File

@ -97,29 +97,29 @@ class Sandbox
seatbelt.close
@start = Time.now
$stdin.raw! if $stdin.tty?
stdin_thread = T.let(nil, T.nilable(Thread))
begin
command = [SANDBOX_EXEC, "-f", seatbelt.path, *args]
# Start sandbox in a pseudoterminal to prevent access of the parent terminal.
T.unsafe(PTY).spawn(*command) do |r, w, pid|
if $stdout.tty?
w.winsize = $stdout.winsize
trap(:WINCH) { w.winsize = $stdout.winsize }
end
old_winch = trap(:WINCH) { w.winsize = $stdout.winsize if $stdout.tty? }
w.winsize = $stdout.winsize if $stdout.tty?
$stdin.raw! if $stdin.tty?
stdin_thread = Thread.new { IO.copy_stream($stdin, w) }
r.each_char { |c| print(c) }
Process.wait(pid)
ensure
stdin_thread&.kill
$stdin.cooked! if $stdin.tty?
trap(:WINCH, old_winch)
end
raise ErrorDuringExecution.new(command, status: $CHILD_STATUS) unless $CHILD_STATUS.success?
rescue
@failed = true
raise
ensure
stdin_thread&.kill
$stdin.cooked! if $stdin.tty?
seatbelt.unlink
sleep 0.1 # wait for a bit to let syslog catch up the latest events.
syslog_args = [