Remove custom terminate handler

* Reduce the amount of code we have to maintain.
* Remove the potential for degrading stack dumps.
This commit is contained in:
Howard Hinnant
2018-11-16 14:40:45 -05:00
committed by Nik Bougalis
parent cc824685e7
commit 60dc949314
7 changed files with 0 additions and 257 deletions

View File

@@ -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:

View File

@@ -28,7 +28,6 @@
#include <ripple/core/Config.h>
#include <ripple/core/ConfigSections.h>
#include <ripple/core/DatabaseCon.h>
#include <ripple/core/TerminateHandler.h>
#include <ripple/core/TimeKeeper.h>
#include <ripple/json/to_string.h>
#include <ripple/net/RPCCall.h>
@@ -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();

View File

@@ -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

View File

@@ -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 <ripple/core/TerminateHandler.h>
#include <ripple/basics/Log.h>
#include <ripple/beast/core/CurrentThreadName.h>
#include <boost/coroutine/exceptions.hpp>
#include <exception>
#include <iostream>
#include <typeinfo>
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";
}
}
}
}

View File

@@ -26,7 +26,6 @@
#include <ripple/core/impl/JobQueue.cpp>
#include <ripple/core/impl/SNTPClock.cpp>
#include <ripple/core/impl/Stoppable.cpp>
#include <ripple/core/impl/TerminateHandler.cpp>
#include <ripple/core/impl/TimeKeeper.cpp>
#include <ripple/core/impl/Workers.cpp>

View File

@@ -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 <ripple/core/TerminateHandler.h>
#include <ripple/beast/core/CurrentThreadName.h>
#include <ripple/beast/unit_test.h>
#include <boost/coroutine/exceptions.hpp>
#include <exception>
#include <sstream>
#include <streambuf>
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<std::string> 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

View File

@@ -25,5 +25,4 @@
#include <test/core/JobQueue_test.cpp>
#include <test/core/SociDB_test.cpp>
#include <test/core/Stoppable_test.cpp>
#include <test/core/TerminateHandler_test.cpp>
#include <test/core/Workers_test.cpp>