0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 16:33:53 +01:00

ircd::mods: Add unload() to unload all modules.

This commit is contained in:
Jason Volk 2016-09-09 16:14:29 -07:00
parent 0dbb0d4af5
commit 090def32d2
4 changed files with 34 additions and 1 deletions

View file

@ -118,6 +118,7 @@ bool reload(const std::string name);
bool unload(const std::string name);
bool load(const std::string &name);
void autoload();
void unload();
template<class T>

View file

@ -150,6 +150,8 @@ void
ircd::main_exiting()
noexcept try
{
mods::unload();
if(main_exit_func)
{
log::debug("Notifying user of IRCd completion");

View file

@ -79,8 +79,19 @@ catch(const boost::system::system_error &e)
}
mod::~mod()
noexcept
noexcept try
{
handle.unload();
assert(!handle.is_loaded());
}
catch(const std::exception &e)
{
log::critical("Module @%p unload: %s",
(const void *)this,
e.what());
if(!ircd::debugmode)
return;
}
template<class T>

View file

@ -103,6 +103,25 @@ void load_symbol(mod &mod, const std::string &name, const std::type_index &);
} // namespace mods
} // namespace ircd
void
ircd::mods::unload()
{
log.info("Unloading %zu (all) modules...", mods.size());
// Proper way to unload is by name; don't just clear the map.
std::vector<std::string> names(mods.size());
std::transform(begin(mods), end(mods), begin(names), []
(const auto &pit)
{
return pit.first;
});
for(const auto &name : names)
unload(name);
log.info("Unloaded all modules.");
}
void
ircd::mods::autoload()
{