0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-22 00:18:57 +02:00

modules/s_conf: Improve rehashing interface; adjust console cmds.

This commit is contained in:
Jason Volk 2018-09-02 21:13:03 -07:00
parent 08a35bdc6a
commit 94a2fdacb5
3 changed files with 76 additions and 14 deletions

View file

@ -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<void ()> rehash_conf
ircd::m::import<void ()> reload_conf
{
"s_conf", "rehash_conf"
"s_conf", "reload_conf"
};
rehash_conf();
reload_conf();
}};
}
catch(const std::exception &e)

View file

@ -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<prototype> 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<prototype> 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<prototype> 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
//

View file

@ -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();
}