sandbox: start sandbox in a pseudoterminal
This commit is contained in:
parent
a1e34bdd10
commit
0f900edfa2
@ -2,6 +2,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "erb"
|
||||
require "io/console"
|
||||
require "pty"
|
||||
require "tempfile"
|
||||
|
||||
# Helper class for running a sub-process inside of a sandboxed environment.
|
||||
@ -95,12 +97,26 @@ class Sandbox
|
||||
seatbelt.close
|
||||
@start = Time.now
|
||||
|
||||
$stdin.raw!
|
||||
stdin_thread = T.let(nil, T.nilable(Thread))
|
||||
|
||||
begin
|
||||
T.unsafe(self).safe_system SANDBOX_EXEC, "-f", seatbelt.path, *args
|
||||
command = [SANDBOX_EXEC, "-f", seatbelt.path, *args]
|
||||
T.unsafe(PTY).spawn(*command) do |r, w, pid|
|
||||
w.winsize = $stdout.winsize
|
||||
trap(:WINCH) { w.winsize = $stdout.winsize }
|
||||
stdin_thread = Thread.new { IO.copy_stream($stdin, w) }
|
||||
r.each_char { |c| print(c) }
|
||||
Process.wait(pid)
|
||||
end
|
||||
raise ErrorDuringExecution.new(command, status: $CHILD_STATUS) unless $CHILD_STATUS.success?
|
||||
rescue
|
||||
@failed = true
|
||||
raise
|
||||
ensure
|
||||
stdin_thread&.kill
|
||||
$stdin.cooked!
|
||||
|
||||
seatbelt.unlink
|
||||
sleep 0.1 # wait for a bit to let syslog catch up the latest events.
|
||||
syslog_args = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user