Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Synopsis

#include <ts/ts.h>

.. 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
===========
7 changes: 4 additions & 3 deletions include/api/InkAPIInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<std::string, INKContInternal *> cb_table;
std::unordered_map<std::string, std::tuple<INKContInternal *, swoc::file::path, swoc::file::file_time_type>> cb_table;
};

#include "HttpAPIHooks.h"
Expand Down
2 changes: 1 addition & 1 deletion include/ts/ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 31 additions & 16 deletions src/api/ConfigUpdateCbTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/InkAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/mgmt/config/FileManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down