Repository: mesos Updated Branches: refs/heads/master 555d0580e -> 3eb585981
stout: Always use stout ABORT() rather than system abort() This makes it so any time there is an abort, we get a line number and at least a basic message as to why there was an abort. If you want a clean(er) exit, use <stout/exit>. Also adds an overload which takes a standard string and unwraps it to a const char * automatically, since a lot of the time we are building strings to pass them to abort. Review: https://reviews.apache.org/r/26472 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c713c5d1 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c713c5d1 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c713c5d1 Branch: refs/heads/master Commit: c713c5d194a43006a788ef6217753f10845949b0 Parents: 555d058 Author: Cody Maloney <[email protected]> Authored: Tue Oct 14 00:21:55 2014 -0700 Committer: Adam B <[email protected]> Committed: Tue Oct 14 00:22:21 2014 -0700 ---------------------------------------------------------------------- .../3rdparty/stout/include/stout/abort.hpp | 6 ++++++ .../3rdparty/stout/include/stout/flags/flags.hpp | 10 ++-------- .../libprocess/3rdparty/stout/include/stout/net.hpp | 8 +++----- .../3rdparty/stout/include/stout/os/fork.hpp | 8 ++++---- .../3rdparty/stout/include/stout/protobuf.hpp | 12 ++++++------ .../3rdparty/stout/include/stout/result.hpp | 11 +++++------ .../3rdparty/stout/include/stout/stringify.hpp | 6 ++---- .../3rdparty/stout/include/stout/thread.hpp | 15 ++++++++------- .../libprocess/3rdparty/stout/include/stout/try.hpp | 5 ++--- .../libprocess/3rdparty/stout/tests/os_tests.cpp | 3 +-- support/apply-review.sh | 3 ++- 11 files changed, 41 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/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 index 6b5b5d1..4a26736 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp @@ -44,4 +44,10 @@ inline __attribute__((noreturn)) void _Abort( abort(); } +inline __attribute__((noreturn)) void _Abort( + const char *prefix, + const std::string &msg) { + _Abort(prefix, msg.c_str()); +} + #endif // __STOUT_ABORT_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp index 9d244b2..f4b7a95 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp @@ -14,8 +14,6 @@ #ifndef __STOUT_FLAGS_FLAGS_HPP__ #define __STOUT_FLAGS_FLAGS_HPP__ -#include <stdlib.h> // For abort. - #include <map> #include <string> #include <typeinfo> // For typeid. @@ -221,9 +219,7 @@ void FlagsBase::add( { Flags* flags = dynamic_cast<Flags*>(this); if (flags == NULL) { - std::cerr << "Attempted to add flag '" << name - << "' with incompatible type" << std::endl; - abort(); + ABORT("Attempted to add flag '" + name + "' with incompatible type"); } else { flags->*t1 = t2; // Set the default. } @@ -264,9 +260,7 @@ void FlagsBase::add( { Flags* flags = dynamic_cast<Flags*>(this); if (flags == NULL) { - std::cerr << "Attempted to add flag '" << name - << "' with incompatible type" << std::endl; - abort(); + ABORT("Attempted to add flag '" + name + "' with incompatible type"); } Flag flag; http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp index 7138bc2..a992bd9 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/net.hpp @@ -439,11 +439,9 @@ inline std::ostream& operator << (std::ostream& stream, const IP& ip) if (str == NULL) { // We do not expect inet_ntop to fail because all parameters // passed in are valid. - std::string message = - "inet_ntop returns error for address " + stringify(ip.address()); - - perror(message.c_str()); - abort(); + const char *error_msg = strerror(errno); + ABORT("inet_ntop returns error for address " + stringify(ip.address()) + + ": " + error_msg); } stream << str; http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/3rdparty/libprocess/3rdparty/stout/include/stout/os/fork.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/fork.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/fork.hpp index 8aa21ed..3832d95 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/fork.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/fork.hpp @@ -25,6 +25,7 @@ #include <set> #include <string> +#include <stout/abort.hpp> #include <stout/error.hpp> #include <stout/exit.hpp> #include <stout/foreach.hpp> @@ -259,12 +260,11 @@ private: void operator () (Tree::Memory* process) const { if (munmap(process, sizeof(Tree::Memory)) == -1) { - perror("Failed to unmap memory"); - abort(); + ABORT(std::string("Failed to unmap memory: ") + strerror(errno)); } if (::close(fd) == -1) { - perror("Failed to close shared memory file descriptor"); - abort(); + ABORT(std::string("Failed to close shared memory file descriptor: ") + + strerror(errno)); } } http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp index ccf80a7..3b30ab7 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp @@ -32,11 +32,13 @@ #include <boost/lexical_cast.hpp> +#include "abort.hpp" #include "error.hpp" #include "json.hpp" #include "none.hpp" #include "os.hpp" #include "result.hpp" +#include "stringify.hpp" #include "try.hpp" namespace protobuf { @@ -553,9 +555,8 @@ struct Protobuf case google::protobuf::FieldDescriptor::TYPE_GROUP: // Deprecated! default: - std::cerr << "Unhandled protobuf field type: " << field->type() - << std::endl; - abort(); + ABORT("Unhandled protobuf field type: " + + stringify(field->type())); } } object.values[field->name()] = array; @@ -614,9 +615,8 @@ struct Protobuf case google::protobuf::FieldDescriptor::TYPE_GROUP: // Deprecated! default: - std::cerr << "Unhandled protobuf field type: " << field->type() - << std::endl; - abort(); + ABORT("Unhandled protobuf field type: " + + stringify(field->type())); } } } http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp index ce8dd9b..631f126 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp @@ -15,11 +15,11 @@ #define __STOUT_RESULT_HPP__ #include <assert.h> -#include <stdlib.h> // For abort. #include <iostream> #include <string> +#include <stout/abort.hpp> #include <stout/error.hpp> #include <stout/none.hpp> #include <stout/option.hpp> @@ -98,15 +98,14 @@ public: const T& get() const { - // TODO(dhamon): Switch this to fatal() once that calls abort(). if (state != SOME) { + std::string errorMessage = "Result::get() but state == "; if (state == ERROR) { - std::cerr << "Result::get() but state == ERROR: " - << error() << std::endl; + errorMessage += "ERROR: " + message; } else if (state == NONE) { - std::cerr << "Result::get() but state == NONE" << std::endl; + errorMessage += "NONE"; } - abort(); + ABORT(errorMessage); } return *t; } http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/3rdparty/libprocess/3rdparty/stout/include/stout/stringify.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/stringify.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/stringify.hpp index ed0a1ef..901b036 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/stringify.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/stringify.hpp @@ -14,8 +14,6 @@ #ifndef __STOUT_STRINGIFY_HPP__ #define __STOUT_STRINGIFY_HPP__ -#include <stdlib.h> // For 'abort'. - #include <iostream> // For 'std::cerr' and 'std::endl'. #include <list> #include <map> @@ -24,6 +22,7 @@ #include <string> #include <vector> +#include "abort.hpp" #include "hashmap.hpp" template <typename T> @@ -32,8 +31,7 @@ std::string stringify(T t) std::ostringstream out; out << t; if (!out.good()) { - std::cerr << "Failed to stringify!" << t << std::endl; - abort(); + ABORT("Failed to stringify!"); } return out.str(); } http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp index b1af74f..892246b 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp @@ -17,7 +17,8 @@ #include <errno.h> #include <pthread.h> #include <stdio.h> // For perror. -#include <stdlib.h> // For abort. + +#include <stout/abort.hpp> template <typename T> struct ThreadLocal @@ -27,8 +28,8 @@ struct ThreadLocal errno = pthread_key_create(&key, NULL); if (errno != 0) { - perror("Failed to create thread local, pthread_key_create"); - abort(); + ABORT(std::string("Failed to create thread local, pthread_key_create: ") + + strerror(errno)); } } @@ -37,8 +38,8 @@ struct ThreadLocal errno = pthread_key_delete(key); if (errno != 0) { - perror("Failed to destruct thread local, pthread_key_delete"); - abort(); + ABORT("Failed to destruct thread local, pthread_key_delete: " + + std::string(strerror(errno))); } } @@ -47,8 +48,8 @@ struct ThreadLocal errno = pthread_setspecific(key, t); if (errno != 0) { - perror("Failed to set thread local, pthread_setspecific"); - abort(); + ABORT(std::string("Failed to set thread local, pthread_setspecific: ") + + strerror(errno)); } return *this; } http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp index 87c5fc8..8150b70 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp @@ -15,11 +15,11 @@ #define __STOUT_TRY_HPP__ #include <assert.h> -#include <stdlib.h> // For abort. #include <iostream> #include <string> +#include <stout/abort.hpp> #include <stout/error.hpp> template <typename T> @@ -89,8 +89,7 @@ public: const T& get() const { if (state != SOME) { - std::cerr << "Try::get() but state == ERROR: " << error() << std::endl; - abort(); + ABORT("Try::get() but state == ERROR: " + message); } return *t; } http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/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 9207c55..898d175 100644 --- a/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp +++ b/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp @@ -471,8 +471,7 @@ TEST_F(OsTest, processes) void dosetsid(void) { if (::setsid() == -1) { - perror("Failed to setsid"); - abort(); + ABORT(string("Failed to setsid: ") + strerror(errno)); } } http://git-wip-us.apache.org/repos/asf/mesos/blob/c713c5d1/support/apply-review.sh ---------------------------------------------------------------------- diff --git a/support/apply-review.sh b/support/apply-review.sh index 66e35d3..75ac842 100755 --- a/support/apply-review.sh +++ b/support/apply-review.sh @@ -60,7 +60,7 @@ else DIFF_URL="${REVIEWBOARD_URL}/${REVIEW}/diff/raw/" fi -atexit "rm -f ${REVIEW}.patch" +#atexit "rm -f ${REVIEW}.patch" wget --no-check-certificate -O ${REVIEW}.patch ${DIFF_URL} || \ { echo "${RED}Failed to download patch${NORMAL}"; exit 1; } @@ -106,6 +106,7 @@ ${REVIEW_DETAILS} Review: ${REVIEW_URL} __EOF__ ) +echo "Successfully applied: ${MESSAGE}" git commit --author="${AUTHOR}" -am "${MESSAGE}" || \ { echo "${RED}Failed to commit patch${NORMAL}"; exit 1; }
