sandbox: fallback to tput for winsize
This commit is contained in:
parent
008296f6b3
commit
9e42ddb011
@ -101,8 +101,21 @@ class Sandbox
|
||||
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|
|
||||
old_winch = trap(:WINCH) { w.winsize = $stdout.winsize if $stdout.tty? }
|
||||
w.winsize = $stdout.winsize if $stdout.tty?
|
||||
# Set the PTY's window size to match the parent terminal.
|
||||
# Some formula tests are sensitive to the terminal size and fail if this is not set.
|
||||
winch = proc do |_sig|
|
||||
w.winsize = if $stdout.tty?
|
||||
# We can only use IO#winsize if the IO object is a TTY.
|
||||
$stdout.winsize
|
||||
else
|
||||
# Otherwise, default to tput, if available.
|
||||
# This relies on ncurses rather than the system's ioctl.
|
||||
[Utils.popen_read("tput", "lines").to_i, Utils.popen_read("tput", "cols").to_i]
|
||||
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?
|
||||
stdin_thread = Thread.new { IO.copy_stream($stdin, w) }
|
||||
|
||||
@ -34,7 +34,8 @@ describe Sandbox, :needs_macos do
|
||||
it "complains on failure" do
|
||||
ENV["HOMEBREW_VERBOSE"] = "1"
|
||||
|
||||
expect(Utils).to receive(:popen_read).and_return("foo")
|
||||
allow(Utils).to receive(:popen_read).and_call_original
|
||||
allow(Utils).to receive(:popen_read).with("syslog", any_args).and_return("foo")
|
||||
|
||||
expect { sandbox.exec "false" }
|
||||
.to raise_error(ErrorDuringExecution)
|
||||
@ -49,7 +50,8 @@ describe Sandbox, :needs_macos do
|
||||
Mar 17 02:55:06 sandboxd[342]: Python(49765) deny file-write-unlink /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/errors.pyc
|
||||
bar
|
||||
EOS
|
||||
expect(Utils).to receive(:popen_read).and_return(with_bogus_error)
|
||||
allow(Utils).to receive(:popen_read).and_call_original
|
||||
allow(Utils).to receive(:popen_read).with("syslog", any_args).and_return(with_bogus_error)
|
||||
|
||||
expect { sandbox.exec "false" }
|
||||
.to raise_error(ErrorDuringExecution)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user