From b8b6fbea37495abc76681f1dcb3cf1ad5d54d4f6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 2 Nov 2018 04:49:56 -0700 Subject: [PATCH] modules/s_conf: Add default_conf w/ console cmd to set item to default value. --- modules/console.cc | 36 ++++++++++++++++++++++++++++++++++++ modules/s_conf.cc | 20 ++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/modules/console.cc b/modules/console.cc index 9b007587b..50b321166 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -832,6 +832,42 @@ console_cmd__conf__rehash(opt &out, const string_view &line) return true; } +bool +console_cmd__conf__default(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "prefix" + }}; + + using prototype = void (const string_view &); + static mods::import default_conf + { + "s_conf", "default_conf" + }; + + string_view prefix + { + param.at("prefix", "*"_sv) + }; + + if(prefix == "*") + prefix = string_view{}; + + default_conf(prefix); + + out << "Set runtime conf items" + << (prefix? " with the prefix "_sv : string_view{}) + << (prefix? prefix : string_view{}) + << " to their default value." + << std::endl + << "Note: These values must be saved with the rehash command" + << " to survive a restart/reload." + << std::endl; + + return true; +} + bool console_cmd__conf__reload(opt &out, const string_view &line) { diff --git a/modules/s_conf.cc b/modules/s_conf.cc index 1d11632b3..fafe20167 100644 --- a/modules/s_conf.cc +++ b/modules/s_conf.cc @@ -10,6 +10,7 @@ using namespace ircd; +extern "C" void default_conf(const string_view &prefix); extern "C" void rehash_conf(const string_view &prefix, const bool &existing); extern "C" void reload_conf(); extern "C" void refresh_conf(); @@ -290,6 +291,25 @@ rehash_conf(const string_view &prefix, } } +void +default_conf(const string_view &prefix) +{ + for(const auto &p : conf::items) + { + const auto &key{p.first}; + if(prefix && !startswith(key, prefix)) + continue; + + const auto &item{p.second}; assert(item); + const auto value + { + unquote(item->feature["default"]) + }; + + conf::set(key, value); + } +} + void reload_conf() {