You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2014/10/14 10:21:42 UTC
[1/2] git commit: stout: Always use stout ABORT() rather than system
abort()
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 <co...@mesosphere.io>
Authored: Tue Oct 14 00:21:55 2014 -0700
Committer: Adam B <ad...@mesosphere.io>
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; }
[2/2] git commit: libprocess: Always use stout ABORT() rather than
system abort()
Posted by me...@apache.org.
libprocess: 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>.
Review: https://reviews.apache.org/r/26473
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3eb58598
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3eb58598
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3eb58598
Branch: refs/heads/master
Commit: 3eb585981b95801eae174a8ff52d581f20b09247
Parents: c713c5d
Author: Cody Maloney <co...@mesosphere.io>
Authored: Tue Oct 14 00:24:26 2014 -0700
Committer: Adam B <ad...@mesosphere.io>
Committed: Tue Oct 14 00:24:52 2014 -0700
----------------------------------------------------------------------
3rdparty/libprocess/include/process/event.hpp | 4 ++--
3rdparty/libprocess/include/process/http.hpp | 6 ++----
3rdparty/libprocess/include/process/socket.hpp | 7 ++-----
3rdparty/libprocess/src/httpd.cpp | 9 +--------
3rdparty/libprocess/src/synchronized.hpp | 9 +++------
5 files changed, 10 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3eb58598/3rdparty/libprocess/include/process/event.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/event.hpp b/3rdparty/libprocess/include/process/event.hpp
index bf689d7..294e215 100644
--- a/3rdparty/libprocess/include/process/event.hpp
+++ b/3rdparty/libprocess/include/process/event.hpp
@@ -6,6 +6,7 @@
#include <process/message.hpp>
#include <process/socket.hpp>
+#include <stout/abort.hpp>
#include <stout/lambda.hpp>
#include <stout/memory.hpp> // TODO(benh): Replace shared_ptr with unique_ptr.
@@ -63,8 +64,7 @@ struct Event
} visitor(&result);
visit(&visitor);
if (result == NULL) {
- std::cerr << "Attempting to \"cast\" event incorrectly!" << std::endl;
- abort();
+ ABORT("Attempting to \"cast\" event incorrectly!");
}
return *result;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/3eb58598/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index d540775..9cf05ac 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -494,10 +494,8 @@ inline Try<std::string> decode(const std::string& s)
unsigned long l;
in >> std::hex >> l;
if (l > UCHAR_MAX) {
- std::cerr << "Unexpected conversion from hex string: "
- << s.substr(i + 1, 2) << " to unsigned long: "
- << l << std::endl;
- abort();
+ ABORT("Unexpected conversion from hex string: " + s.substr(i + 1, 2) +
+ " to unsigned long: " + stringify(l));
}
out << static_cast<unsigned char>(l);
http://git-wip-us.apache.org/repos/asf/mesos/blob/3eb58598/3rdparty/libprocess/include/process/socket.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/socket.hpp b/3rdparty/libprocess/include/process/socket.hpp
index dbcb4f4..6683881 100644
--- a/3rdparty/libprocess/include/process/socket.hpp
+++ b/3rdparty/libprocess/include/process/socket.hpp
@@ -2,10 +2,8 @@
#define __PROCESS_SOCKET_HPP__
#include <assert.h>
-#include <unistd.h> // For close.
-
-#include <iostream>
+#include <stout/abort.hpp>
#include <stout/nothing.hpp>
#include <stout/os.hpp>
#include <stout/try.hpp>
@@ -94,8 +92,7 @@ private:
if (s >= 0) {
Try<Nothing> close = os::close(s);
if (close.isError()) {
- std::cerr << "Failed to close socket: " << close.error() << std::endl;
- abort();
+ ABORT("Failed to close socket: " + close.error());
}
}
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/3eb58598/3rdparty/libprocess/src/httpd.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/httpd.cpp b/3rdparty/libprocess/src/httpd.cpp
index eab3aa5..902ba89 100644
--- a/3rdparty/libprocess/src/httpd.cpp
+++ b/3rdparty/libprocess/src/httpd.cpp
@@ -29,12 +29,6 @@ using std::map;
using process::tuple::Tuple;
-#define malloc(bytes) \
- ({ void *tmp; if ((tmp = malloc(bytes)) == NULL) abort(); tmp; })
-
-#define realloc(address, bytes) \
- ({ void *tmp; if ((tmp = realloc(address, bytes)) == NULL) abort(); tmp; })
-
#define HTTP_500 \
"HTTP/1.1 500 Internal Server Error\r\n\r\n"
@@ -94,8 +88,7 @@ public:
http_parser_execute(&parser, raw.c_str(), raw.length());
if (http_parser_has_error(&parser)) {
- //cerr << "parser error" << endl;
- abort();
+ ABORT("parser error");
}
return message;
http://git-wip-us.apache.org/repos/asf/mesos/blob/3eb58598/3rdparty/libprocess/src/synchronized.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/synchronized.hpp b/3rdparty/libprocess/src/synchronized.hpp
index 70f6cd0..6a341b8 100644
--- a/3rdparty/libprocess/src/synchronized.hpp
+++ b/3rdparty/libprocess/src/synchronized.hpp
@@ -34,8 +34,7 @@ public:
void acquire()
{
if (!initialized) {
- std::cerr << "synchronizable not initialized" << std::endl;
- abort();
+ ABORT("synchronizable not initialized");
}
pthread_mutex_lock(&mutex);
}
@@ -43,8 +42,7 @@ public:
void release()
{
if (!initialized) {
- std::cerr << "synchronizable not initialized" << std::endl;
- abort();
+ ABORT("synchronizable not initialized");
}
pthread_mutex_unlock(&mutex);
}
@@ -60,8 +58,7 @@ private:
pthread_mutexattr_destroy(&attr);
initialized = true;
} else {
- std::cerr << "synchronizable already initialized" << std::endl;
- abort();
+ ABORT("synchronizable already initialized");
}
}