0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::mods: Improve dlopen()/handle construction accoutrements.

This commit is contained in:
Jason Volk 2018-12-15 17:29:31 -08:00
parent 5d7f971b89
commit d7891d91e8

View file

@ -90,6 +90,8 @@ try
// and destruction but not during its lifetime.
const ctx::uninterruptible ui;
// This will be the terminate handler installed during the dlopen() and
// uninstalled after it completes.
const auto ours([]
{
log::critical
@ -99,20 +101,27 @@ try
};
});
// The existing terminate handler is saved here for restoration.
const auto theirs
{
std::get_terminate()
};
const unwind reset{[this, &theirs]
// Reference this instance at the top of the loading stack.
loading.emplace_front(this);
const unwind pop_loading{[this]
{
assert(loading.front() == this);
loading.pop_front();
}};
// Set the terminate handler for the duration of the dlopen().
std::set_terminate(ours);
const unwind pop_terminate{[&theirs]
{
std::set_terminate(theirs);
}};
loading.emplace_front(this);
std::set_terminate(ours);
return boost::dll::shared_library{path, mode};
}()}
,_name