mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 11:08:20 +00:00
Move zeek-setup code into namespaces
This commit is contained in:
parent
e78e68b249
commit
6a3f98c835
4 changed files with 52 additions and 39 deletions
|
@ -15,14 +15,16 @@
|
||||||
#include "bsd-getopt-long.h"
|
#include "bsd-getopt-long.h"
|
||||||
#include "logging/writers/ascii/Ascii.h"
|
#include "logging/writers/ascii/Ascii.h"
|
||||||
|
|
||||||
void zeek::Options::filter_supervisor_options()
|
namespace zeek {
|
||||||
|
|
||||||
|
void Options::filter_supervisor_options()
|
||||||
{
|
{
|
||||||
pcap_filter = {};
|
pcap_filter = {};
|
||||||
signature_files = {};
|
signature_files = {};
|
||||||
pcap_output_file = {};
|
pcap_output_file = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void zeek::Options::filter_supervised_node_options()
|
void Options::filter_supervised_node_options()
|
||||||
{
|
{
|
||||||
auto og = *this;
|
auto og = *this;
|
||||||
*this = {};
|
*this = {};
|
||||||
|
@ -64,14 +66,14 @@ void zeek::Options::filter_supervised_node_options()
|
||||||
script_options_to_set = og.script_options_to_set;
|
script_options_to_set = og.script_options_to_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zeek::fake_dns()
|
bool fake_dns()
|
||||||
{
|
{
|
||||||
return zeek::util::zeekenv("ZEEK_DNS_FAKE");
|
return zeek::util::zeekenv("ZEEK_DNS_FAKE");
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const char* zeek_version();
|
extern const char* zeek_version();
|
||||||
|
|
||||||
void zeek::usage(const char* prog, int code)
|
void usage(const char* prog, int code)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "zeek version %s\n", zeek_version());
|
fprintf(stderr, "zeek version %s\n", zeek_version());
|
||||||
|
|
||||||
|
@ -138,9 +140,9 @@ void zeek::usage(const char* prog, int code)
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
zeek::Options zeek::parse_cmdline(int argc, char** argv)
|
Options parse_cmdline(int argc, char** argv)
|
||||||
{
|
{
|
||||||
zeek::Options rval;
|
Options rval;
|
||||||
|
|
||||||
// When running unit tests, the first argument on the command line must be
|
// When running unit tests, the first argument on the command line must be
|
||||||
// --test, followed by doctest options. Optionally, users can use "--" as
|
// --test, followed by doctest options. Optionally, users can use "--" as
|
||||||
|
@ -479,3 +481,5 @@ zeek::Options zeek::parse_cmdline(int argc, char** argv)
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace zeek
|
||||||
|
|
|
@ -158,6 +158,8 @@ int& bro_argc = zeek::detail::zeek_argc;
|
||||||
char** zeek::detail::zeek_argv;
|
char** zeek::detail::zeek_argv;
|
||||||
char**& bro_argv = zeek::detail::zeek_argv;
|
char**& bro_argv = zeek::detail::zeek_argv;
|
||||||
|
|
||||||
|
namespace zeek {
|
||||||
|
|
||||||
const char* zeek_version()
|
const char* zeek_version()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -176,6 +178,8 @@ const char* zeek_version()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
static std::vector<const char*> to_cargs(const std::vector<std::string>& args)
|
static std::vector<const char*> to_cargs(const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
std::vector<const char*> rval;
|
std::vector<const char*> rval;
|
||||||
|
@ -187,7 +191,7 @@ static std::vector<const char*> to_cargs(const std::vector<std::string>& args)
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool show_plugins(int level)
|
static bool show_plugins(int level)
|
||||||
{
|
{
|
||||||
zeek::plugin::Manager::plugin_list plugins = zeek::plugin_mgr->ActivePlugins();
|
zeek::plugin::Manager::plugin_list plugins = zeek::plugin_mgr->ActivePlugins();
|
||||||
|
|
||||||
|
@ -237,7 +241,7 @@ bool show_plugins(int level)
|
||||||
return count != 0;
|
return count != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void done_with_network()
|
static void done_with_network()
|
||||||
{
|
{
|
||||||
zeek::util::detail::set_processing_status("TERMINATING", "done_with_network");
|
zeek::util::detail::set_processing_status("TERMINATING", "done_with_network");
|
||||||
|
|
||||||
|
@ -284,7 +288,7 @@ void done_with_network()
|
||||||
ZEEK_LSAN_DISABLE();
|
ZEEK_LSAN_DISABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminate_bro()
|
static void terminate_bro()
|
||||||
{
|
{
|
||||||
zeek::util::detail::set_processing_status("TERMINATING", "terminate_bro");
|
zeek::util::detail::set_processing_status("TERMINATING", "terminate_bro");
|
||||||
|
|
||||||
|
@ -344,30 +348,6 @@ void terminate_bro()
|
||||||
zeek::reporter = nullptr;
|
zeek::reporter = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace zeek::net::detail {
|
|
||||||
|
|
||||||
void zeek_terminate_loop(const char* reason)
|
|
||||||
{
|
|
||||||
zeek::util::detail::set_processing_status("TERMINATING", reason);
|
|
||||||
zeek::reporter->Info("%s", reason);
|
|
||||||
|
|
||||||
net_get_final_stats();
|
|
||||||
done_with_network();
|
|
||||||
net_delete();
|
|
||||||
|
|
||||||
terminate_bro();
|
|
||||||
|
|
||||||
// Close files after net_delete(), because net_delete()
|
|
||||||
// might write to connection content files.
|
|
||||||
zeek::File::CloseOpenFiles();
|
|
||||||
|
|
||||||
delete zeek::detail::rule_matcher;
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace zeek::net::detail
|
|
||||||
|
|
||||||
RETSIGTYPE sig_handler(int signo)
|
RETSIGTYPE sig_handler(int signo)
|
||||||
{
|
{
|
||||||
zeek::util::detail::set_processing_status("TERMINATING", "sig_handler");
|
zeek::util::detail::set_processing_status("TERMINATING", "sig_handler");
|
||||||
|
@ -407,7 +387,7 @@ static std::vector<std::string> get_script_signature_files()
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv,
|
zeek::detail::SetupResult setup(int argc, char** argv,
|
||||||
zeek::Options* zopts)
|
zeek::Options* zopts)
|
||||||
{
|
{
|
||||||
ZEEK_LSAN_DISABLE();
|
ZEEK_LSAN_DISABLE();
|
||||||
|
@ -898,7 +878,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv,
|
||||||
return {0, std::move(options)};
|
return {0, std::move(options)};
|
||||||
}
|
}
|
||||||
|
|
||||||
int zeek::detail::cleanup(bool did_net_run)
|
int cleanup(bool did_net_run)
|
||||||
{
|
{
|
||||||
if ( did_net_run )
|
if ( did_net_run )
|
||||||
done_with_network();
|
done_with_network();
|
||||||
|
@ -920,3 +900,30 @@ int zeek::detail::cleanup(bool did_net_run)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
namespace net::detail {
|
||||||
|
|
||||||
|
void zeek_terminate_loop(const char* reason)
|
||||||
|
{
|
||||||
|
zeek::util::detail::set_processing_status("TERMINATING", reason);
|
||||||
|
zeek::reporter->Info("%s", reason);
|
||||||
|
|
||||||
|
net_get_final_stats();
|
||||||
|
zeek::detail::done_with_network();
|
||||||
|
net_delete();
|
||||||
|
|
||||||
|
zeek::detail::terminate_bro();
|
||||||
|
|
||||||
|
// Close files after net_delete(), because net_delete()
|
||||||
|
// might write to connection content files.
|
||||||
|
zeek::File::CloseOpenFiles();
|
||||||
|
|
||||||
|
delete zeek::detail::rule_matcher;
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace net::detail
|
||||||
|
} // namespace zeek
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
|
||||||
namespace zeek { namespace detail {
|
namespace zeek::detail {
|
||||||
|
|
||||||
struct SetupResult {
|
struct SetupResult {
|
||||||
int code = 0;
|
int code = 0;
|
||||||
|
@ -28,4 +28,4 @@ SetupResult setup(int argc, char** argv, zeek::Options* options = nullptr);
|
||||||
*/
|
*/
|
||||||
int cleanup(bool did_net_run);
|
int cleanup(bool did_net_run);
|
||||||
|
|
||||||
}} // namespace zeek::detail
|
} // namespace zeek::detail
|
||||||
|
|
|
@ -1806,7 +1806,9 @@ function getpid%(%) : count
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%%{
|
%%{
|
||||||
|
namespace zeek {
|
||||||
extern const char* zeek_version();
|
extern const char* zeek_version();
|
||||||
|
} // namespace zeek
|
||||||
%%}
|
%%}
|
||||||
|
|
||||||
## Returns the Zeek version string.
|
## Returns the Zeek version string.
|
||||||
|
@ -1814,7 +1816,7 @@ extern const char* zeek_version();
|
||||||
## Returns: Zeek's version, e.g., 2.0-beta-47-debug.
|
## Returns: Zeek's version, e.g., 2.0-beta-47-debug.
|
||||||
function zeek_version%(%): string
|
function zeek_version%(%): string
|
||||||
%{
|
%{
|
||||||
return zeek::make_intrusive<zeek::StringVal>(zeek_version());
|
return zeek::make_intrusive<zeek::StringVal>(zeek::zeek_version());
|
||||||
%}
|
%}
|
||||||
|
|
||||||
## Converts a record type name to a vector of strings, where each element is
|
## Converts a record type name to a vector of strings, where each element is
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue