bryancall commented on PR #12757:
URL: https://github.com/apache/trafficserver/pull/12757#issuecomment-3661451528
Diff with master:
```
diff --git a/plugins/experimental/block_errors/block_errors.cc
b/plugins/experimental/block_errors/block_errors.cc
index 88fe3bf57af..xxxxx 100644
--- a/plugins/experimental/block_errors/block_errors.cc
+++ b/plugins/experimental/block_errors/block_errors.cc
@@ -17,6 +17,7 @@
#include <ts/ts.h>
#include <unordered_map>
+#include <string>
#include <limits>
#include <swoc/IPAddr.h>
#include <swoc/bwf_ip.h>
@@ -37,27 +38,42 @@ static bool enabled = true;
//-------------------------------------------------------------------------
static int
-msg_hook(TSCont * /* contp ATS_UNUSED */, TSEvent /* event ATS_UNUSED */,
void *edata)
+msg_hook(TSCont * /* contp ATS_UNUSED */, TSEvent event, void *edata)
{
- TSPluginMsg *msg = static_cast<TSPluginMsg *>(edata);
- std::string_view tag(static_cast<const char *>(msg->tag));
- std::string_view data(static_cast<const char *>(msg->data));
+ if (event != TS_EVENT_LIFECYCLE_MSG) {
+ TSError("block_errors: unexpected event %d", event);
+ return TS_EVENT_NONE;
+ }
+
+ TSPluginMsg *msg = static_cast<TSPluginMsg *>(edata);
+ std::string_view tag{msg->tag};
+
+ // Filter for messages meant for this plugin
+ static constexpr std::string_view PREFIX{"block_errors."};
+ if (tag.substr(0, PREFIX.size()) != PREFIX) {
+ Dbg(dbg_ctl, "msg_hook: message for a different plugin: %.*s",
+ static_cast<int>(tag.size()), tag.data());
+ return TS_EVENT_NONE;
+ }
- Dbg(dbg_ctl, "msg_hook: tag=%s data=%s", tag.data(), data.data());
+ std::string_view command = tag.substr(PREFIX.size());
+ std::string data{static_cast<const char *>(msg->data), msg->data_size};
- if (tag == "block_errors.enabled") {
- enabled = static_cast<bool>(atoi(data.data()));
- } else if (tag == "block_errors.limit") {
- RESET_LIMIT = atoi(data.data());
- } else if (tag == "block_errors.cycles") {
- TIMEOUT_CYCLES = atoi(data.data());
- } else if (tag == "block_errors.shutdown") {
- shutdown_connection = static_cast<bool>(atoi(data.data()));
+ Dbg(dbg_ctl, "msg_hook: command=%.*s data=%s",
+ static_cast<int>(command.size()), command.data(), data.c_str());
+
+ if (command == "enabled") {
+ enabled = static_cast<bool>(std::stoi(data));
+ } else if (command == "limit") {
+ RESET_LIMIT = std::stoi(data);
+ } else if (command == "cycles") {
+ TIMEOUT_CYCLES = std::stoi(data);
+ } else if (command == "shutdown") {
+ shutdown_connection = static_cast<bool>(std::stoi(data));
} else {
- Dbg(dbg_ctl, "msg_hook: unknown message tag '%s'", tag.data());
- TSError("block_errors: unknown message tag '%s'", tag.data());
+ Dbg(dbg_ctl, "msg_hook: unknown command '%.*s'",
+ static_cast<int>(command.size()), command.data());
+ TSError("block_errors: unknown command '%.*s'",
+ static_cast<int>(command.size()), command.data());
}
Dbg(dbg_ctl, "reset limit: %d per minute, timeout limit: %d minutes,
shutdown connection: %d enabled: %d", RESET_LIMIT,
TIMEOUT_CYCLES, shutdown_connection, enabled);
- return 0;
+ return TS_EVENT_NONE;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]