Skip to content
Snippets Groups Projects
Commit d1617e86 authored by Xu Cheng's avatar Xu Cheng
Browse files

sandbox postinstall


Closes Homebrew/homebrew#38479.

Signed-off-by: default avatarXu Cheng <xucheng@me.com>
parent b621edf8
No related branches found
No related tags found
No related merge requests found
require "sandbox"
module Homebrew
def postinstall
ARGV.formulae.each { |f| f.run_post_install }
ARGV.formulae.each { |f| run_post_install(f) }
end
def run_post_install(formula)
args = %W[
nice #{RUBY_PATH}
-W0
-I #{HOMEBREW_LIBRARY_PATH}
--
#{HOMEBREW_LIBRARY_PATH}/postinstall.rb
#{formula.path}
].concat(ARGV.options_only)
Utils.safe_fork do
if Sandbox.available? && ARGV.sandbox?
sandbox = Sandbox.new
sandbox.allow_write_temp_and_cache
sandbox.allow_write_log(formula)
sandbox.allow_write_cellar(formula)
sandbox.allow_write_path HOMEBREW_PREFIX
sandbox.deny_write_path HOMEBREW_LIBRARY
sandbox.deny_write_path HOMEBREW_REPOSITORY/".git"
sandbox.deny_write HOMEBREW_BREW_FILE
sandbox.exec(*args)
else
exec(*args)
end
end
end
end
......@@ -9,6 +9,7 @@ require 'cleaner'
require 'formula_cellar_checks'
require 'install_renamed'
require 'cmd/tap'
require 'cmd/postinstall'
require 'hooks/bottles'
require 'debrew'
require 'sandbox'
......@@ -586,7 +587,7 @@ class FormulaInstaller
end
def post_install
formula.run_post_install
Homebrew.run_post_install(formula)
rescue Exception => e
opoo "The post-install step did not complete successfully"
puts "You can try again using `brew postinstall #{formula.name}`"
......
old_trap = trap("INT") { exit! 130 }
require "global"
require "debrew"
require "fcntl"
require "socket"
begin
error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
trap("INT", old_trap)
formula = ARGV.formulae.first
formula.extend(Debrew::Formula) if ARGV.debug?
formula.run_post_install
rescue Exception => e
Marshal.dump(e, error_pipe)
error_pipe.close
exit! 1
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment