You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2015/09/26 00:29:48 UTC
[3/3] mesos git commit: Avoid closing '-1' file descriptors in
Subprocess.
Avoid closing '-1' file descriptors in Subprocess.
Review: https://reviews.apache.org/r/38777
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/1ab9618e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/1ab9618e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/1ab9618e
Branch: refs/heads/master
Commit: 1ab9618efba1a2551d40fed5679a25336f2e79ac
Parents: 7e95a3b
Author: Benjamin Mahler <be...@gmail.com>
Authored: Fri Sep 25 15:12:51 2015 -0700
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Sep 25 15:13:01 2015 -0700
----------------------------------------------------------------------
3rdparty/libprocess/src/subprocess.cpp | 34 +++++++++++++++--------------
1 file changed, 18 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/1ab9618e/3rdparty/libprocess/src/subprocess.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/subprocess.cpp b/3rdparty/libprocess/src/subprocess.cpp
index 5ff7848..a457cbe 100644
--- a/3rdparty/libprocess/src/subprocess.cpp
+++ b/3rdparty/libprocess/src/subprocess.cpp
@@ -62,30 +62,32 @@ static void cleanup(
static void close(int stdinFd[2], int stdoutFd[2], int stderrFd[2])
{
- os::close(stdinFd[0]);
- os::close(stdinFd[1]);
- os::close(stdoutFd[0]);
- os::close(stdoutFd[1]);
- os::close(stderrFd[0]);
- os::close(stderrFd[1]);
+ int fds[6] = {
+ stdinFd[0], stdinFd[1],
+ stdoutFd[0], stdoutFd[1],
+ stderrFd[0], stderrFd[1]
+ };
+
+ foreach (int fd, fds) {
+ if (fd >= 0) {
+ os::close(fd);
+ }
+ }
}
// This function will invoke os::cloexec on all file descriptors in
// these pairs that are valid (i.e., >= 0).
static Try<Nothing> cloexec(int stdinFd[2], int stdoutFd[2], int stderrFd[2])
{
- int fd[6] = {
- stdinFd[0],
- stdinFd[1],
- stdoutFd[0],
- stdoutFd[1],
- stderrFd[0],
- stderrFd[1]
+ int fds[6] = {
+ stdinFd[0], stdinFd[1],
+ stdoutFd[0], stdoutFd[1],
+ stderrFd[0], stderrFd[1]
};
- for (int i = 0; i < 6; i++) {
- if (fd[i] >= 0) {
- Try<Nothing> cloexec = os::cloexec(fd[i]);
+ foreach (int fd, fds) {
+ if (fd >= 0) {
+ Try<Nothing> cloexec = os::cloexec(fd);
if (cloexec.isError()) {
return Error(cloexec.error());
}