From d4c691e91e8d2b807cd281556cbe7a52882652be Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Tue, 24 Aug 2021 15:09:25 +0100 Subject: [PATCH] sandbox: check if stdin/out is associated with a tty --- Library/Homebrew/sandbox.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb index c69a47d2bc..571d540fe7 100644 --- a/Library/Homebrew/sandbox.rb +++ b/Library/Homebrew/sandbox.rb @@ -97,15 +97,17 @@ class Sandbox seatbelt.close @start = Time.now - $stdin.raw! + $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| - w.winsize = $stdout.winsize - trap(:WINCH) { w.winsize = $stdout.winsize } + if $stdout.tty? + w.winsize = $stdout.winsize + trap(:WINCH) { w.winsize = $stdout.winsize } + end stdin_thread = Thread.new { IO.copy_stream($stdin, w) } r.each_char { |c| print(c) } Process.wait(pid) @@ -116,7 +118,7 @@ class Sandbox raise ensure stdin_thread&.kill - $stdin.cooked! + $stdin.cooked! if $stdin.tty? seatbelt.unlink sleep 0.1 # wait for a bit to let syslog catch up the latest events.