mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Deprecate zeekenv() and use getenv() directly
This commit is contained in:
parent
79f9979f80
commit
b8c563dbdd
11 changed files with 24 additions and 45 deletions
4
NEWS
4
NEWS
|
@ -39,6 +39,10 @@ Deprecated Functionality
|
||||||
compatible iterators. This enables the use of standard constructs such
|
compatible iterators. This enables the use of standard constructs such
|
||||||
as ranged-for loops to iterate over those objects.
|
as ranged-for loops to iterate over those objects.
|
||||||
|
|
||||||
|
- The ``zeek::util::zeekenv()`` function is deprecated since use of all
|
||||||
|
environment variables prefixed by ``BRO_`` is now removed and calling
|
||||||
|
``getenv()`` directly with ``ZEEK_`` environment variables can be done.
|
||||||
|
|
||||||
Zeek 4.0.0
|
Zeek 4.0.0
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
|
|
@ -409,7 +409,7 @@ void DNS_Mgr::InitSource()
|
||||||
// script-layer option to configure the DNS resolver as it may not be
|
// script-layer option to configure the DNS resolver as it may not be
|
||||||
// configured to the user's desired address at the time when we need to to
|
// configured to the user's desired address at the time when we need to to
|
||||||
// the lookup.
|
// the lookup.
|
||||||
auto dns_resolver = util::zeekenv("ZEEK_DNS_RESOLVER");
|
auto dns_resolver = getenv("ZEEK_DNS_RESOLVER");
|
||||||
auto dns_resolver_addr = dns_resolver ? IPAddr(dns_resolver) : IPAddr();
|
auto dns_resolver_addr = dns_resolver ? IPAddr(dns_resolver) : IPAddr();
|
||||||
char err[NB_DNS_ERRSIZE];
|
char err[NB_DNS_ERRSIZE];
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ void Options::filter_supervised_node_options()
|
||||||
|
|
||||||
bool fake_dns()
|
bool fake_dns()
|
||||||
{
|
{
|
||||||
return util::zeekenv("ZEEK_DNS_FAKE");
|
return getenv("ZEEK_DNS_FAKE");
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const char* zeek_version();
|
extern const char* zeek_version();
|
||||||
|
@ -135,8 +135,8 @@ void usage(const char* prog, int code)
|
||||||
fprintf(stderr, " $ZEEK_SEED_FILE | file to load seeds from (not set)\n");
|
fprintf(stderr, " $ZEEK_SEED_FILE | file to load seeds from (not set)\n");
|
||||||
fprintf(stderr, " $ZEEK_LOG_SUFFIX | ASCII log file extension (.%s)\n", logging::writer::detail::Ascii::LogExt().c_str());
|
fprintf(stderr, " $ZEEK_LOG_SUFFIX | ASCII log file extension (.%s)\n", logging::writer::detail::Ascii::LogExt().c_str());
|
||||||
fprintf(stderr, " $ZEEK_PROFILER_FILE | Output file for script execution statistics (not set)\n");
|
fprintf(stderr, " $ZEEK_PROFILER_FILE | Output file for script execution statistics (not set)\n");
|
||||||
fprintf(stderr, " $ZEEK_DISABLE_ZEEKYGEN | Disable Zeekygen documentation support (%s)\n", util::zeekenv("ZEEK_DISABLE_ZEEKYGEN") ? "set" : "not set");
|
fprintf(stderr, " $ZEEK_DISABLE_ZEEKYGEN | Disable Zeekygen documentation support (%s)\n", getenv("ZEEK_DISABLE_ZEEKYGEN") ? "set" : "not set");
|
||||||
fprintf(stderr, " $ZEEK_DNS_RESOLVER | IPv4/IPv6 address of DNS resolver to use (%s)\n", util::zeekenv("ZEEK_DNS_RESOLVER") ? util::zeekenv("ZEEK_DNS_RESOLVER") : "not set, will use first IPv4 address from /etc/resolv.conf");
|
fprintf(stderr, " $ZEEK_DNS_RESOLVER | IPv4/IPv6 address of DNS resolver to use (%s)\n", getenv("ZEEK_DNS_RESOLVER") ? getenv("ZEEK_DNS_RESOLVER") : "not set, will use first IPv4 address from /etc/resolv.conf");
|
||||||
fprintf(stderr, " $ZEEK_DEBUG_LOG_STDERR | Use stderr for debug logs generated via the -B flag");
|
fprintf(stderr, " $ZEEK_DEBUG_LOG_STDERR | Use stderr for debug logs generated via the -B flag");
|
||||||
|
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
|
@ -39,7 +39,7 @@ void ScriptCoverageManager::AddStmt(Stmt* s)
|
||||||
|
|
||||||
bool ScriptCoverageManager::ReadStats()
|
bool ScriptCoverageManager::ReadStats()
|
||||||
{
|
{
|
||||||
char* bf = util::zeekenv("ZEEK_PROFILER_FILE");
|
char* bf = getenv("ZEEK_PROFILER_FILE");
|
||||||
|
|
||||||
if ( ! bf )
|
if ( ! bf )
|
||||||
return false;
|
return false;
|
||||||
|
@ -89,7 +89,7 @@ bool ScriptCoverageManager::ReadStats()
|
||||||
|
|
||||||
bool ScriptCoverageManager::WriteStats()
|
bool ScriptCoverageManager::WriteStats()
|
||||||
{
|
{
|
||||||
char* bf = util::zeekenv("ZEEK_PROFILER_FILE");
|
char* bf = getenv("ZEEK_PROFILER_FILE");
|
||||||
|
|
||||||
if ( ! bf )
|
if ( ! bf )
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -185,7 +185,7 @@ void Manager::InitPostScript()
|
||||||
else
|
else
|
||||||
reporter->FatalError("Invalid Broker::scheduler_policy: %s", scheduler_policy);
|
reporter->FatalError("Invalid Broker::scheduler_policy: %s", scheduler_policy);
|
||||||
|
|
||||||
auto max_threads_env = util::zeekenv("ZEEK_BROKER_MAX_THREADS");
|
auto max_threads_env = getenv("ZEEK_BROKER_MAX_THREADS");
|
||||||
|
|
||||||
if ( max_threads_env )
|
if ( max_threads_env )
|
||||||
config.set("caf.scheduler.max-threads", atoi(max_threads_env));
|
config.set("caf.scheduler.max-threads", atoi(max_threads_env));
|
||||||
|
@ -365,7 +365,7 @@ void Manager::Peer(const string& addr, uint16_t port, double retry)
|
||||||
DBG_LOG(DBG_BROKER, "Starting to peer with %s:%" PRIu16,
|
DBG_LOG(DBG_BROKER, "Starting to peer with %s:%" PRIu16,
|
||||||
addr.c_str(), port);
|
addr.c_str(), port);
|
||||||
|
|
||||||
auto e = util::zeekenv("ZEEK_DEFAULT_CONNECT_RETRY");
|
auto e = getenv("ZEEK_DEFAULT_CONNECT_RETRY");
|
||||||
|
|
||||||
if ( e )
|
if ( e )
|
||||||
retry = atoi(e);
|
retry = atoi(e);
|
||||||
|
|
|
@ -850,7 +850,7 @@ void Ascii::RotateLeftoverLogs()
|
||||||
|
|
||||||
string Ascii::LogExt()
|
string Ascii::LogExt()
|
||||||
{
|
{
|
||||||
const char* ext = util::zeekenv("ZEEK_LOG_SUFFIX");
|
const char* ext = getenv("ZEEK_LOG_SUFFIX");
|
||||||
|
|
||||||
if ( ! ext )
|
if ( ! ext )
|
||||||
ext = "log";
|
ext = "log";
|
||||||
|
|
36
src/util.cc
36
src/util.cc
|
@ -876,7 +876,7 @@ FILE* rotate_file(const char* name, RecordVal* rotate_info)
|
||||||
|
|
||||||
const char* log_file_name(const char* tag)
|
const char* log_file_name(const char* tag)
|
||||||
{
|
{
|
||||||
const char* env = zeekenv("ZEEK_LOG_SUFFIX");
|
const char* env = getenv("ZEEK_LOG_SUFFIX");
|
||||||
return fmt("%s.%s", tag, (env ? env : "log"));
|
return fmt("%s.%s", tag, (env ? env : "log"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1705,7 +1705,7 @@ const std::string& zeek_path()
|
||||||
{
|
{
|
||||||
if ( zeek_path_value.empty() )
|
if ( zeek_path_value.empty() )
|
||||||
{
|
{
|
||||||
const char* path = zeekenv("ZEEKPATH");
|
const char* path = getenv("ZEEKPATH");
|
||||||
|
|
||||||
if ( ! path )
|
if ( ! path )
|
||||||
path = DEFAULT_ZEEKPATH;
|
path = DEFAULT_ZEEKPATH;
|
||||||
|
@ -1718,7 +1718,7 @@ const std::string& zeek_path()
|
||||||
|
|
||||||
const char* zeek_plugin_path()
|
const char* zeek_plugin_path()
|
||||||
{
|
{
|
||||||
const char* path = zeekenv("ZEEK_PLUGIN_PATH");
|
const char* path = getenv("ZEEK_PLUGIN_PATH");
|
||||||
|
|
||||||
if ( ! path )
|
if ( ! path )
|
||||||
path = BRO_PLUGIN_INSTALL_PATH;
|
path = BRO_PLUGIN_INSTALL_PATH;
|
||||||
|
@ -1728,7 +1728,7 @@ const char* zeek_plugin_path()
|
||||||
|
|
||||||
const char* zeek_plugin_activate()
|
const char* zeek_plugin_activate()
|
||||||
{
|
{
|
||||||
const char* names = zeekenv("ZEEK_PLUGIN_ACTIVATE");
|
const char* names = getenv("ZEEK_PLUGIN_ACTIVATE");
|
||||||
|
|
||||||
if ( ! names )
|
if ( ! names )
|
||||||
names = "";
|
names = "";
|
||||||
|
@ -2338,35 +2338,9 @@ void zeek_strerror_r(int zeek_errno, char* buf, size_t buflen)
|
||||||
strerror_r_helper(res, buf, buflen);
|
strerror_r_helper(res, buf, buflen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::map<const char*, const char*, CompareString> legacy_vars = {
|
|
||||||
{ "ZEEKPATH", "BROPATH" },
|
|
||||||
{ "ZEEK_PLUGIN_PATH", "BRO_PLUGIN_PATH" },
|
|
||||||
{ "ZEEK_PLUGIN_ACTIVATE", "BRO_PLUGIN_ACTIVATE" },
|
|
||||||
{ "ZEEK_PREFIXES", "BRO_PREFIXES" },
|
|
||||||
{ "ZEEK_DNS_FAKE", "BRO_DNS_FAKE" },
|
|
||||||
{ "ZEEK_SEED_FILE", "BRO_SEED_FILE" },
|
|
||||||
{ "ZEEK_LOG_SUFFIX", "BRO_LOG_SUFFIX" },
|
|
||||||
{ "ZEEK_PROFILER_FILE", "BRO_PROFILER_FILE" },
|
|
||||||
{ "ZEEK_DISABLE_ZEEKYGEN", "BRO_DISABLE_BROXYGEN" },
|
|
||||||
{ "ZEEK_DEFAULT_CONNECT_RETRY", "BRO_DEFAULT_CONNECT_RETRY" },
|
|
||||||
{ "ZEEK_BROKER_MAX_THREADS", "BRO_BROKER_MAX_THREADS" },
|
|
||||||
{ "ZEEK_DEFAULT_LISTEN_ADDRESS", "BRO_DEFAULT_LISTEN_ADDRESS" },
|
|
||||||
{ "ZEEK_DEFAULT_LISTEN_RETRY", "BRO_DEFAULT_LISTEN_RETRY" },
|
|
||||||
};
|
|
||||||
|
|
||||||
char* zeekenv(const char* name)
|
char* zeekenv(const char* name)
|
||||||
{
|
{
|
||||||
auto rval = getenv(name);
|
return getenv(name);
|
||||||
|
|
||||||
if ( rval )
|
|
||||||
return rval;
|
|
||||||
|
|
||||||
auto it = legacy_vars.find(name);
|
|
||||||
|
|
||||||
if ( it == legacy_vars.end() )
|
|
||||||
return rval;
|
|
||||||
|
|
||||||
return getenv(it->second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static string json_escape_byte(char c)
|
static string json_escape_byte(char c)
|
||||||
|
|
|
@ -526,6 +526,7 @@ void zeek_strerror_r(int zeek_errno, char* buf, size_t buflen);
|
||||||
* A wrapper function for getenv(). Helps check for existence of
|
* A wrapper function for getenv(). Helps check for existence of
|
||||||
* legacy environment variable names that map to the latest \a name.
|
* legacy environment variable names that map to the latest \a name.
|
||||||
*/
|
*/
|
||||||
|
[[deprecated("Remove in v5.1. Use getenv() directly.")]]
|
||||||
char* zeekenv(const char* name);
|
char* zeekenv(const char* name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -427,7 +427,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
||||||
RETSIGTYPE (*oldhandler)(int);
|
RETSIGTYPE (*oldhandler)(int);
|
||||||
|
|
||||||
zeek_script_prefixes = options.script_prefixes;
|
zeek_script_prefixes = options.script_prefixes;
|
||||||
auto zeek_prefixes = util::zeekenv("ZEEK_PREFIXES");
|
auto zeek_prefixes = getenv("ZEEK_PREFIXES");
|
||||||
|
|
||||||
if ( zeek_prefixes )
|
if ( zeek_prefixes )
|
||||||
util::tokenize_string(zeek_prefixes, ":", &zeek_script_prefixes);
|
util::tokenize_string(zeek_prefixes, ":", &zeek_script_prefixes);
|
||||||
|
@ -488,7 +488,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
||||||
supervisor_mgr = new Supervisor(std::move(cfg), std::move(*stem));
|
supervisor_mgr = new Supervisor(std::move(cfg), std::move(*stem));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* seed_load_file = util::zeekenv("ZEEK_SEED_FILE");
|
const char* seed_load_file = getenv("ZEEK_SEED_FILE");
|
||||||
|
|
||||||
if ( options.random_seed_input_file )
|
if ( options.random_seed_input_file )
|
||||||
seed_load_file = options.random_seed_input_file->data();
|
seed_load_file = options.random_seed_input_file->data();
|
||||||
|
@ -879,7 +879,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
||||||
// Drain the event queue here to support the protocols framework configuring DPM
|
// Drain the event queue here to support the protocols framework configuring DPM
|
||||||
event_mgr.Drain();
|
event_mgr.Drain();
|
||||||
|
|
||||||
if ( reporter->Errors() > 0 && ! util::zeekenv("ZEEK_ALLOW_INIT_ERRORS") )
|
if ( reporter->Errors() > 0 && ! getenv("ZEEK_ALLOW_INIT_ERRORS") )
|
||||||
reporter->FatalError("errors occurred while initializing");
|
reporter->FatalError("errors occurred while initializing");
|
||||||
|
|
||||||
run_state::detail::zeek_init_done = true;
|
run_state::detail::zeek_init_done = true;
|
||||||
|
|
|
@ -344,7 +344,7 @@ function network_time%(%): time
|
||||||
## .. zeek:see:: setenv
|
## .. zeek:see:: setenv
|
||||||
function getenv%(var: string%): string
|
function getenv%(var: string%): string
|
||||||
%{
|
%{
|
||||||
const char* env_val = zeek::util::zeekenv(var->CheckString());
|
const char* env_val = getenv(var->CheckString());
|
||||||
if ( ! env_val )
|
if ( ! env_val )
|
||||||
env_val = ""; // ###
|
env_val = ""; // ###
|
||||||
return zeek::make_intrusive<zeek::StringVal>(env_val);
|
return zeek::make_intrusive<zeek::StringVal>(env_val);
|
||||||
|
|
|
@ -71,7 +71,7 @@ Manager::Manager(const string& arg_config, const string& bro_command)
|
||||||
identifiers(), all_info(), last_identifier_seen(), incomplete_type(),
|
identifiers(), all_info(), last_identifier_seen(), incomplete_type(),
|
||||||
enum_mappings(), config(arg_config), bro_mtime()
|
enum_mappings(), config(arg_config), bro_mtime()
|
||||||
{
|
{
|
||||||
if ( util::zeekenv("ZEEK_DISABLE_ZEEKYGEN") )
|
if ( getenv("ZEEK_DISABLE_ZEEKYGEN") )
|
||||||
disabled = true;
|
disabled = true;
|
||||||
|
|
||||||
// If running bro without the "-X" option, then we don't need bro_mtime.
|
// If running bro without the "-X" option, then we don't need bro_mtime.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue