Skip to content

Commit

Permalink
alias_resolve: perform an initial map refresh before going live
Browse files Browse the repository at this point in the history
It was possible for mail to be processed before any aliases were
loaded, which is not so good.

Fixes: gromox-2.14-63-gfc3305283
References: GXL-301
  • Loading branch information
jengelh committed Oct 11, 2024
1 parent 88932bc commit a5b8bf4
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions mda/alias_resolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,27 @@ static std::shared_ptr<domain_set> xa_refresh_domains(MYSQL *conn) try
return nullptr;
}

static void xa_refresh_once()
{
auto conn = sql_make_conn();
auto newmap = xa_refresh_aliases(conn);
auto newdom = xa_refresh_domains(conn);
std::unique_lock lk(xa_alias_lock);
if (newmap != nullptr)
xa_alias_map = std::move(newmap);
if (newdom != nullptr)
xa_domain_set = std::move(newdom);
}

static void xa_refresh_thread()
{
std::mutex slp_mtx;
while (!xa_notify_stop) {
{
auto conn = sql_make_conn();
auto newmap = xa_refresh_aliases(conn);
auto newdom = xa_refresh_domains(conn);
std::unique_lock lk(xa_alias_lock);
if (newmap != nullptr)
xa_alias_map = std::move(newmap);
if (newdom != nullptr)
xa_domain_set = std::move(newdom);
std::unique_lock slp_hold(slp_mtx);
xa_thread_wake.wait_for(slp_hold, g_cache_lifetime);
}
std::unique_lock slp_hold(slp_mtx);
xa_thread_wake.wait_for(slp_hold, g_cache_lifetime);
xa_refresh_once();
}
}

Expand Down Expand Up @@ -365,8 +370,10 @@ BOOL HOOK_alias_resolve(enum plugin_op reason, const struct dlfuncs &data)
strerror(errno));
return false;
}
if (!xa_reload_config(std::move(mcfg), std::move(acfg)) ||
!register_hook(xa_alias_subst))
if (!xa_reload_config(std::move(mcfg), std::move(acfg)))
return false;
xa_refresh_once();
if (!register_hook(xa_alias_subst))
return false;
try {
xa_thread = std::thread(xa_refresh_thread);
Expand Down

0 comments on commit a5b8bf4

Please sign in to comment.