You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by dm...@apache.org on 2014/07/29 23:45:58 UTC

[1/2] git commit: Converted bool returns to Try in stout/os.hpp.

Repository: mesos
Updated Branches:
  refs/heads/master cd61a228e -> 190d15886


Converted bool returns to Try<Nothing> in stout/os.hpp.

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


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

Branch: refs/heads/master
Commit: 3cf732fc181bd1ade830e07c34b783271299dd5c
Parents: cd61a22
Author: Dominic Hamon <dh...@twitter.com>
Authored: Fri Apr 18 11:12:24 2014 -0700
Committer: Dominic Hamon <dh...@twitter.com>
Committed: Tue Jul 29 14:33:40 2014 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/os.hpp         | 36 ++++++++------------
 .../stout/include/stout/tests/utils.hpp         |  4 +--
 .../3rdparty/stout/tests/os_tests.cpp           |  4 +--
 3 files changed, 18 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3cf732fc/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 0825172..85b49d9 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -578,7 +578,6 @@ inline int system(const std::string& command)
 }
 
 
-// TODO(bmahler): Clean these bool functions to return Try<Nothing>.
 // Changes the specified path's user and group ownership to that of
 // the specified user..
 inline Try<Nothing> chown(
@@ -613,25 +612,23 @@ inline Try<Nothing> chown(
 }
 
 
-inline bool chmod(const std::string& path, int mode)
+inline Try<Nothing> chmod(const std::string& path, int mode)
 {
   if (::chmod(path.c_str(), mode) < 0) {
-    PLOG(ERROR) << "Failed to changed the mode of the path '" << path << "'";
-    return false;
+    return ErrnoError();
   }
 
-  return true;
+  return Nothing();
 }
 
 
-inline bool chdir(const std::string& directory)
+inline Try<Nothing> chdir(const std::string& directory)
 {
   if (::chdir(directory.c_str()) < 0) {
-    PLOG(ERROR) << "Failed to change directory";
-    return false;
+    return ErrnoError();
   }
 
-  return true;
+  return Nothing();
 }
 
 
@@ -723,30 +720,25 @@ inline Result<gid_t> getgid(const Option<std::string>& user = None())
 }
 
 
