Set close-on-exec on the error pipe

We use a pipe to marshal exceptions from the build script back to the
main Homebrew process; the associated file descriptor is stored in an
environment variable so that the script can figure out which descriptor
to use after being exec'd.

However, any child processes of the build script inherit this
descriptor (i.e. anything spawned via "system" by the formula during
installation). Normally this is not an issue, but if a formula executes
a long-running process such as a daemon, the main Homebrew process will
never see EOF on the error pipe because the daemon still has an open
descriptor.

We can fix this while preserving current behavior by setting the
close-on-exec flag on the build script's error pipe descriptor.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
Jack Nagel 2012-05-08 21:40:55 -05:00
parent 01bcf58e6a
commit d9fe48cf54

View File

@ -32,6 +32,11 @@ at_exit do
# can be inconvenient for the user. But we need to be safe.
system "/usr/bin/sudo -k"
if ENV['HOMEBREW_ERROR_PIPE']
require 'fcntl'
IO.new(ENV['HOMEBREW_ERROR_PIPE'].to_i, 'w').fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
end
install(Formula.factory($0))
rescue Exception => e
if ENV['HOMEBREW_ERROR_PIPE']