diff --git a/CMakeLists.txt b/CMakeLists.txt index d717ef717..fb764ad45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1849,7 +1849,6 @@ else () src/ripple/core/impl/SNTPClock.cpp src/ripple/core/impl/SociDB.cpp src/ripple/core/impl/Stoppable.cpp - src/ripple/core/impl/TerminateHandler.cpp src/ripple/core/impl/TimeKeeper.cpp src/ripple/core/impl/Workers.cpp #[===============================[ @@ -2133,7 +2132,6 @@ else () src/test/core/JobQueue_test.cpp src/test/core/SociDB_test.cpp src/test/core/Stoppable_test.cpp - src/test/core/TerminateHandler_test.cpp src/test/core/Workers_test.cpp #[===============================[ nounity, test sources: diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index 0b8115e0d..2e91535ff 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -766,8 +765,6 @@ int main (int argc, char** argv) atexit(&google::protobuf::ShutdownProtobufLibrary); - std::set_terminate(ripple::terminateHandler); - auto const result (ripple::run (argc, argv)); beast::basic_seconds_clock_main_hook(); diff --git a/src/ripple/core/TerminateHandler.h b/src/ripple/core/TerminateHandler.h deleted file mode 100644 index b1939ea6b..000000000 --- a/src/ripple/core/TerminateHandler.h +++ /dev/null @@ -1,30 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012 - 2017 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef RIPPLE_CORE_TERMINATE_HANDLER_H_INCLUDED -#define RIPPLE_CORE_TERMINATE_HANDLER_H_INCLUDED - -namespace ripple -{ - -void terminateHandler(); - -} // ripple - -#endif diff --git a/src/ripple/core/impl/TerminateHandler.cpp b/src/ripple/core/impl/TerminateHandler.cpp deleted file mode 100644 index 5ea1a4dc1..000000000 --- a/src/ripple/core/impl/TerminateHandler.cpp +++ /dev/null @@ -1,68 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012 - 2017 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include -#include -#include - -#include -#include -#include -#include - -namespace ripple { - -void terminateHandler() -{ - if (std::current_exception()) - { - auto const thName = - beast::getCurrentThreadName().value_or("Unknown"); - try - { - throw; - } - catch (const std::exception& e) - { - auto exName = typeid (e).name(); - std::cerr - << "Terminating thread " << thName << ": unhandled " - << exName << " '" << e.what () << "'\n"; - JLOG(debugLog().fatal()) - << "Terminating thread " << thName << ": unhandled " - << exName << " '" << e.what () << "'\n"; - } - catch (boost::coroutines::detail::forced_unwind const&) - { - std::cerr - << "Terminating thread " << thName << ": forced_unwind\n"; - JLOG(debugLog().fatal()) - << "Terminating thread " << thName << ": forced_unwind\n"; - } - catch (...) - { - std::cerr - << "Terminating thread " << thName << ": unknown exception\n"; - JLOG (debugLog().fatal()) - << "Terminating thread " << thName << ": unknown exception\n"; - } - } -} - -} diff --git a/src/ripple/unity/core.cpp b/src/ripple/unity/core.cpp index 541ef021c..25a699088 100644 --- a/src/ripple/unity/core.cpp +++ b/src/ripple/unity/core.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/src/test/core/TerminateHandler_test.cpp b/src/test/core/TerminateHandler_test.cpp deleted file mode 100644 index 7d09a07c8..000000000 --- a/src/test/core/TerminateHandler_test.cpp +++ /dev/null @@ -1,152 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2016 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include -#include -#include - -#include -#include -#include -#include - -namespace ripple { -namespace test { - -class TerminateHandler_test : public beast::unit_test::suite -{ -private: - // Allow cerr to be redirected. Destructor restores old cerr streambuf. - class CerrRedirect - { - public: - explicit CerrRedirect (std::stringstream& sStream) - : old_ (std::cerr.rdbuf (sStream.rdbuf())) - { } - - ~CerrRedirect() - { - std::cerr.rdbuf (old_); - } - - private: - std::streambuf* const old_; - }; - - // Set a new current thread name. Destructor restores the old thread name. - class ThreadNameGuard - { - public: - explicit ThreadNameGuard (std::string const& newName) - : old_ (beast::getCurrentThreadName ()) - { - beast::setCurrentThreadName (newName); - } - - ~ThreadNameGuard() - { - std::string oldName; - if (old_) - oldName = std::move (*old_); - - beast::setCurrentThreadName (oldName); - } - - private: - boost::optional old_; - }; - -public: - void - run() override - { - // Set the current thread name, but restore the old name on exit. - std::string const threadName {"terminateHandler_test"}; - ThreadNameGuard nameGuard {threadName}; - { - // Test terminateHandler() with a std::exception. - - // The terminateHandler() output goes to std::cerr. Capture that. - std::stringstream cerrCapture; - CerrRedirect cerrRedirect {cerrCapture}; - - try - { - throw std::range_error ("Out of range"); - } - catch (...) - { - terminateHandler(); - } - { - std::string result = cerrCapture.str(); - BEAST_EXPECT (result.find (threadName) != std::string::npos); - BEAST_EXPECT ( - result.find ("Out of range") != std::string::npos); - } - } - - { - // Verify terminateHnadler() handles forced_unwind correctly. - std::stringstream cerrCapture; - CerrRedirect cerrRedirect {cerrCapture}; - - try - { - throw boost::coroutines::detail::forced_unwind(); - } - catch (...) - { - terminateHandler(); - } - { - std::string result = cerrCapture.str(); - BEAST_EXPECT (result.find (threadName) != std::string::npos); - BEAST_EXPECT ( - result.find ("forced_unwind") != std::string::npos); - } - } - - { - // Verify terminatHandler()'s handling of non-standard exceptions. - std::stringstream cerrCapture; - CerrRedirect cerrRedirect {cerrCapture}; - - try - { - throw 7; - } - catch (...) - { - terminateHandler(); - } - { - std::string result = cerrCapture.str(); - BEAST_EXPECT (result.find (threadName) != std::string::npos); - BEAST_EXPECT ( - result.find ("unknown exception") != std::string::npos); - } - } - } -}; - -BEAST_DEFINE_TESTSUITE(TerminateHandler,core,ripple); - -} // test -} // ripple diff --git a/src/test/unity/core_test_unity.cpp b/src/test/unity/core_test_unity.cpp index 2db132918..824fde026 100644 --- a/src/test/unity/core_test_unity.cpp +++ b/src/test/unity/core_test_unity.cpp @@ -25,5 +25,4 @@ #include #include #include -#include #include