-// TODO(idownes): Refactor to return a Try and to not log internally.
-inline bool su(const std::string& user)
+inline Try<Nothing> su(const std::string& user)
 {
   Result<gid_t> gid = os::getgid(user);
   if (gid.isError() || gid.isNone()) {
-    LOG(ERROR) << "Failed to set gid: "
-               << (gid.isError() ? gid.error() : "unknown user");
-    return false;
+    return Error("Failed to getgid: " +
+        (gid.isError() ? gid.error() : "unknown user"));
   } else if (::setgid(gid.get())) {
-    PLOG(ERROR) << "Failed to setgid";
-    return false;
+    return ErrnoError("Failed to set gid");
   }
 
   Result<uid_t> uid = os::getuid(user);
   if (uid.isError() || uid.isNone()) {
-    LOG(ERROR) << "Failed to set uid: "
-               << (uid.isError() ? uid.error() : "unknown user");
-    return false;
+    return Error("Failed to getuid: " +
+        (uid.isError() ? uid.error() : "unknown user"));
   } else if (::setuid(uid.get())) {
-    PLOG(ERROR) << "Failed to setuid";
-    return false;
+    return ErrnoError("Failed to setuid");
   }
 
-  return true;
+  return Nothing();
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/3cf732fc/3rdparty/libprocess/3rdparty/stout/include/stout/tests/utils.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/tests/utils.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/tests/utils.hpp
index ff4907b..494baca 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/tests/utils.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/tests/utils.hpp
@@ -39,14 +39,14 @@ protected:
     sandbox = directory.get();
 
     // Run the test out of the temporary directory we created.
-    ASSERT_TRUE(os::chdir(sandbox.get()))
+    ASSERT_SOME(os::chdir(sandbox.get()))
       << "Failed to chdir into '" << sandbox.get() << "'";
   }
 
   virtual void TearDown()
   {
     // Return to previous working directory and cleanup the sandbox.
-    ASSERT_TRUE(os::chdir(cwd));
+    ASSERT_SOME(os::chdir(cwd));
 
     if (sandbox.isSome()) {
       ASSERT_SOME(os::rmdir(sandbox.get()));

http://git-wip-us.apache.org/repos/asf/mesos/blob/3cf732fc/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
index 7fa7346..3f2ba47 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
@@ -720,6 +720,6 @@ TEST_F(OsTest, user)
   EXPECT_NONE(os::getuid(UUID::random().toString()));
   EXPECT_NONE(os::getgid(UUID::random().toString()));
 
-  EXPECT_TRUE(os::su(user.get()));
-  EXPECT_FALSE(os::su(UUID::random().toString()));
+  EXPECT_SOME(os::su(user.get()));
+  EXPECT_ERROR(os::su(UUID::random().toString()));
 }


[2/2] git commit: Mesos converted to use Try returns from stout/os.hpp.

Posted by dm...@apache.org.
Mesos converted to use Try<Nothing> returns from stout/os.hpp.

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


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

Branch: refs/heads/master
Commit: 190d158865e786c716670b4e503fa8044bd3d0aa
Parents: 3cf732f
Author: Dominic Hamon <dh...@twitter.com>
Authored: Fri Apr 18 11:12:24 2014 -0700
Committer: Dominic Hamon <dh...@twitter.com>
Committed: Tue Jul 29 14:33:48 2014 -0700

----------------------------------------------------------------------
 src/launcher/fetcher.cpp                 |  6 +++---
 src/slave/containerizer/mesos/launch.cpp | 17 +++++++++++------
 src/tests/log_tests.cpp                  |  4 ++--
 src/tests/script.cpp                     |  7 ++++---
 src/tests/utils.cpp                      |  4 ++--
 5 files changed, 22 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/190d1588/src/launcher/fetcher.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/fetcher.cpp b/src/launcher/fetcher.cpp
index 427a2d6..50e9918 100644
--- a/src/launcher/fetcher.cpp
+++ b/src/launcher/fetcher.cpp
@@ -238,10 +238,10 @@ int main(int argc, char* argv[])
     // Chmod the fetched URI if it's executable, else assume it's an archive
     // that should be extracted.
     if (uri.executable()) {
-      bool chmodded = os::chmod(
+      Try<Nothing> chmod = os::chmod(
           fetched.get(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
-      if (!chmodded) {
-        EXIT(1) << "Failed to chmod: " << fetched.get();
+      if (chmod.isError()) {
+        EXIT(1) << "Failed to chmod " << fetched.get() << ": " << chmod.error();
       }
     } else if (uri.extract()) {
       //TODO(idownes): Consider removing the archive once extracted.

http://git-wip-us.apache.org/repos/asf/mesos/blob/190d1588/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index 2db1c7a..f8324bb 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -172,18 +172,23 @@ int MesosContainerizerLaunch::execute()
   }
 
   // Enter working directory.
-  if (!os::chdir(flags.directory.get())) {
-    cerr << "Failed to chdir into work directory "
-         << flags.directory.get() << endl;
+  Try<Nothing> chdir = os::chdir(flags.directory.get());
+  if (chdir.isError()) {
+    cerr << "Failed to chdir into work directory '"
+         << flags.directory.get() << "': " << chdir.error() << endl;
     return 1;
   }
 
   // Change user if provided. Note that we do that after executing the
   // preparation commands so that those commands will be run with the
   // same privilege as the mesos-slave.
-  if (flags.user.isSome() && !os::su(flags.user.get())) {
-    cerr << "Failed to change user to " << flags.user.get() << endl;
-    return 1;
+  if (flags.user.isSome()) {
+    Try<Nothing> su = os::su(flags.user.get());
+    if (su.isError()) {
+      cerr << "Failed to change user to '" << flags.user.get() << "': "
+           << su.error() << endl;
+      return 1;
+    }
   }
 
   // Relay the environment variables.

http://git-wip-us.apache.org/repos/asf/mesos/blob/190d1588/src/tests/log_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/log_tests.cpp b/src/tests/log_tests.cpp
index b60577d..0088706 100644
--- a/src/tests/log_tests.cpp
+++ b/src/tests/log_tests.cpp
@@ -1945,14 +1945,14 @@ protected:
     LOG(INFO) << "Using temporary directory '" << sandbox.get() << "'";
 
     // Run the test out of the temporary directory we created.
-    ASSERT_TRUE(os::chdir(sandbox.get()))
+    ASSERT_SOME(os::chdir(sandbox.get()))
       << "Failed to chdir into '" << sandbox.get() << "'";
   }
 
   virtual void TearDown()
   {
     // Return to previous working directory and cleanup the sandbox.
-    ASSERT_TRUE(os::chdir(cwd));
+    ASSERT_SOME(os::chdir(cwd));
 
     if (sandbox.isSome()) {
       ASSERT_SOME(os::rmdir(sandbox.get()));

http://git-wip-us.apache.org/repos/asf/mesos/blob/190d1588/src/tests/script.cpp
----------------------------------------------------------------------
diff --git a/src/tests/script.cpp b/src/tests/script.cpp
index 15a6542..0d29c6d 100644
--- a/src/tests/script.cpp
+++ b/src/tests/script.cpp
@@ -88,9 +88,10 @@ void execute(const string& script)
     // In child process. DO NOT USE GLOG!
 
     // Start by cd'ing into the temporary directory.
-    if (!os::chdir(directory.get())) {
-      std::cerr << "Failed to chdir to '" << directory.get() << "'"
-                << std::endl;
+    Try<Nothing> chdir = os::chdir(directory.get());
+    if (chdir.isError()) {
+      std::cerr << "Failed to chdir to '" << directory.get() << "': "
+                << chdir.error() << std::endl;
       abort();
     }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/190d1588/src/tests/utils.cpp
----------------------------------------------------------------------
diff --git a/src/tests/utils.cpp b/src/tests/utils.cpp
index 05ef305..f4f90b9 100644
--- a/src/tests/utils.cpp
+++ b/src/tests/utils.cpp
@@ -55,7 +55,7 @@ void TemporaryDirectoryTest::SetUp()
   }
 
   // Run the test out of the temporary directory we created.
-  ASSERT_TRUE(os::chdir(sandbox.get()))
+  ASSERT_SOME(os::chdir(sandbox.get()))
     << "Failed to chdir into '" << sandbox.get() << "'";
 }
 
@@ -63,7 +63,7 @@ void TemporaryDirectoryTest::SetUp()
 void TemporaryDirectoryTest::TearDown()
 {
   // Return to previous working directory and cleanup the sandbox.
-  ASSERT_TRUE(os::chdir(cwd));
+  ASSERT_SOME(os::chdir(cwd));
 
   if (sandbox.isSome()) {
     ASSERT_SOME(os::rmdir(sandbox.get()));