diff --git a/src/RunState.cc b/src/RunState.cc index 7c24ee18c4..5e44eb8129 100644 --- a/src/RunState.cc +++ b/src/RunState.cc @@ -63,6 +63,7 @@ double current_wallclock = 0.0; double current_pseudo = 0.0; bool zeek_init_done = false; bool time_updated = false; +bool bare_mode = false; RETSIGTYPE watchdog(int /* signo */) { diff --git a/src/RunState.h b/src/RunState.h index 3b9171c483..d3ba66c8a3 100644 --- a/src/RunState.h +++ b/src/RunState.h @@ -65,6 +65,8 @@ extern double current_pseudo; extern bool zeek_init_done; +extern bool bare_mode; // True if Zeek was started in bare mode. + } // namespace detail // Functions to temporarily suspend processing of live input (network packets diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index f682d39118..df8294816d 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -516,6 +516,8 @@ SetupResult setup(int argc, char** argv, Options* zopts) auto options = zopts ? *zopts : parse_cmdline(argc, argv); + run_state::detail::bare_mode = options.bare_mode; + // Set up the global that facilitates access to analysis/optimization // options from deep within some modules. analysis_options = options.analysis_options; diff --git a/src/zeek.bif b/src/zeek.bif index a1fc14b26c..39a73af809 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1748,6 +1748,20 @@ function zeek_version%(%): string return zeek::make_intrusive(zeek::zeek_version()); %} +%%{ +namespace zeek::run_state::detail { +extern bool bare_mode; +} // namespace zeek::run_state::detail +%%} + +## Returns whether Zeek was started in bare mode. +## +## Returns: True if Zeek was started in bare mode, false otherwise. +function bare_mode%(%): bool + %{ + return zeek::val_mgr->Bool(zeek::run_state::detail::bare_mode); + %} + ## Converts a record type name to a vector of strings, where each element is ## the name of a record field. Nested records are flattened. ## diff --git a/testing/btest/Baseline/bifs.bare_mode/output b/testing/btest/Baseline/bifs.bare_mode/output new file mode 100644 index 0000000000..1956db8698 --- /dev/null +++ b/testing/btest/Baseline/bifs.bare_mode/output @@ -0,0 +1,3 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +F +T diff --git a/testing/btest/bifs/bare_mode.zeek b/testing/btest/bifs/bare_mode.zeek new file mode 100644 index 0000000000..5183cde7d3 --- /dev/null +++ b/testing/btest/bifs/bare_mode.zeek @@ -0,0 +1,8 @@ +# @TEST-EXEC: zeek %INPUT >>output +# @TEST-EXEC: zeek -b %INPUT >>output +# @TEST-EXEC: btest-diff output + +event zeek_init() + { + print bare_mode(); + }