Improve zeek_script_args test case and documentation

This commit is contained in:
Jon Siwek 2020-10-13 12:09:03 -07:00
parent 39177ce8c9
commit 2d3b4dab74
7 changed files with 30 additions and 19 deletions

7
NEWS
View file

@ -34,6 +34,13 @@ New Functionality
See https://docs.zeek.org/en/master/frameworks/logging.html#filter-log-records
for more details.
- A new ``zeek_script_args`` variable contains a list of arguments passed
to a script. E.g. either when explicitly executing Zeek like
``zeek -- myscript.zeek -arg1 -arg2``, or when using Zeek as to interpret
executable scripts that contain a hashbang line at the top like::
#!/usr/local/zeek/bin/zeek --
Changed Functionality
---------------------

View file

@ -455,15 +455,15 @@ type connection: record {
};
## Arguments given to Zeek from the command line. In order to use this, Zeek
## must use the "--" command line argument, then give the script name immediately
## after the double hyphens and the provide the arguments after that. For example:
##
## must use a ``--`` command line argument immediately followed by a script
## file and additional arguments after that. For example::
##
## zeek --bare-mode -- myscript.zeek -a -b -c
##
##
## To use Zeek as an executable interpreter, include a line at the top of a script
## like the following and make the script executable:
##
## #!/usr/local/zeek/bin/zeek --
## like the following and make the script executable::
##
## #!/usr/local/zeek/bin/zeek --
const zeek_script_args: vector of string = vector();
## Default amount of time a file can be inactive before the file analysis

View file

@ -30,8 +30,6 @@ zeek::VectorType* index_vec;
zeek::VectorType* mime_matches;
zeek::RecordType* mime_match;
zeek::VectorVal* zeek_script_args;
zeek::RecordType* socks_address;
zeek::TableVal* tcp_reassembler_ports_orig;

View file

@ -663,7 +663,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
// Assign the script_args for command line processing in Zeek scripts.
if ( ! options.script_args.empty() )
{
auto script_args_val = zeek::id::find_val("zeek_script_args")->AsVectorVal();
auto script_args_val = id::find_val<VectorVal>("zeek_script_args");
for ( const string& script_arg : options.script_args )
{
script_args_val->Assign(script_args_val->Size(), make_intrusive<StringVal>(script_arg));

View file

@ -0,0 +1,14 @@
# @TEST-EXEC: printf '#!' > test.zeek
# @TEST-EXEC: printf "$BUILD/src/zeek -b --\n" >> test.zeek
# @TEST-EXEC: cat %INPUT >> test.zeek
# @TEST-EXEC: chmod u+x test.zeek
# @TEST-EXEC: zeek -b -- %INPUT -a -b -c >out
# @TEST-EXEC: $(dirname %INPUT)/test.zeek -d -e -f >>out
# @TEST-EXEC: btest-diff out
event zeek_init()
{
print zeek_script_args;
}

View file

@ -1,9 +0,0 @@
# @TEST-EXEC: zeek -b -- %INPUT -a -b -c
# @TEST-EXEC: btest-diff .stdout
event zeek_init()
{
print zeek_script_args;
}