aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-01-06 23:41:44 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-01-07 00:11:18 +0000
commiteacc541e4b81f5f50b19fb1a32266d760f4cf783 (patch)
tree7d17355d590f99c03099136214434ddbedb30b6d
parent1d7fa3dd097834ee102a741b245b669cb3387661 (diff)
downloadpaludis-eacc541e4b81f5f50b19fb1a32266d760f4cf783.tar.gz
paludis-eacc541e4b81f5f50b19fb1a32266d760f4cf783.tar.xz
Close off unused FDs
-rw-r--r--paludis/ipc_output_manager.cc24
1 files changed, 22 insertions, 2 deletions
diff --git a/paludis/ipc_output_manager.cc b/paludis/ipc_output_manager.cc
index 3eaa22c..db874e6 100644
--- a/paludis/ipc_output_manager.cc
+++ b/paludis/ipc_output_manager.cc
@@ -44,6 +44,7 @@
#include <cstdlib>
#include <cstring>
#include <unistd.h>
+#include <fcntl.h>
#include <errno.h>
using namespace paludis;
@@ -92,8 +93,14 @@ IPCOutputManager::IPCOutputManager(const int r, const int w, const CreateOutputM
if (tokens.size() != 4 || tokens[0] != "O" || tokens[1] != "1")
throw InternalError(PALUDIS_HERE, "got response '" + response + "'");
- _imp->stdout_stream.reset(new SafeOFStream(destringify<int>(tokens[2])));
- _imp->stderr_stream.reset(new SafeOFStream(destringify<int>(tokens[3])));
+ int stdout_fd(destringify<int>(tokens[2])), stderr_fd(destringify<int>(tokens[3]));
+ _imp->stdout_stream.reset(new SafeOFStream(stdout_fd));
+ _imp->stderr_stream.reset(new SafeOFStream(stderr_fd));
+
+ if (0 != ::fcntl(stdout_fd, F_SETFD, FD_CLOEXEC))
+ throw InternalError(PALUDIS_HERE, "fcntl failed");
+ if (0 != ::fcntl(stderr_fd, F_SETFD, FD_CLOEXEC))
+ throw InternalError(PALUDIS_HERE, "fcntl failed");
}
IPCOutputManager::~IPCOutputManager()
@@ -183,6 +190,14 @@ namespace paludis
env(e),
exclusivity(x)
{
+ if (0 != ::fcntl(finished_pipe.read_fd(), F_SETFD, FD_CLOEXEC))
+ throw InternalError(PALUDIS_HERE, "fcntl failed");
+ if (0 != ::fcntl(finished_pipe.write_fd(), F_SETFD, FD_CLOEXEC))
+ throw InternalError(PALUDIS_HERE, "fcntl failed");
+ if (0 != ::fcntl(stdout_pipe.read_fd(), F_SETFD, FD_CLOEXEC))
+ throw InternalError(PALUDIS_HERE, "fcntl failed");
+ if (0 != ::fcntl(stderr_pipe.read_fd(), F_SETFD, FD_CLOEXEC))
+ throw InternalError(PALUDIS_HERE, "fcntl failed");
}
};
}
@@ -358,6 +373,11 @@ namespace paludis
throw InternalError(PALUDIS_HERE, "no pipe command handler available");
unsetenv("PALUDIS_IPC_READ_FD");
unsetenv("PALUDIS_IPC_WRITE_FD");
+
+ if (0 != ::fcntl(read_fd, F_SETFD, FD_CLOEXEC))
+ throw InternalError(PALUDIS_HERE, "fcntl failed");
+ if (0 != ::fcntl(write_fd, F_SETFD, FD_CLOEXEC))
+ throw InternalError(PALUDIS_HERE, "fcntl failed");
}
};
}