Repository: mesos Updated Branches: refs/heads/master 4c6985e63 -> 5f46778bb
Introduced ABORT as alternative to fatal. Review: https://reviews.apache.org/r/18549 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5f46778b Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5f46778b Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5f46778b Branch: refs/heads/master Commit: 5f46778bb20a3033abafd97804ea687376e38c7f Parents: 4c6985e Author: Dominic Hamon <[email protected]> Authored: Wed Mar 5 17:01:18 2014 -0800 Committer: Benjamin Hindman <[email protected]> Committed: Wed Mar 5 17:01:18 2014 -0800 ---------------------------------------------------------------------- 3rdparty/libprocess/3rdparty/stout/Makefile.am | 1 + .../3rdparty/stout/include/stout/abort.hpp | 78 ++++++++++++++++++++ .../3rdparty/stout/include/stout/check.hpp | 34 ++++----- .../stout/include/stout/os/sendfile.hpp | 7 +- 4 files changed, 97 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/5f46778b/3rdparty/libprocess/3rdparty/stout/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am b/3rdparty/libprocess/3rdparty/stout/Makefile.am index b1d60ae..b53a3f1 100644 --- a/3rdparty/libprocess/3rdparty/stout/Makefile.am +++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am @@ -5,6 +5,7 @@ ACLOCAL_AMFLAGS = -I m4 AUTOMAKE_OPTIONS = foreign EXTRA_DIST = \ + include/stout/abort.hpp \ include/stout/bytes.hpp \ include/stout/cache.hpp \ include/stout/check.hpp \ http://git-wip-us.apache.org/repos/asf/mesos/blob/5f46778b/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp new file mode 100644 index 0000000..d43f1b5 --- /dev/null +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp @@ -0,0 +1,78 @@ +/** + * 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 __STOUT_ABORT_HPP__ +#define __STOUT_ABORT_HPP__ + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +// Signal safe abort which prints a message. +#define __STRINGIZE(x) #x +#define _STRINGIZE(x) __STRINGIZE(x) +#define _ABORT_PREFIX "ABORT: (" __FILE__ ":" _STRINGIZE(__LINE__) "): " + +#define ABORT(...) _Abort(_ABORT_PREFIX)(__VA_ARGS__) + +struct _Abort +{ + _Abort(const char* _prefix) : prefix(_prefix) {} + + void operator () ( + const char* arg0 = NULL, + const char* arg1 = NULL, + const char* arg2 = NULL, + const char* arg3 = NULL, + const char* arg4 = NULL, + const char* arg5 = NULL, + const char* arg6 = NULL, + const char* arg7 = NULL, + const char* arg8 = NULL, + const char* arg9 = 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 + while (write(STDERR_FILENO, prefix, strlen(prefix)) == -1 && errno == EINTR); + while (arg0 != NULL && + write(STDERR_FILENO, arg0, strlen(arg0)) == -1 && errno == EINTR); + while (arg1 != NULL && + write(STDERR_FILENO, arg1, strlen(arg1)) == -1 && errno == EINTR); + while (arg2 != NULL && + write(STDERR_FILENO, arg2, strlen(arg2)) == -1 && errno == EINTR); + while (arg3 != NULL && + write(STDERR_FILENO, arg3, strlen(arg3)) == -1 && errno == EINTR); + while (arg4 != NULL && + write(STDERR_FILENO, arg4, strlen(arg4)) == -1 && errno == EINTR); + while (arg5 != NULL && + write(STDERR_FILENO, arg5, strlen(arg5)) == -1 && errno == EINTR); + while (arg6 != NULL && + write(STDERR_FILENO, arg6, strlen(arg6)) == -1 && errno == EINTR); + while (arg7 != NULL && + write(STDERR_FILENO, arg7, strlen(arg7)) == -1 && errno == EINTR); + while (arg8 != NULL && + write(STDERR_FILENO, arg8, strlen(arg8)) == -1 && errno == EINTR); + while (arg9 != NULL && + write(STDERR_FILENO, arg9, strlen(arg9)) == -1 && errno == EINTR); + abort(); + } + + const char* prefix; +}; + +#endif // __STOUT_ABORT_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/5f46778b/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp index 695db20..4b93aa0 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp @@ -18,8 +18,9 @@ #include <sstream> #include <string> -#include <glog/logging.h> // Includes LOG(*), PLOG(*), CHECK, etc. +#include <glog/logging.h> +#include <stout/abort.hpp> #include <stout/none.hpp> #include <stout/option.hpp> #include <stout/result.hpp> @@ -29,10 +30,11 @@ // Provides a CHECK_SOME 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_SOME(expression) \ - for (const Option<std::string>& _error = _check(expression); \ - _error.isSome();) \ - _CheckSome(__FILE__, __LINE__, #expression, _error.get()).stream() \ +#define CHECK_SOME(expression) \ + for (const Option<std::string>& _error = _check(expression); \ + _error.isSome();) \ + _CheckFatal(__FILE__, __LINE__, "CHECK_SOME", \ + #expression, _error.get()).stream() // Private structs/functions used for CHECK_SOME. @@ -68,23 +70,21 @@ Option<std::string> _check(const Result<T>& r) } -struct _CheckSome +struct _CheckFatal { - _CheckSome(const char* _file, + _CheckFatal(const char* _file, int _line, - const char* _expression, - const std::string& _error) - : file(_file), - line(_line), - expression(_expression), - error(_error) + const char* type, + const char* expression, + const std::string& error) + : file(_file), + line(_line) { - out << "CHECK_SOME(" << expression << "): "; + out << type << "(" << expression << "): " << error; } - ~_CheckSome() + ~_CheckFatal() { - out << error; google::LogMessageFatal(file.c_str(), line).stream() << out.str(); } @@ -95,8 +95,6 @@ struct _CheckSome const std::string file; const int line; - const std::string expression; - const std::string error; std::ostringstream out; }; http://git-wip-us.apache.org/repos/asf/mesos/blob/5f46778b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp index 3350929..5607896 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp @@ -25,10 +25,8 @@ #include <sys/uio.h> #endif // __APPLE__ -#ifdef __linux__ -#include <stout/fatal.hpp> -#endif // __linux__ #include <stout/os/signals.hpp> +#include <stout/unreachable.hpp> namespace os { @@ -46,8 +44,7 @@ inline ssize_t sendfile(int s, int fd, off_t offset, size_t length) // This will set errno to EPIPE if a SIGPIPE occurs. return ::sendfile(s, fd, &offset, length); } - fatal("Unreachable statement"); - return -1; + return UNREACHABLE(); #elif defined __APPLE__ // On OS X, sendfile does not need to have SIGPIPE suppressed. off_t _length = static_cast<off_t>(length);
