Don't use Kernel.system much

It just seems to behave strangely with SIGINT. Eg. SIGINT causes tar to exit, but the SIGINT is ignored by our process. This is not the case when used with curl.
This commit is contained in:
Max Howell 2009-11-09 17:44:29 +00:00
parent 590f64e302
commit 1da26d89ea
3 changed files with 31 additions and 11 deletions

View File

@ -60,7 +60,7 @@ class FormulaInstaller
exit! 1 exit! 1
end end
end end
ignore_interrupts do ignore_interrupts do # because child proc will get it and marshall it back
write.close write.close
Process.wait Process.wait
data = read.read data = read.read

View File

@ -30,6 +30,24 @@ MACOS_VERSION=10.6
Dir.chdir HOMEBREW_PREFIX Dir.chdir HOMEBREW_PREFIX
at_exit { HOMEBREW_PREFIX.parent.rmtree } at_exit { HOMEBREW_PREFIX.parent.rmtree }
# for some reason our utils.rb safe_system behaves completely differently
# during these tests. This is worrying for sure.
def safe_system *args
Kernel.system *args
end
class ExecutionError <RuntimeError
attr :status
def initialize cmd, args=[], status=nil
super "Failure while executing: #{cmd} #{args*' '}"
@status = status
end
end
class BuildError <ExecutionError
end
require 'test/unit' # must be after at_exit require 'test/unit' # must be after at_exit
require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
ARGV.extend(HomebrewArgvExtension) ARGV.extend(HomebrewArgvExtension)

View File

@ -69,27 +69,29 @@ def pretty_duration s
end end
def interactive_shell def interactive_shell
pid=fork fork do
if pid.nil?
# TODO make the PS1 var change pls # TODO make the PS1 var change pls
#brown="\[\033[0;33m\]" #brown="\[\033[0;33m\]"
#reset="\[\033[0m\]" #reset="\[\033[0m\]"
#ENV['PS1']="Homebrew-#{HOMEBREW_VERSION} #{brown}\W#{reset}\$ " #ENV['PS1']="Homebrew-#{HOMEBREW_VERSION} #{brown}\W#{reset}\$ "
exec ENV['SHELL'] exec ENV['SHELL']
end end
Process.wait pid Process.wait
raise SystemExit, "Aborting due to non-zero exit status" if $? != 0 unless $?.success?
puts "Aborting due to non-zero exit status"
exit $?
end
end end
# Kernel.system but with exceptions # Kernel.system but with exceptions
def safe_system cmd, *args def safe_system cmd, *args
puts "#{cmd} #{args*' '}" if ARGV.verbose? puts "#{cmd} #{args*' '}" if ARGV.verbose?
exec_success = Kernel.system cmd, *args fork do
# some tools, eg. tar seem to confuse ruby and it doesn't propogate the trap("EXIT") {} # no bt on exit from this short-lived fork
# CTRL-C interrupt to us too, so execution continues, but the exit code is exit! 1 unless exec(cmd, *args)
# still 2 so we raise our own interrupt end
raise Interrupt, cmd if $?.termsig == 2 Process.wait
raise ExecutionError.new(cmd, args, $?) unless exec_success raise ExecutionError.new(cmd, args, $?) unless $?.success?
end end
def curl *args def curl *args