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:46 UTC
[1/3] mesos git commit: Removed unnecessary close calls on ifstream
and ofstream.
Repository: mesos
Updated Branches:
refs/heads/master de9c8dc9a -> 1ab9618ef
Removed unnecessary close calls on ifstream and ofstream.
std::ifstream and std::ofstream have RAII semantics and will
close() upon destruction.
Review: https://reviews.apache.org/r/38775
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/445fe283
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/445fe283
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/445fe283
Branch: refs/heads/master
Commit: 445fe28361a79e20d2b53f02667d571a80a48ebb
Parents: de9c8dc
Author: Benjamin Mahler <be...@gmail.com>
Authored: Fri Sep 25 14:48:49 2015 -0700
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Sep 25 14:52:38 2015 -0700
----------------------------------------------------------------------
.../libprocess/3rdparty/stout/include/stout/os/posix/read.hpp | 7 ++++---
3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp | 7 -------
2 files changed, 4 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/445fe283/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/read.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/read.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/read.hpp
index e154bb6..ffacce1 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/read.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/read.hpp
@@ -74,11 +74,12 @@ inline Result<std::string> read(int fd, size_t size)
#ifdef __sun // getline is not available on Solaris, using STL.
inline Try<std::string> read(const std::string& path)
{
- std::ifstream ifs(path.c_str());
- if (!ifs.is_open()) {
+ std::ifstream file(path.c_str());
+ if (!file.is_open()) {
+ // Does ifstream actually set errno?
return ErrnoError("Failed to open file '" + path + "'");
}
- return std::string((std::istreambuf_iterator<char>(ifs)),
+ return std::string((std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>()));
}
#else
http://git-wip-us.apache.org/repos/asf/mesos/blob/445fe283/3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp
index 66ece4d..200b8fc 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp
@@ -280,7 +280,6 @@ inline Result<std::string> cmdline(const Option<pid_t>& pid = None())
// Check for any read errors.
if (file.fail() && !file.eof()) {
- file.close();
return Error("Failed to read '" + path + "'");
} else if (!file.eof()) {
file.get(); // Read the null byte.
@@ -381,12 +380,9 @@ inline Try<SystemStatus> status()
}
if (file.fail() && !file.eof()) {
- file.close();
return Error("Failed to read /proc/stat");
}
- file.close();
-
return SystemStatus(btime);
}
@@ -507,12 +503,9 @@ inline Try<std::list<CPU> > cpus()
}
if (file.fail() && !file.eof()) {
- file.close();
return Error("Failed to read /proc/cpuinfo");
}
- file.close();
-
return results;
}
[2/3] mesos git commit: Removed unnecessary close calls on ifstream
and ofstream.
Posted by bm...@apache.org.
Removed unnecessary close calls on ifstream and ofstream.
std::ifstream and std::ofstream have RAII semantics and will
close() upon destruction.
Review: https://reviews.apache.org/r/38776
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/7e95a3b5
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/7e95a3b5
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/7e95a3b5
Branch: refs/heads/master
Commit: 7e95a3b5f44d7506dd8fb48cd801b5bda043a57e
Parents: 445fe28
Author: Benjamin Mahler <be...@gmail.com>
Authored: Fri Sep 25 14:49:05 2015 -0700
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Sep 25 14:53:51 2015 -0700
----------------------------------------------------------------------
src/linux/cgroups.cpp | 15 ++++-----------
src/log/tool/benchmark.cpp | 3 ---
2 files changed, 4 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/7e95a3b5/src/linux/cgroups.cpp
----------------------------------------------------------------------
diff --git a/src/linux/cgroups.cpp b/src/linux/cgroups.cpp
index 6ef42ed..53c568b 100644
--- a/src/linux/cgroups.cpp
+++ b/src/linux/cgroups.cpp
@@ -127,7 +127,6 @@ static Try<map<string, SubsystemInfo>> subsystems()
if (file.fail()) {
if (!file.eof()) {
- file.close();
return Error("Failed to read /proc/cgroups");
}
} else {
@@ -149,7 +148,6 @@ static Try<map<string, SubsystemInfo>> subsystems()
// Check for any read/parse errors.
if (ss.fail() && !ss.eof()) {
- file.close();
return Error("Failed to parse /proc/cgroups");
}
@@ -158,7 +156,6 @@ static Try<map<string, SubsystemInfo>> subsystems()
}
}
- file.close();
return infos;
}
@@ -368,12 +365,10 @@ static Try<string> read(
ss << file.rdbuf();
if (file.fail()) {
- ErrnoError error; // TODO(jieyu): Does ifstream actually set errno?
- file.close();
- return error;
+ // TODO(jieyu): Does ifstream actually set errno?
+ return ErrnoError();
}
- file.close();
return ss.str();
}
@@ -404,12 +399,10 @@ static Try<Nothing> write(
file << value;
if (file.fail()) {
- ErrnoError error; // TODO(jieyu): Does ifstream actually set errno?
- file.close();
- return error;
+ // TODO(jieyu): Does ofstream actually set errno?
+ return ErrnoError();
}
- file.close();
return Nothing();
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/7e95a3b5/src/log/tool/benchmark.cpp
----------------------------------------------------------------------
diff --git a/src/log/tool/benchmark.cpp b/src/log/tool/benchmark.cpp
index 4895dd8..cb823c3 100644
--- a/src/log/tool/benchmark.cpp
+++ b/src/log/tool/benchmark.cpp
@@ -196,7 +196,6 @@ Try<Nothing> Benchmark::execute(int argc, char** argv)
while (getline(input, line)) {
Try<Bytes> size = Bytes::parse(strings::trim(line));
if (size.isError()) {
- input.close();
return Error("Failed to parse the trace file: " + size.error());
}
@@ -256,8 +255,6 @@ Try<Nothing> Benchmark::execute(int argc, char** argv)
<< " in " << durations[i].ms() << " ms" << endl;
}
- output.close();
-
return Nothing();
}
[3/3] mesos git commit: Avoid closing '-1' file descriptors in
Subprocess.
Posted by bm...@apache.org.
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());
}