Fixed Mesos since `os::system()` now returns an `Option<int>`. The `os::system()` function now returns `None()` for a launch failure instead of `-1`, and a `Some(exit_code)` for success.
Review: https://reviews.apache.org/r/65863/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/765c8343 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/765c8343 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/765c8343 Branch: refs/heads/master Commit: 765c8343813e5c64775bca6757b4cd42356636ad Parents: 330ddcb Author: Akash Gupta <akash-gu...@hotmail.com> Authored: Tue Mar 6 13:11:23 2018 -0800 Committer: Andrew Schwartzmeyer <and...@schwartzmeyer.com> Committed: Tue Mar 6 13:52:35 2018 -0800 ---------------------------------------------------------------------- src/slave/containerizer/mesos/launch.cpp | 14 +++++++++----- src/tests/containerizer/cgroups_isolator_tests.cpp | 6 +++--- src/tests/containerizer/memory_pressure_tests.cpp | 2 +- src/tests/environment.cpp | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/765c8343/src/slave/containerizer/mesos/launch.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp index 75b7eaf..8c739cc 100644 --- a/src/slave/containerizer/mesos/launch.cpp +++ b/src/slave/containerizer/mesos/launch.cpp @@ -33,6 +33,7 @@ #include <stout/adaptor.hpp> #include <stout/foreach.hpp> +#include <stout/option.hpp> #include <stout/os.hpp> #include <stout/protobuf.hpp> #include <stout/path.hpp> @@ -641,7 +642,7 @@ int MesosContainerizerLaunch::execute() cout << "Executing pre-exec command '" << JSON::protobuf(command) << "'" << endl; - int status = 0; + Option<int> status; if (command.shell()) { // Execute the command using the system shell. @@ -657,11 +658,14 @@ int MesosContainerizerLaunch::execute() status = os::spawn(command.value(), args); } - if (!WSUCCEEDED(status)) { + if (status.isNone() || !WSUCCEEDED(status.get())) { cerr << "Failed to execute pre-exec command '" - << JSON::protobuf(command) << "': " - << WSTRINGIFY(status) - << endl; + << JSON::protobuf(command) << "': "; + if (status.isNone()) { + cerr << "exited with unknown status" << endl; + } else { + cerr << WSTRINGIFY(status.get()) << endl; + } exitWithStatus(EXIT_FAILURE); } } http://git-wip-us.apache.org/repos/asf/mesos/blob/765c8343/src/tests/containerizer/cgroups_isolator_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/cgroups_isolator_tests.cpp b/src/tests/containerizer/cgroups_isolator_tests.cpp index 59b23be..40c18a1 100644 --- a/src/tests/containerizer/cgroups_isolator_tests.cpp +++ b/src/tests/containerizer/cgroups_isolator_tests.cpp @@ -217,7 +217,7 @@ TEST_F(CgroupsIsolatorTest, ROOT_CGROUPS_PERF_NET_CLS_UserCgroup) // Verify that the user cannot manipulate the container's cgroup // control files as their owner is root. - EXPECT_NE(0, os::system(strings::format( + EXPECT_SOME_NE(0, os::system(strings::format( "su - nobody -s /bin/sh -c 'echo $$ > %s'", path::join(hierarchy.get(), cgroup, "cgroup.procs")).get())); @@ -225,13 +225,13 @@ TEST_F(CgroupsIsolatorTest, ROOT_CGROUPS_PERF_NET_CLS_UserCgroup) // cgroup as the isolator changes the owner of the cgroup. string userCgroup = path::join(cgroup, "user"); - EXPECT_EQ(0, os::system(strings::format( + EXPECT_SOME_EQ(0, os::system(strings::format( "su - nobody -s /bin/sh -c 'mkdir %s'", path::join(hierarchy.get(), userCgroup)).get())); // Verify that the user can manipulate control files in the // created cgroup as it's owned by the user. - EXPECT_EQ(0, os::system(strings::format( + EXPECT_SOME_EQ(0, os::system(strings::format( "su - nobody -s /bin/sh -c 'echo $$ > %s'", path::join(hierarchy.get(), userCgroup, "cgroup.procs")).get())); http://git-wip-us.apache.org/repos/asf/mesos/blob/765c8343/src/tests/containerizer/memory_pressure_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/memory_pressure_tests.cpp b/src/tests/containerizer/memory_pressure_tests.cpp index 0c3e738..488051d 100644 --- a/src/tests/containerizer/memory_pressure_tests.cpp +++ b/src/tests/containerizer/memory_pressure_tests.cpp @@ -68,7 +68,7 @@ public: // Verify that the dd command and its flags used in a bit are valid // on this system. - ASSERT_EQ(0, os::system("dd count=1 bs=1M if=/dev/zero of=/dev/null")) + ASSERT_SOME_EQ(0, os::system("dd count=1 bs=1M if=/dev/zero of=/dev/null")) << "Cannot find a compatible 'dd' command"; } }; http://git-wip-us.apache.org/repos/asf/mesos/blob/765c8343/src/tests/environment.cpp ---------------------------------------------------------------------- diff --git a/src/tests/environment.cpp b/src/tests/environment.cpp index 1cba274..a30592a 100644 --- a/src/tests/environment.cpp +++ b/src/tests/environment.cpp @@ -394,7 +394,7 @@ private: { // Use `os::system` here because `docker->inspect()` only works on // containers even though `docker inspect` cli command works on images. - const int res = os::system( + const Option<int> res = os::system( docker->getPath() + " -H " + docker->getSocket() + " inspect " + string(mesos::internal::checks::DOCKER_HEALTH_CHECK_IMAGE) + " > NUL");