0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-01 21:28:53 +02:00

ircd::mapi: Improve the stuck-module message by showing it immediately.

This commit is contained in:
Jason Volk 2016-09-24 19:45:37 -07:00
parent 6115671122
commit 1da6aa2b93
3 changed files with 20 additions and 11 deletions

View file

@ -110,14 +110,7 @@ inline
header::~header() header::~header()
noexcept noexcept
{ {
if(ircd::main_exited) mods::static_destruction = true;
{
// When central IRCd thinks this module is already unloaded when at this point,
// the DSO got stuck. This will not assert, but warn the developer to fix it.
const auto &name(meta["name"]);
log::warning("Module \"%s\" is stuck and failing to unload.", name.c_str());
log::warning("Module \"%s\" may result in undefined behavior if not fixed.", name.c_str());
}
} }
const char *const const char *const

View file

@ -62,8 +62,6 @@ const std::string &desc(const mod &);
std::string location(const mod &); std::string location(const mod &);
std::string name(const mod &); std::string name(const mod &);
extern struct log::log log;
// Symbol handlers // Symbol handlers
struct type_handlers struct type_handlers
{ {
@ -121,6 +119,9 @@ bool load(const std::string &name);
void autoload(); void autoload();
void unload(); void unload();
extern struct log::log log;
extern bool static_destruction;
// Initialization and destruction singleton held by ircd::main() // Initialization and destruction singleton held by ircd::main()
struct init struct init
{ {

View file

@ -199,6 +199,12 @@ catch(const std::exception &e)
throw; throw;
} }
// Allows module to communicate static destruction is taking place when mapi::header
// destructs. This allows us to gauge if the module *really* unloaded on command. DSO's
// are allowed to silently refuse to unload for any reason. We prefer developers to do
// things that don't trigger such behavior and allow a clean unload.
bool ircd::mods::static_destruction;
bool bool
ircd::mods::unload(const std::string name) ircd::mods::unload(const std::string name)
{ {
@ -215,8 +221,17 @@ ircd::mods::unload(const std::string name)
unload_symbol(mod, name, sym.type); unload_symbol(mod, name, sym.type);
} }
static_destruction = false;
mods.erase(it); mods.erase(it);
log.info("Module '%s' unloaded", filename.c_str());
if(!static_destruction)
{
log.error("Module \"%s\" is stuck and failing to unload.", name.c_str());
log.warning("Module \"%s\" may result in undefined behavior if not fixed.", name.c_str());
} else {
log.info("Module '%s' unloaded", filename.c_str());
}
return true; return true;
} }