mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mp...@apache.org
Subject [1/7] mesos git commit: Replaced `int` with `int_fd` in mesos.
Date Mon, 06 Feb 2017 20:07:14 GMT
Repository: mesos
Updated Branches:
  refs/heads/master b150a4ff0 -> ca240948e


Replaced `int` with `int_fd` in mesos.

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


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

Branch: refs/heads/master
Commit: ca240948e96937d331293255f8db576adbf8062f
Parents: 3033cfb
Author: Michael Park <mpark@apache.org>
Authored: Tue Dec 6 17:38:03 2016 -0800
Committer: Michael Park <mpark@apache.org>
Committed: Mon Feb 6 11:54:51 2017 -0800

----------------------------------------------------------------------
 include/mesos/slave/container_logger.hpp        |  8 ++---
 src/docker/docker.cpp                           |  2 +-
 src/files/files.cpp                             | 13 ++++----
 src/slave/containerizer/fetcher.cpp             |  4 +--
 src/slave/containerizer/mesos/containerizer.cpp | 19 +++++------
 src/slave/containerizer/mesos/containerizer.hpp |  3 +-
 .../containerizer/mesos/io/switchboard.cpp      | 32 +++++++++++--------
 .../containerizer/mesos/io/switchboard_main.cpp |  9 ++++--
 src/slave/containerizer/mesos/launch.cpp        | 11 +------
 src/slave/containerizer/mesos/launch.hpp        |  5 ++-
 src/slave/state.cpp                             | 26 +++++++++------
 src/slave/status_update_manager.cpp             |  2 +-
 src/slave/status_update_manager.hpp             |  2 +-
 src/tests/containerizer/cgroups_tests.cpp       |  2 +-
 .../containerizer/io_switchboard_tests.cpp      | 33 ++++++++++----------
 src/tests/containerizer/memory_test_helper.cpp  |  2 +-
 .../nested_mesos_containerizer_tests.cpp        | 18 +++++++----
 src/tests/credentials_tests.cpp                 |  4 +--
 src/tests/mesos.cpp                             |  6 ++--
 src/tests/protobuf_io_tests.cpp                 |  8 ++---
 20 files changed, 112 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/include/mesos/slave/container_logger.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/slave/container_logger.hpp b/include/mesos/slave/container_logger.hpp
index 5781fec..a3f619b 100644
--- a/include/mesos/slave/container_logger.hpp
+++ b/include/mesos/slave/container_logger.hpp
@@ -83,7 +83,7 @@ public:
         return IO(Type::PATH, None(), path);
       }
 
-      static IO FD(int fd)
+      static IO FD(int_fd fd)
       {
         return IO(Type::FD, fd, None());
       }
@@ -107,19 +107,19 @@ public:
       }
 
       Type type() const { return type_; }
-      Option<int> fd() const { return fd_; }
+      Option<int_fd> fd() const { return fd_; }
       Option<std::string> path() const { return path_; }
 
     private:
       IO(Type _type,
-         const Option<int>& _fd,
+         const Option<int_fd>& _fd,
          const Option<std::string>& _path)
         : type_(_type),
           fd_(_fd),
           path_(_path) {}
 
       Type type_;
