From 1973e2c08692bc0d23d727a85a6784c8a0536e7f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 19 Mar 2023 22:04:17 -0700 Subject: [PATCH] construct: Fix the conf rehash interface for SIGUSR1. --- construct/homeserver.cc | 7 +++++++ construct/homeserver.h | 2 ++ construct/signals.cc | 16 +++++++++++----- include/ircd/m/homeserver.h | 1 + matrix/homeserver.cc | 14 ++++++++++++++ 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/construct/homeserver.cc b/construct/homeserver.cc index 0431b0b3c..aa9868e92 100644 --- a/construct/homeserver.cc +++ b/construct/homeserver.cc @@ -15,6 +15,9 @@ namespace fs = ircd::fs; using ircd::string_view; +decltype(construct::homeserver::primary) +construct::homeserver::primary; + construct::homeserver::homeserver(struct ircd::m::homeserver::opts opts) try :opts @@ -45,6 +48,8 @@ try } } { + assert(!primary); + primary = this; } catch(const std::exception &e) { @@ -59,4 +64,6 @@ catch(const std::exception &e) construct::homeserver::~homeserver() noexcept { + assert(primary); + primary = nullptr; } diff --git a/construct/homeserver.h b/construct/homeserver.h index a8b449840..d47569939 100644 --- a/construct/homeserver.h +++ b/construct/homeserver.h @@ -23,4 +23,6 @@ struct construct::homeserver public: homeserver(struct ircd::m::homeserver::opts); ~homeserver() noexcept; + + static homeserver *primary; }; diff --git a/construct/signals.cc b/construct/signals.cc index 4bc597687..5d1582893 100644 --- a/construct/signals.cc +++ b/construct/signals.cc @@ -8,9 +8,10 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. -#include // must include because asio.h.gch is fPIC +#include #include #include "construct.h" +#include "homeserver.h" #include "signals.h" #include "console.h" @@ -225,24 +226,29 @@ try return; } + if(!homeserver::primary || !homeserver::primary->module[0]) + return; + // This signal handler (though not a *real* signal handler) is still // running on the main async stack and not an ircd::ctx. The reload // function does a lot of IO so it requires an ircd::ctx. ircd::context{[] { - ircd::mods::import reload_conf + static ircd::mods::import rehash { - "s_conf", "reload_conf" + homeserver::primary->module[0], "ircd::m::homeserver::rehash" }; - reload_conf(); + assert(homeserver::primary->hs); + rehash(homeserver::primary->hs.get()); }}; } catch(const std::exception &e) { ircd::log::error { - "SIGUSR1 handler: %s", e.what() + "SIGUSR1 handler :%s", + e.what() }; } diff --git a/include/ircd/m/homeserver.h b/include/ircd/m/homeserver.h index eefc31a5a..6ffeb7236 100644 --- a/include/ircd/m/homeserver.h +++ b/include/ircd/m/homeserver.h @@ -83,6 +83,7 @@ struct ircd::m::homeserver /// Factory to create homeserver with single procedure for shlib purposes. static homeserver *init(const struct opts *); static void fini(homeserver *) noexcept; + static bool rehash(homeserver *); }; struct ircd::m::homeserver::key diff --git a/matrix/homeserver.cc b/matrix/homeserver.cc index f8df465c9..ab69ee95f 100644 --- a/matrix/homeserver.cc +++ b/matrix/homeserver.cc @@ -213,6 +213,20 @@ noexcept delete homeserver; } +bool +IRCD_MODULE_EXPORT +ircd::m::homeserver::rehash(homeserver *const homeserver) +{ + if(!homeserver) + return false; + + if(!homeserver->conf) + return false; + + homeserver->conf->load(); + return true; +} + // // homeserver::homeserver::homeserver //