Clean up socket and filesystem resources separately
This commit is contained in:
parent
16dfe3dd40
commit
f7ded45bc7
@ -3,12 +3,13 @@ require "socket"
|
|||||||
|
|
||||||
module Utils
|
module Utils
|
||||||
def self.safe_fork(&block)
|
def self.safe_fork(&block)
|
||||||
socket_path = "#{Dir.mktmpdir("homebrew", HOMEBREW_TEMP)}/socket"
|
Dir.mktmpdir("homebrew", HOMEBREW_TEMP) do |tmpdir|
|
||||||
server = UNIXServer.new(socket_path)
|
UNIXServer.open("#{tmpdir}/socket") do |server|
|
||||||
ENV["HOMEBREW_ERROR_PIPE"] = socket_path
|
|
||||||
read, write = IO.pipe
|
read, write = IO.pipe
|
||||||
|
|
||||||
pid = fork do
|
pid = fork do
|
||||||
|
ENV["HOMEBREW_ERROR_PIPE"] = server.path
|
||||||
|
|
||||||
begin
|
begin
|
||||||
server.close
|
server.close
|
||||||
read.close
|
read.close
|
||||||
@ -37,8 +38,7 @@ module Utils
|
|||||||
raise Interrupt if $?.exitstatus == 130
|
raise Interrupt if $?.exitstatus == 130
|
||||||
raise "Suspicious failure" unless $?.success?
|
raise "Suspicious failure" unless $?.success?
|
||||||
end
|
end
|
||||||
ensure
|
end
|
||||||
server.close
|
end
|
||||||
FileUtils.rm_r File.dirname(socket_path)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user