diff --git a/doc/developer-guide/api/functions/TSMgmtUpdateRegister.en.rst b/doc/developer-guide/api/functions/TSMgmtUpdateRegister.en.rst index b841466bae1..41e1b0dcd3e 100644 --- a/doc/developer-guide/api/functions/TSMgmtUpdateRegister.en.rst +++ b/doc/developer-guide/api/functions/TSMgmtUpdateRegister.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSMgmtUpdateRegister(TSCont contp, const char * plugin_name) +.. function:: void TSMgmtUpdateRegister(TSCont contp, const char *plugin_name, const char *plugin_file_name=nullptr) Description =========== diff --git a/include/api/InkAPIInternal.h b/include/api/InkAPIInternal.h index 086bcffd84b..e3a7f0e2b17 100644 --- a/include/api/InkAPIInternal.h +++ b/include/api/InkAPIInternal.h @@ -37,6 +37,7 @@ #include "api/APIHooks.h" #include "api/FeatureAPIHooks.h" +#include "swoc/swoc_file.h" #include "ts/InkAPIPrivateIOCore.h" #include "ts/experimental.h" @@ -143,12 +144,12 @@ class ConfigUpdateCbTable ConfigUpdateCbTable(); ~ConfigUpdateCbTable(); - void insert(INKContInternal *contp, const char *name); - void invoke(const char *name); + void insert(INKContInternal *contp, const char *name, const char *file_name = nullptr); + void invoke(); void invoke(INKContInternal *contp); private: - std::unordered_map cb_table; + std::unordered_map> cb_table; }; #include "HttpAPIHooks.h" diff --git a/include/ts/ts.h b/include/ts/ts.h index 734aa6d77c0..0bbd3163602 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -1255,7 +1255,7 @@ namespace c /* -------------------------------------------------------------------------- Management */ - void TSMgmtUpdateRegister(TSCont contp, const char *plugin_name); + void TSMgmtUpdateRegister(TSCont contp, const char *plugin_name, const char *plugin_file_name = nullptr); TSReturnCode TSMgmtIntGet(const char *var_name, TSMgmtInt *result); TSReturnCode TSMgmtCounterGet(const char *var_name, TSMgmtCounter *result); TSReturnCode TSMgmtFloatGet(const char *var_name, TSMgmtFloat *result); diff --git a/src/api/ConfigUpdateCbTable.cc b/src/api/ConfigUpdateCbTable.cc index 19f6dfa50e8..1b1e5d33980 100644 --- a/src/api/ConfigUpdateCbTable.cc +++ b/src/api/ConfigUpdateCbTable.cc @@ -28,31 +28,46 @@ ConfigUpdateCbTable::ConfigUpdateCbTable() {} ConfigUpdateCbTable::~ConfigUpdateCbTable() {} void -ConfigUpdateCbTable::insert(INKContInternal *contp, const char *name) +ConfigUpdateCbTable::insert(INKContInternal *contp, const char *name, const char *file_name) { - if (contp && name) { - cb_table.emplace(name, contp); + ink_assert(contp != nullptr); + ink_assert(name != nullptr); + + if (nullptr != file_name) { + swoc::file::path file_path{file_name}; + std::error_code ec; + auto timestamp = swoc::file::last_write_time(file_path, ec); + + if (!ec) { + cb_table.emplace(name, std::make_tuple(contp, file_path, timestamp)); + } else { + Error("Failed to stat %s: %s", file_path.c_str(), ec.message().c_str()); + } + } else { + cb_table.emplace(name, std::make_tuple(contp, swoc::file::path{}, swoc::file::file_time_type{})); } } void -ConfigUpdateCbTable::invoke(const char *name) +ConfigUpdateCbTable::invoke() { - INKContInternal *contp; + for (auto &&it : cb_table) { + auto &[contp, file_path, timestamp] = it.second; + + if (!file_path.empty()) { + std::error_code ec; + auto newtime = swoc::file::last_write_time(file_path, ec); - if (name != nullptr) { - if (strcmp(name, "*") == 0) { - for (auto &&it : cb_table) { - contp = it.second; - ink_assert(contp != nullptr); - invoke(contp); + if (!ec) { + if (newtime > timestamp) { + timestamp = newtime; + invoke(contp); + } + } else { + Error("Failed to stat %s: %s", file_path.c_str(), ec.message().c_str()); } } else { - if (auto it = cb_table.find(name); it != cb_table.end()) { - contp = it->second; - ink_assert(contp != nullptr); - invoke(contp); - } + invoke(contp); } } } diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc index 9de791cbfb6..5172a82bab3 100644 --- a/src/api/InkAPI.cc +++ b/src/api/InkAPI.cc @@ -4096,12 +4096,12 @@ tsapi::c::TSConfigDataGet(TSConfig configp) //////////////////////////////////////////////////////////////////// void -tsapi::c::TSMgmtUpdateRegister(TSCont contp, const char *plugin_name) +tsapi::c::TSMgmtUpdateRegister(TSCont contp, const char *plugin_name, const char *plugin_file_name) { sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)plugin_name) == TS_SUCCESS); - global_config_cbs->insert((INKContInternal *)contp, plugin_name); + global_config_cbs->insert((INKContInternal *)contp, plugin_name, plugin_file_name); } TSReturnCode diff --git a/src/mgmt/config/FileManager.cc b/src/mgmt/config/FileManager.cc index d96332eef51..c379355c4e0 100644 --- a/src/mgmt/config/FileManager.cc +++ b/src/mgmt/config/FileManager.cc @@ -193,9 +193,8 @@ void FileManager::invokeConfigPluginCallbacks() { Debug("filemanager", "invoke plugin callbacks"); - static const std::string_view s{"*"}; if (_pluginCallbackList) { - _pluginCallbackList->invoke(s.data()); + _pluginCallbackList->invoke(); } }