You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2013/08/06 08:08:36 UTC

[10/13] git commit: Updated proc::status to handle race with checking if a file exists and opening the file.

Updated proc::status to handle race with checking if a file exists and
opening the file.

Review: https://reviews.apache.org/r/12433


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e5c2edc3
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e5c2edc3
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e5c2edc3

Branch: refs/heads/master
Commit: e5c2edc3434b918bc9e25629b1571d7c283ce867
Parents: eb4762c
Author: Benjamin Hindman <be...@twitter.com>
Authored: Tue Jul 2 22:55:12 2013 -0400
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Mon Aug 5 23:08:04 2013 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e5c2edc3/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 2fcc04b..a69a36c 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/proc.hpp
@@ -152,13 +152,15 @@ inline Result<ProcessStatus> status(pid_t pid)
 {
   std::string path = "/proc/" + stringify(pid) + "/stat";
 
-  if (!os::exists(path)) {
-    return None();
-  }
-
   std::ifstream file(path.c_str());
 
   if (!file.is_open()) {
+    // 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).
+    if (!os::exists(path)) {
+      return None();
+    }
     return Error("Failed to open '" + path + "'");
   }