Repository: mesos Updated Branches: refs/heads/master 4635b66af -> 3b1e937ec
Added a SIGPIPE handler for the libprocess tests. Review: https://reviews.apache.org/r/38817 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3b1e937e Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3b1e937e Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3b1e937e Branch: refs/heads/master Commit: 3b1e937ec7c8c72ee960a4b51f1847c3cccb8d98 Parents: 4635b66 Author: Benjamin Mahler <[email protected]> Authored: Mon Sep 28 12:22:00 2015 -0700 Committer: Benjamin Mahler <[email protected]> Committed: Mon Sep 28 17:13:36 2015 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/src/tests/main.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/3b1e937e/3rdparty/libprocess/src/tests/main.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/tests/main.cpp b/3rdparty/libprocess/src/tests/main.cpp index eec0c5f..4a7b9b6 100644 --- a/3rdparty/libprocess/src/tests/main.cpp +++ b/3rdparty/libprocess/src/tests/main.cpp @@ -15,6 +15,7 @@ #include <signal.h> #include <glog/logging.h> +#include <glog/raw_logging.h> #include <gmock/gmock.h> @@ -26,6 +27,22 @@ #include <stout/os/signals.hpp> + +// NOTE: We use RAW_LOG instead of LOG because RAW_LOG doesn't +// allocate any memory or grab locks. And according to +// https://code.google.com/p/google-glog/issues/detail?id=161 +// it should work in 'most' cases in signal handlers. +inline void handler(int signal) +{ + if (signal == SIGPIPE) { + RAW_LOG(WARNING, "Received signal SIGPIPE; escalating to SIGABRT"); + raise(SIGABRT); + } else { + RAW_LOG(FATAL, "Unexpected signal in signal handler: %d", signal); + } +} + + int main(int argc, char** argv) { // Initialize Google Mock/Test. @@ -42,6 +59,11 @@ int main(int argc, char** argv) // results in a stack trace otherwise. os::signals::reset(SIGTERM); + // Set up the SIGPIPE signal handler to escalate to SIGABRT + // in order to have the glog handler catch it and print all + // of its lovely information. + os::signals::install(SIGPIPE, handler); + // Add the libprocess test event listeners. ::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners();
