mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Remove EventRegistry::Used and EventRegistry::SetUsed
This commit is contained in:
parent
97fa7cdc0a
commit
e2b03681d1
11 changed files with 6 additions and 111 deletions
|
@ -5259,9 +5259,6 @@ const likely_server_ports: set[port] &redef;
|
|||
## If true, output profiling for Time-Machine queries.
|
||||
const time_machine_profiling = F &redef &deprecated="Remove in v7.1. Unused.";
|
||||
|
||||
## If true, warns about unused event handlers at startup.
|
||||
const check_for_unused_event_handlers = F &redef &deprecated="Remove in v7.1. This has been replaced by usage analyzer functionality.";
|
||||
|
||||
## Holds the filename of the trace file given with ``-w`` (empty if none).
|
||||
##
|
||||
## .. zeek:see:: record_all_packets
|
||||
|
|
|
@ -44,13 +44,6 @@ public:
|
|||
// Returns true if there is at least one local or remote handler.
|
||||
explicit operator bool() const;
|
||||
|
||||
[[deprecated("Remove in v7.1 - Unused event handlers are now found via UsageAnalyzer.")]] void SetUsed() {
|
||||
used = true;
|
||||
}
|
||||
[[deprecated("Remove in v7.1 - Unused event handlers are now found via UsageAnalyzer.")]] bool Used() const {
|
||||
return used;
|
||||
}
|
||||
|
||||
// Handlers marked as error handlers will not be called recursively to
|
||||
// avoid infinite loops if they trigger a similar error themselves.
|
||||
void SetErrorHandler() { error_handler = true; }
|
||||
|
|
|
@ -21,23 +21,12 @@ EventHandlerPtr EventRegistry::Register(std::string_view name, bool is_from_scri
|
|||
if ( ! is_from_script )
|
||||
not_only_from_script.insert(std::string(name));
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
// Remove in v7.1
|
||||
h->SetUsed();
|
||||
#pragma GCC diagnostic pop
|
||||
return h;
|
||||
}
|
||||
|
||||
h = new EventHandler(std::string(name));
|
||||
event_registry->Register(h, is_from_script);
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
// Remove in v7.1
|
||||
h->SetUsed();
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
@ -74,36 +63,6 @@ EventRegistry::string_list EventRegistry::Match(RE_Matcher* pattern) {
|
|||
return names;
|
||||
}
|
||||
|
||||
EventRegistry::string_list EventRegistry::UnusedHandlers() {
|
||||
string_list names;
|
||||
|
||||
for ( const auto& entry : handlers ) {
|
||||
EventHandler* v = entry.second.get();
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
if ( v->GetFunc() && ! v->Used() )
|
||||
names.push_back(entry.first);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
EventRegistry::string_list EventRegistry::UsedHandlers() {
|
||||
string_list names;
|
||||
|
||||
for ( const auto& entry : handlers ) {
|
||||
EventHandler* v = entry.second.get();
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
if ( v->GetFunc() && v->Used() )
|
||||
names.push_back(entry.first);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
EventRegistry::string_list EventRegistry::AllHandlers() {
|
||||
string_list names;
|
||||
|
||||
|
|
|
@ -69,8 +69,6 @@ public:
|
|||
// themselves.
|
||||
void SetErrorHandler(std::string_view name);
|
||||
|
||||
[[deprecated("Remove in v7.1 - Unused handlers are now found via UsageAnalyzer.")]] string_list UnusedHandlers();
|
||||
[[deprecated("Remove in v7.1 - UsedHandlers() is unreliable - use AllHandlers().")]] string_list UsedHandlers();
|
||||
string_list AllHandlers();
|
||||
|
||||
void PrintDebug();
|
||||
|
|
12
src/Expr.cc
12
src/Expr.cc
|
@ -414,13 +414,6 @@ NameExpr::NameExpr(IDPtr arg_id, bool const_init) : Expr(EXPR_NAME), id(std::mov
|
|||
SetType(make_intrusive<TypeType>(id->GetType()));
|
||||
else
|
||||
SetType(id->GetType());
|
||||
|
||||
EventHandler* h = event_registry->Lookup(id->Name());
|
||||
if ( h )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
h->SetUsed();
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
bool NameExpr::CanDel() const {
|
||||
|
@ -4417,11 +4410,6 @@ EventExpr::EventExpr(const char* arg_name, ListExprPtr arg_args)
|
|||
event_registry->Register(h, true);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
h->SetUsed();
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
handler = h;
|
||||
|
||||
if ( args->IsError() ) {
|
||||
|
|
|
@ -182,8 +182,6 @@ int dpd_match_only_beginning;
|
|||
int dpd_late_match_stop;
|
||||
int dpd_ignore_ports;
|
||||
|
||||
int check_for_unused_event_handlers;
|
||||
|
||||
int record_all_packets;
|
||||
|
||||
zeek_uint_t bits_per_uid;
|
||||
|
@ -229,7 +227,6 @@ void init_general_global_var() {
|
|||
table_incremental_step = id::find_val("table_incremental_step")->AsCount();
|
||||
packet_filter_default = id::find_val("packet_filter_default")->AsBool();
|
||||
sig_max_group_size = id::find_val("sig_max_group_size")->AsCount();
|
||||
check_for_unused_event_handlers = id::find_val("check_for_unused_event_handlers")->AsBool();
|
||||
record_all_packets = id::find_val("record_all_packets")->AsBool();
|
||||
bits_per_uid = id::find_val("bits_per_uid")->AsCount();
|
||||
}
|
||||
|
|
|
@ -85,8 +85,6 @@ extern int dpd_match_only_beginning;
|
|||
extern int dpd_late_match_stop;
|
||||
extern int dpd_ignore_ports;
|
||||
|
||||
extern int check_for_unused_event_handlers;
|
||||
|
||||
extern int record_all_packets;
|
||||
|
||||
extern zeek_uint_t bits_per_uid;
|
||||
|
|
|
@ -131,13 +131,8 @@ void activate_bodies__CPP(const char* fn, const char* module, bool exported, Typ
|
|||
events.insert(cs.events.begin(), cs.events.end());
|
||||
}
|
||||
|
||||
for ( const auto& e : events ) {
|
||||
auto eh = event_registry->Register(e);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
eh->SetUsed();
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
for ( const auto& e : events )
|
||||
event_registry->Register(e);
|
||||
}
|
||||
|
||||
IDPtr lookup_global__CPP(const char* g, const TypePtr& t, bool exported) {
|
||||
|
@ -191,13 +186,8 @@ FuncValPtr lookup_func__CPP(string name, int num_bodies, vector<p_hash_type> has
|
|||
// This might register the same event more than once,
|
||||
// if it's used in multiple bodies, but that's okay as
|
||||
// the semantics for Register explicitly allow it.
|
||||
for ( auto& e : f.events ) {
|
||||
auto eh = event_registry->Register(e);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
eh->SetUsed();
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
for ( auto& e : f.events )
|
||||
event_registry->Register(e);
|
||||
}
|
||||
|
||||
auto sf = make_intrusive<ScriptFunc>(std::move(name), std::move(ft), std::move(bodies), std::move(priorities));
|
||||
|
|
|
@ -417,13 +417,8 @@ static void use_CPP() {
|
|||
f.SetBody(b);
|
||||
}
|
||||
|
||||
for ( auto& e : s->second.events ) {
|
||||
auto h = event_registry->Register(e);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
h->SetUsed();
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
for ( auto& e : s->second.events )
|
||||
event_registry->Register(e);
|
||||
|
||||
auto finish = s->second.finish_init_func;
|
||||
if ( finish )
|
||||
|
|
|
@ -996,16 +996,6 @@ SetupResult setup(int argc, char** argv, Options* zopts) {
|
|||
if ( zeek_init )
|
||||
event_mgr.Enqueue(zeek_init, Args{});
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
EventRegistry::string_list dead_handlers = event_registry->UnusedHandlers();
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
if ( ! dead_handlers.empty() && check_for_unused_event_handlers ) {
|
||||
for ( const string& handler : dead_handlers )
|
||||
reporter->Warning("event handler never invoked: %s", handler.c_str());
|
||||
}
|
||||
|
||||
// Enable LeakSanitizer before zeek_init() and even before executing
|
||||
// top-level statements. Even though it's not bad if a leak happens only
|
||||
// once at initialization, we have to assume that script-layer code causing
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
# This test should print a warning that the event handler is never invoked.
|
||||
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
|
||||
# @TEST-REQUIRES: $SCRIPTS/have-spicy # This test logs uninvoked event handlers, so disable it if Spicy and its plugin is unavailable.
|
||||
# @TEST-EXEC: zeek -b %INPUT check_for_unused_event_handlers=T
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort-and-remove-abspath btest-diff .stderr
|
||||
|
||||
event this_is_never_used()
|
||||
{
|
||||
print "not even once";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue