auto disable sandbox for interactive shell

Closes Homebrew/homebrew#38792.

Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
Xu Cheng 2015-07-21 14:47:37 +08:00
parent 895983fed5
commit 8cebb64eec
4 changed files with 27 additions and 3 deletions

View File

@ -15,8 +15,12 @@ module Homebrew
#{formula.path}
].concat(ARGV.options_only)
if Sandbox.available? && ARGV.sandbox? && Sandbox.auto_disable?
Sandbox.print_autodisable_warning
end
Utils.safe_fork do
if Sandbox.available? && ARGV.sandbox?
if Sandbox.available? && ARGV.sandbox? && !Sandbox.auto_disable?
sandbox = Sandbox.new
formula.logs.mkpath
sandbox.record_log(formula.logs/"sandbox.postinstall.log")

View File

@ -35,8 +35,12 @@ module Homebrew
#{f.path}
].concat(ARGV.options_only)
if Sandbox.available? && ARGV.sandbox? && Sandbox.auto_disable?
Sandbox.print_autodisable_warning
end
Utils.safe_fork do
if Sandbox.available? && ARGV.sandbox?
if Sandbox.available? && ARGV.sandbox? && !Sandbox.auto_disable?
sandbox = Sandbox.new
f.logs.mkpath
sandbox.record_log(f.logs/"sandbox.test.log")

View File

@ -486,8 +486,12 @@ class FormulaInstaller
#{formula.path}
].concat(build_argv)
if Sandbox.available? && ARGV.sandbox? && Sandbox.auto_disable?
Sandbox.print_autodisable_warning
end
Utils.safe_fork do
if Sandbox.available? && ARGV.sandbox?
if Sandbox.available? && ARGV.sandbox? && !Sandbox.auto_disable?
sandbox = Sandbox.new
formula.logs.mkpath
sandbox.record_log(formula.logs/"sandbox.build.log")

View File

@ -8,6 +8,18 @@ class Sandbox
OS.mac? && File.executable?(SANDBOX_EXEC)
end
# there are times the sandbox cannot be used.
def self.auto_disable?
@auto_disable ||= ARGV.interactive? || ARGV.debug?
end
def self.print_autodisable_warning
unless @print_autodisable_warning
opoo "The sandbox cannot be used in debug or interactive mode."
@print_autodisable_warning = true
end
end
def initialize
@profile = SandboxProfile.new
end