-      Option<int> fd_;
+      Option<int_fd> fd_;
       Option<std::string> path_;
     };
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/docker/docker.cpp
----------------------------------------------------------------------
diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp
index b63b060..68042fd 100755
--- a/src/docker/docker.cpp
+++ b/src/docker/docker.cpp
@@ -561,7 +561,7 @@ Future<Option<int>> Docker::run(
 
   const string& environmentFile = environmentFile_.get();
 
-  Try<int> fd = os::open(
+  Try<int_fd> fd = os::open(
       environmentFile,
       O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
       S_IRUSR | S_IWUSR);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/files/files.cpp
----------------------------------------------------------------------
diff --git a/src/files/files.cpp b/src/files/files.cpp
index 2b984ed..8327f80 100644
--- a/src/files/files.cpp
+++ b/src/files/files.cpp
@@ -619,8 +619,7 @@ Future<Try<tuple<size_t, string>, FilesError>> FilesProcess::_read(
 
   // TODO(benh): Cache file descriptors so we aren't constantly
   // opening them and paging the data in from disk.
-  Try<int> fd = os::open(resolvedPath.get(), O_RDONLY | O_CLOEXEC);
-
+  Try<int_fd> fd = os::open(resolvedPath.get(), O_RDONLY | O_CLOEXEC);
   if (fd.isError()) {
     string error = strings::format(
         "Failed to open file at '%s': %s",
@@ -630,9 +629,8 @@ Future<Try<tuple<size_t, string>, FilesError>> FilesProcess::_read(
     return FilesError(FilesError::Type::UNKNOWN, error + ".\n");
   }
 
-  const off_t size = lseek(fd.get(), 0, SEEK_END);
-
-  if (size == -1) {
+  Try<off_t> lseek = os::lseek(fd.get(), 0, SEEK_END);
+  if (lseek.isError()) {
     string error = strings::format(
         "Failed to open file at '%s': %s",
         resolvedPath.get(),
@@ -643,6 +641,8 @@ Future<Try<tuple<size_t, string>, FilesError>> FilesProcess::_read(
     return FilesError(FilesError::Type::UNKNOWN, error + ".\n");
   }
 
+  const off_t size = lseek.get();
+
   if (offset >= static_cast<size_t>(size)) {
     os::close(fd.get());
     return std::make_tuple(size, "");
@@ -662,7 +662,8 @@ Future<Try<tuple<size_t, string>, FilesError>> FilesProcess::_read(
   length = std::min(length.get(), os::pagesize() * 16);
 
   // Seek to the offset we want to read from.
-  if (lseek(fd.get(), offset, SEEK_SET) == -1) {
+  lseek = os::lseek(fd.get(), offset, SEEK_SET);
+  if (lseek.isError()) {
     string error = strings::format(
         "Failed to seek file at '%s': %s",
         resolvedPath.get(),

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/slave/containerizer/fetcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/fetcher.cpp b/src/slave/containerizer/fetcher.cpp
index ba2e118..9ec38dc 100644
--- a/src/slave/containerizer/fetcher.cpp
+++ b/src/slave/containerizer/fetcher.cpp
@@ -734,7 +734,7 @@ Future<Nothing> FetcherProcess::run(
   // chown them.
   const string stdoutPath = path::join(info.sandbox_directory(), "stdout");
 
-  Try<int> out = os::open(
+  Try<int_fd> out = os::open(
       stdoutPath,
       O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK | O_CLOEXEC,
       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -744,7 +744,7 @@ Future<Nothing> FetcherProcess::run(
   }
 
   string stderrPath = path::join(info.sandbox_directory(), "stderr");
-  Try<int> err = os::open(
+  Try<int_fd> err = os::open(
       stderrPath,
       O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK | O_CLOEXEC,
       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/slave/containerizer/mesos/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp
index 4f0a773..d2b4f75 100644
--- a/src/slave/containerizer/mesos/containerizer.cpp
+++ b/src/slave/containerizer/mesos/containerizer.cpp
@@ -1507,21 +1507,23 @@ Future<bool> MesosContainerizerProcess::_launch(
 
   // Use a pipe to block the child until it's been isolated.
   // The `pipes` array is captured later in a lambda.
-  std::array<int, 2> pipes;
+  Try<std::array<int_fd, 2>> pipes_ = os::pipe();
 
   // TODO(jmlvanre): consider returning failure if `pipe` gives an
   // error. Currently we preserve the previous logic.
-  CHECK_SOME(os::pipe(pipes.data()));
+  CHECK_SOME(pipes_);
+
+  const std::array<int_fd, 2>& pipes = pipes_.get();
 
   // Prepare the flags to pass to the launch process.
   MesosContainerizerLaunch::Flags launchFlags;
 
   launchFlags.launch_info = JSON::protobuf(launchInfo);
 
-#ifndef __WINDOWS__
   launchFlags.pipe_read = pipes[0];
   launchFlags.pipe_write = pipes[1];
 
+#ifndef __WINDOWS__
   // Set the `runtime_directory` launcher flag so that the launch
   // helper knows where to checkpoint the status of the container
   // once it exits.
@@ -1531,12 +1533,7 @@ Future<bool> MesosContainerizerProcess::_launch(
   CHECK(os::exists(runtimePath));
 
   launchFlags.runtime_directory = runtimePath;
-#else
-  // NOTE: On windows we need to pass `Handle`s between processes, as fds
-  // are not unique across processes.
-  launchFlags.pipe_read = os::fd_to_handle(pipes[0]);
-  launchFlags.pipe_write = os::fd_to_handle(pipes[1]);
-#endif // __WINDOWS
+#endif // __WINDOWS__
 
   VLOG(1) << "Launching '" << MESOS_CONTAINERIZER << "' with flags '"
           << launchFlags << "'";
@@ -1745,7 +1742,7 @@ Future<bool> MesosContainerizerProcess::isolate(
 
 Future<bool> MesosContainerizerProcess::exec(
     const ContainerID& containerId,
-    int pipeWrite)
+    int_fd pipeWrite)
 {
   // The container may be destroyed before we exec the executor so
   // return failure here.
@@ -1763,7 +1760,7 @@ Future<bool> MesosContainerizerProcess::exec(
   // by writing to the pipe.
   char dummy;
   ssize_t length;
-  while ((length = write(pipeWrite, &dummy, sizeof(dummy))) == -1 &&
+  while ((length = os::write(pipeWrite, &dummy, sizeof(dummy))) == -1 &&
          errno == EINTR);
 
   if (length != sizeof(dummy)) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/slave/containerizer/mesos/containerizer.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/containerizer.hpp b/src/slave/containerizer/mesos/containerizer.hpp
index 9fcad93..10a9b57 100644
--- a/src/slave/containerizer/mesos/containerizer.hpp
+++ b/src/slave/containerizer/mesos/containerizer.hpp
@@ -29,6 +29,7 @@
 
 #include <stout/hashmap.hpp>
 #include <stout/multihashmap.hpp>
+#include <stout/os/int_fd.hpp>
 
 #include <mesos/slave/isolator.hpp>
 
@@ -181,7 +182,7 @@ public:
 
   virtual process::Future<bool> exec(
       const ContainerID& containerId,
-      int pipeWrite);
+      int_fd pipeWrite);
 
   virtual process::Future<bool> destroy(
       const ContainerID& containerId);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/slave/containerizer/mesos/io/switchboard.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/io/switchboard.cpp b/src/slave/containerizer/mesos/io/switchboard.cpp
index 6de9917..b948f3c 100644
--- a/src/slave/containerizer/mesos/io/switchboard.cpp
+++ b/src/slave/containerizer/mesos/io/switchboard.cpp
@@ -311,10 +311,12 @@ Future<Option<ContainerLaunchInfo>> IOSwitchboard::_prepare(
     ContainerIO* err = launchInfo.mutable_err();
 
     switch (loggerInfo.out.type()) {
+#ifndef __WINDOWS__
       case ContainerLogger::SubprocessInfo::IO::Type::FD:
         out->set_type(ContainerIO::FD);
         out->set_fd(loggerInfo.out.fd().get());
         break;
+#endif
       case ContainerLogger::SubprocessInfo::IO::Type::PATH:
         out->set_type(ContainerIO::PATH);
         out->set_path(loggerInfo.out.path().get());
@@ -324,10 +326,12 @@ Future<Option<ContainerLaunchInfo>> IOSwitchboard::_prepare(
     }
 
     switch (loggerInfo.err.type()) {
+#ifndef __WINDOWS__
       case ContainerLogger::SubprocessInfo::IO::Type::FD:
         err->set_type(ContainerIO::FD);
         err->set_fd(loggerInfo.err.fd().get());
         break;
+#endif
       case ContainerLogger::SubprocessInfo::IO::Type::PATH:
         err->set_type(ContainerIO::PATH);
         err->set_path(loggerInfo.err.path().get());
@@ -450,34 +454,36 @@ Future<Option<ContainerLaunchInfo>> IOSwitchboard::_prepare(
 
     launchInfo.set_tty_slave_path(slavePath.get());
   } else {
-    int infds[2];
-    int outfds[2];
-    int errfds[2];
-
-    Try<Nothing> pipe = os::pipe(infds);
-    if (pipe.isError()) {
+    Try<std::array<int_fd, 2>> infds_ = os::pipe();
+    if (infds_.isError()) {
       close(openedFds);
-      return Failure("Failed to create stdin pipe: " + pipe.error());
+      return Failure("Failed to create stdin pipe: " + infds_.error());
     }
 
+    const std::array<int_fd, 2>& infds = infds_.get();
+
     openedFds.insert(infds[0]);
     openedFds.insert(infds[1]);
 
-    pipe = os::pipe(outfds);
-    if (pipe.isError()) {
+    Try<std::array<int_fd, 2>> outfds_ = os::pipe();
+    if (outfds_.isError()) {
       close(openedFds);
-      return Failure("Failed to create stdout pipe: " + pipe.error());
+      return Failure("Failed to create stdout pipe: " + outfds_.error());
     }
 
+    const std::array<int_fd, 2>& outfds = outfds_.get();
+
     openedFds.insert(outfds[0]);
     openedFds.insert(outfds[1]);
 
-    pipe = os::pipe(errfds);
-    if (pipe.isError()) {
+    Try<std::array<int_fd, 2>> errfds_ = os::pipe();
+    if (errfds_.isError()) {
       close(openedFds);
-      return Failure("Failed to create stderr pipe: " + pipe.error());
+      return Failure("Failed to create stderr pipe: " + errfds_.error());
     }
 
+    const std::array<int_fd, 2>& errfds = errfds_.get();
+
     openedFds.insert(errfds[0]);
     openedFds.insert(errfds[1]);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/slave/containerizer/mesos/io/switchboard_main.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/io/switchboard_main.cpp b/src/slave/containerizer/mesos/io/switchboard_main.cpp
index 87056c3..fa0b296 100644
--- a/src/slave/containerizer/mesos/io/switchboard_main.cpp
+++ b/src/slave/containerizer/mesos/io/switchboard_main.cpp
@@ -14,6 +14,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#include <array>
+
 #include <process/future.hpp>
 #include <process/io.hpp>
 #include <process/owned.hpp>
@@ -38,8 +40,7 @@ using process::Owned;
 // support to defer a signal handler to a thread, but we currently
 // don't expose this through libprocess. Once we do expose this, we
 // should change this logic to use it.
-int unblockFds[2];
-
+std::array<int_fd, 2> unblockFds;
 
 static void sigtermHandler(int sig)
 {
@@ -91,12 +92,14 @@ int main(int argc, char** argv)
     EXIT(EXIT_FAILURE) << flags.usage("'--socket_path' is missing");
   }
 
-  Try<Nothing> pipe = os::pipe(unblockFds);
+  Try<std::array<int_fd, 2>> pipe = os::pipe();
   if (pipe.isError()) {
     EXIT(EXIT_FAILURE) << "Failed to create pipe for signaling unblock:"
                        << " " + pipe.error();
   }
 
+  unblockFds = pipe.get();
+
   if (os::signals::install(SIGTERM, sigtermHandler) != 0) {
     EXIT(EXIT_FAILURE) << "Failed to register signal"
                        << " '" + stringify(strsignal(SIGTERM)) << "'";

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index 40116f9..4dd81b4 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -319,16 +319,7 @@ int MesosContainerizerLaunch::execute()
     flags.pipe_read.isSome() && flags.pipe_write.isSome();
 
   if (controlPipeSpecified) {
-    int pipe[2] = { flags.pipe_read.get(), flags.pipe_write.get() };
-
-    // NOTE: On windows we need to pass `HANDLE`s between processes,
-    // as file descriptors are not unique across processes. Here we
-    // convert back from from the `HANDLE`s we receive to fds that can
-    // be used in os-agnostic code.
-#ifdef __WINDOWS__
-    pipe[0] = os::handle_to_fd(pipe[0], _O_RDONLY | _O_TEXT);
-    pipe[1] = os::handle_to_fd(pipe[1], _O_TEXT);
-#endif // __WINDOWS__
+    int_fd pipe[2] = { flags.pipe_read.get(), flags.pipe_write.get() };
 
     Try<Nothing> close = os::close(pipe[1]);
     if (close.isError()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/slave/containerizer/mesos/launch.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.hpp b/src/slave/containerizer/mesos/launch.hpp
index 5bba139..49eb912 100644
--- a/src/slave/containerizer/mesos/launch.hpp
+++ b/src/slave/containerizer/mesos/launch.hpp
@@ -40,9 +40,12 @@ public:
     Flags();
 
     Option<JSON::Object> launch_info;
+#ifdef __WINDOWS__
+    Option<HANDLE> pipe_read;
+    Option<HANDLE> pipe_write;
+#else
     Option<int> pipe_read;
     Option<int> pipe_write;
-#ifndef __WINDOWS__
     Option<std::string> runtime_directory;
 #endif // __WINDOWS__
 #ifdef __linux__

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/slave/state.cpp
----------------------------------------------------------------------
diff --git a/src/slave/state.cpp b/src/slave/state.cpp
index 6894875..f8e7cdd 100644
--- a/src/slave/state.cpp
+++ b/src/slave/state.cpp
@@ -35,7 +35,9 @@
 #include <stout/os/close.hpp>
 #include <stout/os/exists.hpp>
 #include <stout/os/ftruncate.hpp>
+#include <stout/os/int_fd.hpp>
 #include <stout/os/ls.hpp>
+#include <stout/os/lseek.hpp>
 #include <stout/os/read.hpp>
 #include <stout/os/realpath.hpp>
 #include <stout/os/stat.hpp>
@@ -614,8 +616,7 @@ Try<TaskState> TaskState::recover(
 
   // Open the status updates file for reading and writing (for
   // truncating).
-  Try<int> fd = os::open(path, O_RDWR | O_CLOEXEC);
-
+  Try<int_fd> fd = os::open(path, O_RDWR | O_CLOEXEC);
   if (fd.isError()) {
     message = "Failed to open status updates file '" + path +
               "': " + fd.error();
@@ -647,13 +648,15 @@ Try<TaskState> TaskState::recover(
     }
   }
 
-  off_t offset = lseek(fd.get(), 0, SEEK_CUR);
-
-  if (offset < 0) {
+  Try<off_t> lseek = os::lseek(fd.get(), 0, SEEK_CUR);
+  if (lseek.isError()) {
     os::close(fd.get());
-    return ErrnoError("Failed to lseek status updates file '" + path + "'");
+    return Error(
+        "Failed to lseek status updates file '" + path + "':" + lseek.error());
   }
 
+  off_t offset = lseek.get();
+
   // Always truncate the file to contain only valid updates.
   // NOTE: This is safe even though we ignore partial protobuf read
   // errors above, because the 'fd' is properly set to the end of the
@@ -740,7 +743,7 @@ Try<Resources> ResourcesState::recoverResources(
 {
   Resources resources;
 
-  Try<int> fd = os::open(path, O_RDWR | O_CLOEXEC);
+  Try<int_fd> fd = os::open(path, O_RDWR | O_CLOEXEC);
   if (fd.isError()) {
     string message =
       "Failed to open resources file '" + path + "': " + fd.error();
@@ -766,12 +769,15 @@ Try<Resources> ResourcesState::recoverResources(
     resources += resource.get();
   }
 
-  off_t offset = lseek(fd.get(), 0, SEEK_CUR);
-  if (offset < 0) {
+  Try<off_t> lseek = os::lseek(fd.get(), 0, SEEK_CUR);
+  if (lseek.isError()) {
     os::close(fd.get());
-    return ErrnoError("Failed to lseek resources file '" + path + "'");
+    return Error(
+        "Failed to lseek resources file '" + path + "':" + lseek.error());
   }
 
+  off_t offset = lseek.get();
+
   // Always truncate the file to contain only valid resources.
   // NOTE: This is safe even though we ignore partial protobuf read
   // errors above, because the 'fd' is properly set to the end of the

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/slave/status_update_manager.cpp
----------------------------------------------------------------------
diff --git a/src/slave/status_update_manager.cpp b/src/slave/status_update_manager.cpp
index 056a684..df63a70 100644
--- a/src/slave/status_update_manager.cpp
+++ b/src/slave/status_update_manager.cpp
@@ -680,7 +680,7 @@ StatusUpdateStream::StatusUpdateStream(
     // if the host did not crash. `os::write` success implies the kernel
     // will have flushed our data to the page cache. This is sufficient
     // for the recovery scenarios we use this data for.
-    Try<int> result = os::open(
+    Try<int_fd> result = os::open(
         path.get(),
         O_CREAT | O_WRONLY | O_APPEND | O_CLOEXEC,
         S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/slave/status_update_manager.hpp
----------------------------------------------------------------------
diff --git a/src/slave/status_update_manager.hpp b/src/slave/status_update_manager.hpp
index 9fad0c5..14ead42 100644
--- a/src/slave/status_update_manager.hpp
+++ b/src/slave/status_update_manager.hpp
@@ -197,7 +197,7 @@ private:
   hashset<UUID> acknowledged;
 
   Option<std::string> path; // File path of the update stream.
-  Option<int> fd; // File descriptor to the update stream.
+  Option<int_fd> fd; // File descriptor to the update stream.
 
   Option<std::string> error; // Potential non-retryable error.
 };

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/tests/containerizer/cgroups_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/cgroups_tests.cpp b/src/tests/containerizer/cgroups_tests.cpp
index 5c1ef70..af8a201 100644
--- a/src/tests/containerizer/cgroups_tests.cpp
+++ b/src/tests/containerizer/cgroups_tests.cpp
@@ -1366,7 +1366,7 @@ TEST_F(CgroupsAnyHierarchyDevicesTest, ROOT_CGROUPS_Devices)
   EXPECT_TRUE(whitelist->empty());
 
   // Verify that we can't open /dev/null.
-  Try<int> fd = os::open("/dev/null", O_RDWR);
+  Try<int_fd> fd = os::open("/dev/null", O_RDWR);
   EXPECT_ERROR(fd);
 
   // Add /dev/null to the list of allowed devices.

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/tests/containerizer/io_switchboard_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/io_switchboard_tests.cpp b/src/tests/containerizer/io_switchboard_tests.cpp
index 738da5b..ce8336b 100644
--- a/src/tests/containerizer/io_switchboard_tests.cpp
+++ b/src/tests/containerizer/io_switchboard_tests.cpp
@@ -162,17 +162,18 @@ protected:
 
 TEST_F(IOSwitchboardServerTest, RedirectLog)
 {
-  int stdoutPipe[2];
-  int stderrPipe[2];
-
   Try<int> nullFd = os::open("/dev/null", O_RDWR);
   ASSERT_SOME(nullFd);
 
-  Try<Nothing> pipe = os::pipe(stdoutPipe);
-  ASSERT_SOME(pipe);
+  Try<std::array<int, 2>> stdoutPipe_ = os::pipe();
+  ASSERT_SOME(stdoutPipe_);
+
+  const std::array<int, 2>& stdoutPipe = stdoutPipe_.get();
+
+  Try<std::array<int, 2>> stderrPipe_ = os::pipe();
+  ASSERT_SOME(stderrPipe_);
 
-  pipe = os::pipe(stderrPipe);
-  ASSERT_SOME(pipe);
+  const std::array<int, 2>& stderrPipe = stderrPipe_.get();
 
   string stdoutPath = path::join(sandbox.get(), "stdout");
   Try<int> stdoutFd = os::open(
@@ -360,10 +361,10 @@ TEST_F(IOSwitchboardServerTest, SendHeartbeat)
   // We use a pipe in this test to prevent the switchboard from
   // reading EOF on its `stdoutFromFd` until we are ready for the
   // switchboard to terminate.
-  int stdoutPipe[2];
+  Try<std::array<int, 2>> stdoutPipe_ = os::pipe();
+  ASSERT_SOME(stdoutPipe_);
 
-  Try<Nothing> pipe = os::pipe(stdoutPipe);
-  ASSERT_SOME(pipe);
+  const std::array<int, 2>& stdoutPipe = stdoutPipe_.get();
 
   Try<int> nullFd = os::open("/dev/null", O_RDWR);
   ASSERT_SOME(nullFd);
@@ -467,10 +468,10 @@ TEST_F(IOSwitchboardServerTest, AttachInput)
   // We use a pipe in this test to prevent the switchboard from
   // reading EOF on its `stdoutFromFd` until we are ready for the
   // switchboard to terminate.
-  int stdoutPipe[2];
+  Try<std::array<int, 2>> stdoutPipe_ = os::pipe();
+  ASSERT_SOME(stdoutPipe_);
 
-  Try<Nothing> pipe = os::pipe(stdoutPipe);
-  ASSERT_SOME(pipe);
+  const std::array<int, 2>& stdoutPipe = stdoutPipe_.get();
 
   Try<int> nullFd = os::open("/dev/null", O_RDWR);
   ASSERT_SOME(nullFd);
@@ -598,10 +599,10 @@ TEST_F(IOSwitchboardServerTest, ReceiveHeartbeat)
   // We use a pipe in this test to prevent the switchboard from
   // reading EOF on its `stdoutFromFd` until we are ready for the
   // switchboard to terminate.
-  int stdoutPipe[2];
+  Try<std::array<int, 2>> stdoutPipe_ = os::pipe();
+  ASSERT_SOME(stdoutPipe_);
 
-  Try<Nothing> pipe = os::pipe(stdoutPipe);
-  ASSERT_SOME(pipe);
+  const std::array<int, 2>& stdoutPipe = stdoutPipe_.get();
 
   Try<int> nullFd = os::open("/dev/null", O_RDWR);
   ASSERT_SOME(nullFd);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/tests/containerizer/memory_test_helper.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/memory_test_helper.cpp b/src/tests/containerizer/memory_test_helper.cpp
index b94f0aa..53dc6a0 100644
--- a/src/tests/containerizer/memory_test_helper.cpp
+++ b/src/tests/containerizer/memory_test_helper.cpp
@@ -255,7 +255,7 @@ static Try<Nothing> doIncreasePageCache(const vector<string>&
tokens)
     return Error("Failed to create a temporary file: " + path.error());
   }
 
-  Try<int> fd = os::open(path.get(), O_WRONLY);
+  Try<int_fd> fd = os::open(path.get(), O_WRONLY);
   if (fd.isError()) {
     return Error("Failed to open file: " + fd.error());
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/nested_mesos_containerizer_tests.cpp b/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
index 9a6bcb5..ea01fe5 100644
--- a/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
+++ b/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
@@ -400,8 +400,10 @@ TEST_F(NestedMesosContainerizerTest,
   ASSERT_EQ(1u, offers->size());
 
   // Use a pipe to synchronize with the top-level container.
-  int pipes[2] = {-1, -1};
-  ASSERT_SOME(os::pipe(pipes));
+  Try<std::array<int, 2>> pipes_ = os::pipe();
+  ASSERT_SOME(pipes_);
+
+  const std::array<int, 2>& pipes = pipes_.get();
 
   // Launch a command task within the `alpine` docker image and
   // synchronize its launch with the launch of a debug container below.
@@ -768,8 +770,10 @@ TEST_F(NestedMesosContainerizerTest, ROOT_CGROUPS_ParentExit)
   ContainerID containerId;
   containerId.set_value(UUID::random().toString());
 
-  int pipes[2] = {-1, -1};
-  ASSERT_SOME(os::pipe(pipes));
+  Try<std::array<int, 2>> pipes_ = os::pipe();
+  ASSERT_SOME(pipes_);
+
+  const std::array<int, 2>& pipes = pipes_.get();
 
   // NOTE: We use a non-shell command here to use 'bash -c' to execute
   // the 'read', which deals with the file descriptor, because of a bug
@@ -869,8 +873,10 @@ TEST_F(NestedMesosContainerizerTest, ROOT_CGROUPS_ParentSigterm)
   containerId.set_value(UUID::random().toString());
 
   // Use a pipe to synchronize with the top-level container.
-  int pipes[2] = {-1, -1};
-  ASSERT_SOME(os::pipe(pipes));
+  Try<std::array<int, 2>> pipes_ = os::pipe();
+  ASSERT_SOME(pipes_);
+
+  const std::array<int, 2>& pipes = pipes_.get();
 
   // NOTE: We use a non-shell command here to use 'bash -c' to execute
   // the 'echo', which deals with the file descriptor, because of a bug

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/tests/credentials_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/credentials_tests.cpp b/src/tests/credentials_tests.cpp
index a600252..809f8c7 100644
--- a/src/tests/credentials_tests.cpp
+++ b/src/tests/credentials_tests.cpp
@@ -76,7 +76,7 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(CredentialsTest, AuthenticatedSlaveText)
 {
   string path =  path::join(os::getcwd(), "credentials");
 
-  Try<int> fd = os::open(
+  Try<int_fd> fd = os::open(
       path,
       O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
       S_IRUSR | S_IWUSR | S_IRGRP);
@@ -120,7 +120,7 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(CredentialsTest, AuthenticatedSlaveJSON)
 {
   string path =  path::join(os::getcwd(), "credentials");
 
-  Try<int> fd = os::open(
+  Try<int_fd> fd = os::open(
       path,
       O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
       S_IRUSR | S_IWUSR | S_IRGRP);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index adbb697..6a96fa5 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -118,7 +118,7 @@ master::Flags MesosTest::CreateMasterFlags()
   // Create a default credentials file.
   const string& path = path::join(os::getcwd(), "credentials");
 
-  Try<int> fd = os::open(
+  Try<int_fd> fd = os::open(
       path,
       O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
       S_IRUSR | S_IWUSR | S_IRGRP);
@@ -182,7 +182,7 @@ slave::Flags MesosTest::CreateSlaveFlags()
     // Create a default credential file for master/agent authentication.
     const string& path = path::join(directory.get(), "credential");
 
-    Try<int> fd = os::open(
+    Try<int_fd> fd = os::open(
         path,
         O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
         S_IRUSR | S_IWUSR | S_IRGRP);
@@ -212,7 +212,7 @@ slave::Flags MesosTest::CreateSlaveFlags()
     // Create a default HTTP credentials file.
     const string& path = path::join(directory.get(), "http_credentials");
 
-    Try<int> fd = os::open(
+    Try<int_fd> fd = os::open(
         path,
         O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
         S_IRUSR | S_IWUSR | S_IRGRP);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca240948/src/tests/protobuf_io_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/protobuf_io_tests.cpp b/src/tests/protobuf_io_tests.cpp
index 9263d8c..82bffb8 100644
--- a/src/tests/protobuf_io_tests.cpp
+++ b/src/tests/protobuf_io_tests.cpp
@@ -47,14 +47,14 @@ TEST_F(ProtobufIOTest, Basic)
 {
   const string file = ".protobuf_io_test_basic";
 
-  Try<int> result = os::open(
+  Try<int_fd> result = os::open(
       file,
       O_CREAT | O_WRONLY | O_SYNC | O_CLOEXEC,
       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
   ASSERT_SOME(result);
 
-  int fdw = result.get();
+  int_fd fdw = result.get();
 
   result = os::open(
       file,
@@ -63,7 +63,7 @@ TEST_F(ProtobufIOTest, Basic)
 
   ASSERT_SOME(result);
 
-  int fdr = result.get();
+  int_fd fdr = result.get();
 
   const size_t writes = 10;
   for (size_t i = 0; i < writes; i++) {
@@ -107,7 +107,7 @@ TEST_F(ProtobufIOTest, Append)
     ASSERT_SOME(result);
   }
 
-  Try<int> fd = os::open(
+  Try<int_fd> fd = os::open(
       file,
       O_CREAT | O_RDONLY | O_CLOEXEC,
       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);


Mime
View raw message