diff options
author | 2010-01-06 23:41:44 +0000 | |
---|---|---|
committer | 2010-01-07 00:11:18 +0000 | |
commit | eacc541e4b81f5f50b19fb1a32266d760f4cf783 (patch) | |
tree | 7d17355d590f99c03099136214434ddbedb30b6d /paludis/ipc_output_manager.cc | |
parent | 1d7fa3dd097834ee102a741b245b669cb3387661 (diff) | |
download | paludis-eacc541e4b81f5f50b19fb1a32266d760f4cf783.tar.gz paludis-eacc541e4b81f5f50b19fb1a32266d760f4cf783.tar.xz |
Close off unused FDs
Diffstat (limited to 'paludis/ipc_output_manager.cc')
-rw-r--r-- | paludis/ipc_output_manager.cc | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/paludis/ipc_output_manager.cc b/paludis/ipc_output_manager.cc index 3eaa22c89..db874e661 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"); } }; } |