new global_options() BiF to speed up startup, plus a micro-preen

This commit is contained in:
Vern Paxson 2022-05-03 11:13:15 -07:00
parent 07f5e9cbe7
commit fab4905fc2
3 changed files with 21 additions and 9 deletions

View file

@ -162,13 +162,7 @@ event zeek_init() &priority=10
@if ( !Cluster::is_enabled() || Cluster::local_node_type() == Cluster::MANAGER )
# Iterate over all existing options and add ourselves as change handlers
# with a low priority so that we can log the changes.
local gids = global_ids();
for ( i, gid in gids )
{
if ( ! gid$option_value )
next;
Option::set_change_handler(i, config_option_changed, -100);
}
for ( opt in global_options() )
Option::set_change_handler(opt, config_option_changed, -100);
@endif
}

View file

@ -243,5 +243,4 @@ event zeek_init() &priority=10
# Create the local_nets mapping table.
for ( cidr in Site::local_nets )
local_nets_table[cidr] = cidr;
}

View file

@ -2022,6 +2022,25 @@ function global_ids%(%): id_table
return ids;
%}
## Returns a set giving the names of all global options.
function global_options%(%): string_set
%{
auto options = make_intrusive<zeek::TableVal>(zeek::id::string_set);
const auto& globals = zeek::detail::global_scope()->Vars();
for ( const auto& global : globals )
{
const auto& id = global.second;
if ( ! id->IsOption() )
continue;
auto id_name = zeek::make_intrusive<zeek::StringVal>(id->Name());
options->Assign(std::move(id_name), nullptr);
}
return options;
%}
## Returns the value of a global identifier.
##
## id: The global identifier.