Repository: mesos Updated Branches: refs/heads/master 2250b2084 -> e2f560424
Introduced CHECK_* for Future and use of ABORT. Review: https://reviews.apache.org/r/18550 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e2f56042 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e2f56042 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e2f56042 Branch: refs/heads/master Commit: e2f560424dcf86f0d6f7dda1a5430f857b8e9e27 Parents: 2250b20 Author: Dominic Hamon <[email protected]> Authored: Wed Mar 5 17:06:47 2014 -0800 Committer: Benjamin Hindman <[email protected]> Committed: Wed Mar 5 17:10:25 2014 -0800 ---------------------------------------------------------------------- 3rdparty/libprocess/Makefile.am | 1 + 3rdparty/libprocess/include/process/check.hpp | 115 +++++++++++++++++++ 3rdparty/libprocess/include/process/collect.hpp | 3 +- 3rdparty/libprocess/include/process/future.hpp | 11 +- .../libprocess/include/process/subprocess.hpp | 15 +-- 5 files changed, 122 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/e2f56042/3rdparty/libprocess/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/Makefile.am b/3rdparty/libprocess/Makefile.am index 08a709a..3c6219e 100644 --- a/3rdparty/libprocess/Makefile.am +++ b/3rdparty/libprocess/Makefile.am @@ -63,6 +63,7 @@ endif # Headers. libprocess_la_SOURCES += \ $(top_srcdir)/include/process/async.hpp \ + $(top_srcdir)/include/process/check.hpp \ $(top_srcdir)/include/process/clock.hpp \ $(top_srcdir)/include/process/collect.hpp \ $(top_srcdir)/include/process/defer.hpp \ http://git-wip-us.apache.org/repos/asf/mesos/blob/e2f56042/3rdparty/libprocess/include/process/check.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/check.hpp b/3rdparty/libprocess/include/process/check.hpp new file mode 100644 index 0000000..107446a --- /dev/null +++ b/3rdparty/libprocess/include/process/check.hpp @@ -0,0 +1,115 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __PROCESS_CHECK_HPP__ +#define __PROCESS_CHECK_HPP__ + +#include <string> + +#include <stout/check.hpp> +#include <stout/option.hpp> + +#include <process/future.hpp> + +// Provides a CHECK_PENDING macro, akin to CHECK. +// This appends the error if possible to the end of the log message, so there's +// no need to append the error message explicitly. +#define CHECK_PENDING(expression) \ + for (const Option<std::string>& _error = _checkPending(expression); \ + _error.isSome();) \ + _CheckFatal(__FILE__, __LINE__, "CHECK_PENDING", \ + #expression, _error.get()).stream() + +#define CHECK_READY(expression) \ + for (const Option<std::string>& _error = _checkReady(expression); \ + _error.isSome();) \ + _CheckFatal(__FILE__, __LINE__, "CHECK_READY", \ + #expression, _error.get()).stream() + +#define CHECK_DISCARDED(expression) \ + for (const Option<std::string>& _error = _checkDiscarded(expression); \ + _error.isSome();) \ + _CheckFatal(__FILE__, __LINE__, "CHECK_DISCARDED", \ + #expression, _error.get()).stream() + +#define CHECK_FAILED(expression) \ + for (const Option<std::string>& _error = _checkFailed(expression); \ + _error.isSome();) \ + _CheckFatal(__FILE__, __LINE__, "CHECK_FAILED", \ + #expression, _error.get()).stream() + + +// Private structs/functions used for CHECK_*. + +template <typename T> +Option<std::string> _checkPending(const process::Future<T>& f) +{ + if (f.isReady()) { + return Some("is READY"); + } else if (f.isDiscarded()) { + return Some("is DISCARDED"); + } else if (f.isFailed()) { + return Some("is FAILED: " + f.failure()); + } + CHECK(f.isPending()); + return None(); +} + + +template <typename T> +Option<std::string> _checkReady(const process::Future<T>& f) +{ + if (f.isPending()) { + return Some("is PENDING"); + } else if (f.isDiscarded()) { + return Some("is DISCARDED"); + } else if (f.isFailed()) { + return Some("is FAILED: " + f.failure()); + } + CHECK(f.isReady()); + return None(); +} + + +template <typename T> +Option<std::string> _checkDiscarded(const process::Future<T>& f) +{ + if (f.isPending()) { + return Some("is PENDING"); + } else if (f.isReady()) { + return Some("is READY"); + } else if (f.isFailed()) { + return Some("is FAILED: " + f.failure()); + } + CHECK(f.isDiscarded()); + return None(); +} + + +template <typename T> +Option<std::string> _checkFailed(const process::Future<T>& f) +{ + if (f.isPending()) { + return Some("is PENDING"); + } else if (f.isReady()) { + return Some("is READY"); + } else if (f.isDiscarded()) { + return Some("is DISCARDED"); + } + CHECK(f.isFailed()); + return None(); +} + +// TODO(dhamon): CHECK_NPENDING, CHECK_NREADY, etc + +#endif // __PROCESS_CHECK_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/e2f56042/3rdparty/libprocess/include/process/collect.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/collect.hpp b/3rdparty/libprocess/include/process/collect.hpp index 2a73bc9..50546d3 100644 --- a/3rdparty/libprocess/include/process/collect.hpp +++ b/3rdparty/libprocess/include/process/collect.hpp @@ -5,6 +5,7 @@ #include <list> +#include <process/check.hpp> #include <process/defer.hpp> #include <process/delay.hpp> #include <process/future.hpp> @@ -104,7 +105,7 @@ private: promise->fail("Collect failed: future discarded"); terminate(this); } else { - assert(future.isReady()); + CHECK_READY(future); ready += 1; if (ready == futures.size()) { std::list<T> values; http://git-wip-us.apache.org/repos/asf/mesos/blob/e2f56042/3rdparty/libprocess/include/process/future.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/future.hpp b/3rdparty/libprocess/include/process/future.hpp index 7c2f755..27b0970 100644 --- a/3rdparty/libprocess/include/process/future.hpp +++ b/3rdparty/libprocess/include/process/future.hpp @@ -1088,15 +1088,10 @@ const T& Future<T>::get() const } CHECK(!isPending()) << "Future was in PENDING after await()"; - + // We can't use CHECK_READY here due to check.hpp depending on future.hpp. if (!isReady()) { - if (isFailed()) { - std::cerr << "Future::get() but state == FAILED: " - << failure() << std::endl; - } else if (isDiscarded()) { - std::cerr << "Future::get() but state == DISCARDED" << std::endl; - } - abort(); + CHECK(!isFailed()) << "Future::get() but state == FAILED: " << failure(); + CHECK(!isDiscarded()) << "Future::get() but state == DISCARDED"; } assert(data->t != NULL); http://git-wip-us.apache.org/repos/asf/mesos/blob/e2f56042/3rdparty/libprocess/include/process/subprocess.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/subprocess.hpp b/3rdparty/libprocess/include/process/subprocess.hpp index 452eeea..d16cbc1 100644 --- a/3rdparty/libprocess/include/process/subprocess.hpp +++ b/3rdparty/libprocess/include/process/subprocess.hpp @@ -148,20 +148,7 @@ inline Try<Subprocess> subprocess(const std::string& command) execl("/bin/sh", "sh", "-c", command.c_str(), (char *) NULL); - // Write the failure message in an async-signal safe manner, - // assuming strlen is async-signal safe or optimized out. - // In fact, it is highly unlikely that strlen would be - // implemented in an unsafe manner: - // http://austingroupbugs.net/view.php?id=692 - const char* message = "Failed to execl '/bin sh -c "; - while (write(STDERR_FILENO, message, strlen(message)) == -1 && - errno == EINTR); - while (write(STDERR_FILENO, command.c_str(), command.size()) == -1 && - errno == EINTR); - while (write(STDERR_FILENO, "'\n", strlen("'\n")) == -1 && - errno == EINTR); - - _exit(1); + ABORT("Failed to execl '/bin sh -c ", command.c_str(), "'\n"); } // Parent.
