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 2013/08/10 02:46:41 UTC
[2/5] git commit: Changed proc::status(pid) to use os::read().
Changed proc::status(pid) to use os::read().
This was changed because ifstream threw unexpected exceptions.
From: Jiang Yan Xu <ya...@jxu.me>
Review: https://reviews.apache.org/r/13388
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f80698f0
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f80698f0
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f80698f0
Branch: refs/heads/master
Commit: f80698f00e7ebd3c7ced5b4704f3fd3c6c7093f4
Parents: 4d2b9f2
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Fri Aug 9 17:21:03 2013 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Fri Aug 9 17:32:23 2013 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/proc.hpp | 22 +++++++++-----------
1 file changed, 10 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/f80698f0/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 d51aaa9..c3eac30 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp
@@ -15,7 +15,7 @@
#include <list>
#include <queue>
#include <set>
-#include <sstream> // For 'std::stringbuf'.
+#include <sstream> // For 'std::istringstream'.
#include <string>
#include <vector>
@@ -29,6 +29,7 @@
#include <stout/os/exists.hpp>
#include <stout/os/ls.hpp>
+#include <stout/os/read.hpp>
namespace proc {
@@ -153,18 +154,18 @@ inline Result<ProcessStatus> status(pid_t pid)
{
std::string path = "/proc/" + stringify(pid) + "/stat";
- std::ifstream file(path.c_str());
-
- if (!file.is_open()) {
+ Try<std::string> read = os::read(path);
+ if (read.isError()) {
// Need to check if file exists AFTER we open it to guarantee
- // process hasn't terminated (or if it has, we at least have a
- // file which the kernel _should_ respect until a close).
+ // process hasn't terminated.
if (!os::exists(path)) {
return None();
}
- return Error("Failed to open '" + path + "'");
+ return Error(read.error());
}
+ std::istringstream data(read.get());
+
std::string comm;
char state;
pid_t ppid;
@@ -212,7 +213,7 @@ inline Result<ProcessStatus> status(pid_t pid)
std::string _; // For ignoring fields.
// Parse all fields from stat.
- file >> _ >> comm >> state >> ppid >> pgrp >> session >> tty_nr
+ data >> _ >> comm >> state >> ppid >> pgrp >> session >> tty_nr
>> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
>> utime >> stime >> cutime >> cstime >> priority >> nice
>> num_threads >> itrealvalue >> starttime >> vsize >> rss
@@ -220,8 +221,7 @@ inline Result<ProcessStatus> status(pid_t pid)
>> signal >> blocked >> sigcatch >> wchan >> nswap >> cnswap;
// Check for any read/parse errors.
- if (file.fail() && !file.eof()) {
- file.close();
+ if (data.fail() && !data.eof()) {
return Error("Failed to read/parse '" + path + "'");
}
@@ -231,8 +231,6 @@ inline Result<ProcessStatus> status(pid_t pid)
comm = strings::remove(comm, "(", strings::PREFIX);
comm = strings::remove(comm, ")", strings::SUFFIX);
- file.close();
-
return ProcessStatus(pid, comm, state, ppid, pgrp, session, tty_nr,
tpgid, flags, minflt, cminflt, majflt, cmajflt,
utime, stime, cutime, cstime, priority, nice,