From d9fe48cf543b7d1594dd491b27ab578acf237186 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Tue, 8 May 2012 21:40:55 -0500 Subject: [PATCH] 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 --- Library/Homebrew/build.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index ab1a44e6e7..f72633ffac 100755 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -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']