diff --git a/construct/construct.cc b/construct/construct.cc index 0f1d7bc55..a4affe7cf 100644 --- a/construct/construct.cc +++ b/construct/construct.cc @@ -353,16 +353,16 @@ try } // This signal handler (though not a *real* signal handler) is still - // running on the main async stack and not an ircd::ctx. The rehash + // 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::m::import rehash_conf + ircd::m::import reload_conf { - "s_conf", "rehash_conf" + "s_conf", "reload_conf" }; - rehash_conf(); + reload_conf(); }}; } catch(const std::exception &e) diff --git a/modules/console.cc b/modules/console.cc index a071fc795..6d9cf75cc 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -642,13 +642,30 @@ console_cmd__conf__get(opt &out, const string_view &line) bool console_cmd__conf__rehash(opt &out, const string_view &line) { - using prototype = void (); + using prototype = void (const bool &); static m::import rehash_conf { "s_conf", "rehash_conf" }; - rehash_conf(); + rehash_conf(false); + out << "Saved runtime conf items" + << " from the current state into !conf:" << my_host() + << std::endl; + + return true; +} + +bool +console_cmd__conf__reload(opt &out, const string_view &line) +{ + using prototype = void (); + static m::import reload_conf + { + "s_conf", "reload_conf" + }; + + reload_conf(); out << "Updated any runtime conf items" << " from the current state in !conf:" << my_host() << std::endl; @@ -656,6 +673,23 @@ console_cmd__conf__rehash(opt &out, const string_view &line) return true; } +bool +console_cmd__conf__reset(opt &out, const string_view &line) +{ + using prototype = void (); + static m::import refresh_conf + { + "s_conf", "refresh_conf" + }; + + refresh_conf(); + out << "All conf items which execute code upon a change" + << " have done so with the latest runtime value." + << std::endl; + + return true; +} + // // hook // diff --git a/modules/s_conf.cc b/modules/s_conf.cc index 1d41d8dfd..876ed37e7 100644 --- a/modules/s_conf.cc +++ b/modules/s_conf.cc @@ -10,14 +10,16 @@ using namespace ircd; -extern "C" void rehash_conf(); +extern "C" void rehash_conf(const bool &existing = false); +extern "C" void reload_conf(); +extern "C" void refresh_conf(); mapi::header IRCD_MODULE { "Server Configuration", [] { - rehash_conf(); + reload_conf(); } }; @@ -146,12 +148,6 @@ init_conf_items_hook } }; -void -rehash_conf() -{ - init_conf_items(m::event{}); -} - static void create_conf_item(const string_view &key, const conf::item<> &item) @@ -191,3 +187,35 @@ create_conf_room_hook { "type", "m.room.create" }, } }; + +void +rehash_conf(const bool &existing) +{ + const m::room::state state + { + conf_room + }; + + for(const auto &p : conf::items) + { + const auto &key{p.first}; + const auto &item{p.second}; assert(item); + if(!existing) + if(state.has("ircd.conf.item", key)) + continue; + + create_conf_item(key, *item); + } +} + +void +reload_conf() +{ + init_conf_items(m::event{}); +} + +void +refresh_conf() +{ + ircd::conf::reset(); +}