mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
ircd: Wrap the std::terminate() handler and add some related toys.
This commit is contained in:
parent
f81a9d8da9
commit
a046a56d0d
8 changed files with 77 additions and 12 deletions
|
@ -29,6 +29,14 @@
|
|||
namespace ircd
|
||||
{
|
||||
struct exception;
|
||||
|
||||
// Prefer ircd::terminate() to std::terminate() if possible.
|
||||
[[noreturn]] void terminate(const std::exception &) noexcept;
|
||||
[[noreturn]] void terminate(std::exception_ptr) noexcept;
|
||||
[[noreturn]] void terminate() noexcept;
|
||||
|
||||
// Can be used to clobber the std::terminate_handler
|
||||
void aborting() noexcept;
|
||||
}
|
||||
|
||||
/// The root exception type.
|
||||
|
|
|
@ -1469,7 +1469,7 @@ catch(const std::exception &e)
|
|||
{
|
||||
_continue = false;
|
||||
log::critical("iov::handler: cfid[%u]: %s", cfid, e.what());
|
||||
std::terminate();
|
||||
ircd::terminate();
|
||||
}
|
||||
|
||||
rocksdb::Status
|
||||
|
|
|
@ -46,3 +46,49 @@ noexcept
|
|||
|
||||
return size;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::terminate()
|
||||
noexcept
|
||||
{
|
||||
terminate(std::current_exception());
|
||||
}
|
||||
|
||||
void
|
||||
ircd::terminate(std::exception_ptr eptr)
|
||||
noexcept
|
||||
{
|
||||
if(eptr) try
|
||||
{
|
||||
std::rethrow_exception(eptr);
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
terminate(e);
|
||||
}
|
||||
|
||||
log::critical("IRCd Terminate without exception");
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
void
|
||||
ircd::terminate(const std::exception &e)
|
||||
noexcept
|
||||
{
|
||||
log::critical("IRCd Terminated: %s", e.what());
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
[[noreturn]] static void
|
||||
ircd_terminate_handler()
|
||||
noexcept
|
||||
{
|
||||
std::abort();
|
||||
}
|
||||
|
||||
void
|
||||
ircd::aborting()
|
||||
noexcept
|
||||
{
|
||||
std::set_terminate(&ircd_terminate_handler);
|
||||
}
|
||||
|
|
16
ircd/ircd.cc
16
ircd/ircd.cc
|
@ -287,11 +287,21 @@ catch(const ctx::interrupted &e)
|
|||
{
|
||||
log::warning("IRCd main interrupted...");
|
||||
}
|
||||
#ifndef RB_DEBUG
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::critical("IRCd terminated: %s", e.what());
|
||||
std::terminate();
|
||||
// When not in debug mode this is a clean return to not crash through
|
||||
// the embedder's ios.run() which would terminate the rest of their
|
||||
// program. Instead they have the right to handle the error and try again.
|
||||
log::critical("IRCd main exited: %s", e.what());
|
||||
}
|
||||
#else
|
||||
catch(...)
|
||||
{
|
||||
// In debug mode we terminate with a message and a coredump
|
||||
ircd::terminate();
|
||||
}
|
||||
#endif // RB_DEBUG
|
||||
|
||||
void
|
||||
ircd::at_main_exit()
|
||||
|
@ -344,7 +354,7 @@ catch(const std::exception &e)
|
|||
reflect(new_runlevel),
|
||||
e.what());
|
||||
|
||||
std::terminate();
|
||||
ircd::terminate();
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
|
|
|
@ -1228,13 +1228,13 @@ ircd::js::trap::from(const JSObject *const &o)
|
|||
if(!c)
|
||||
{
|
||||
log.critical("trap::from(): Trapped on an object without a JSClass!");
|
||||
std::terminate(); //TODO: exception
|
||||
ircd::terminate(); //TODO: exception
|
||||
}
|
||||
|
||||
if(!c->reserved[0])
|
||||
{
|
||||
log.critical("trap::from(): Trap called on a trap instance that has gone out of scope!");
|
||||
std::terminate(); //TODO: exception
|
||||
ircd::terminate(); //TODO: exception
|
||||
}
|
||||
|
||||
return *static_cast<trap *>(c->reserved[0]); //TODO: ???
|
||||
|
@ -3453,7 +3453,7 @@ noexcept try
|
|||
catch(const std::exception &e)
|
||||
{
|
||||
log.critical("triple fault: %s\n", e.what());
|
||||
std::terminate();
|
||||
ircd::terminate();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -4290,7 +4290,7 @@ __attribute__((noreturn))
|
|||
js::ReportOutOfMemory(ExclusiveContext *const c)
|
||||
{
|
||||
ircd::js::log.critical("jsalloc(): Reported out of memory (ExclusiveContext: %p)", (const void *)c);
|
||||
std::terminate();
|
||||
ircd::terminate();
|
||||
}
|
||||
#endif //IRCD_JS_FIX
|
||||
|
||||
|
|
|
@ -465,7 +465,7 @@ catch(const std::exception &e)
|
|||
fprintf(stdout, "%s\n", e.what());
|
||||
fflush(stderr);
|
||||
fflush(stdout);
|
||||
std::terminate();
|
||||
ircd::terminate();
|
||||
}
|
||||
|
||||
const char *
|
||||
|
|
|
@ -135,6 +135,7 @@ try
|
|||
catch(const m::error &e)
|
||||
{
|
||||
log.critical("%s %s", e.what(), e.content);
|
||||
throw;
|
||||
}
|
||||
|
||||
ircd::m::init::~init()
|
||||
|
@ -148,7 +149,7 @@ noexcept try
|
|||
catch(const m::error &e)
|
||||
{
|
||||
log.critical("%s %s", e.what(), e.content);
|
||||
std::terminate();
|
||||
ircd::terminate();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -356,7 +356,7 @@ catch(const std::exception &e)
|
|||
(const void *)tid,
|
||||
e.what());
|
||||
|
||||
std::terminate();
|
||||
ircd::terminate();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -389,7 +389,7 @@ catch(const std::exception &e)
|
|||
debug(mode, num, file, line),
|
||||
e.what());
|
||||
|
||||
std::terminate();
|
||||
ircd::terminate();
|
||||
}
|
||||
|
||||
std::string
|
||||
|
|
Loading…
Reference in a new issue