From a052dc4e355e206f42b47337b17ed0af749bf44c Mon Sep 17 00:00:00 2001 From: Johanna Amann Date: Wed, 16 Sep 2015 15:16:04 -0700 Subject: [PATCH] Fix offset=-1 (eof) for raw reader Addresses BIT-1479 --- src/input/readers/raw/Raw.cc | 5 ++--- .../scripts.base.frameworks.input.raw.offset/out | 1 + .../scripts/base/frameworks/input/raw/offset.bro | 13 ++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/input/readers/raw/Raw.cc b/src/input/readers/raw/Raw.cc index 2aae96abf7..8a1f469ddb 100644 --- a/src/input/readers/raw/Raw.cc +++ b/src/input/readers/raw/Raw.cc @@ -303,7 +303,8 @@ bool Raw::OpenInput() if ( offset ) { int whence = (offset > 0) ? SEEK_SET : SEEK_END; - if ( fseek(file, offset, whence) < 0 ) + int64_t pos = (offset >= 0) ? offset : offset + 1; // we want -1 to be the end of the file + if ( fseek(file, pos, whence) < 0 ) { char buf[256]; strerror_r(errno, buf, sizeof(buf)); @@ -395,8 +396,6 @@ bool Raw::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fie { string offset_s = it->second; offset = strtoll(offset_s.c_str(), 0, 10); - if ( offset < 0 ) - offset++; // we want -1 to be the end of the file } else if ( it != info.config.end() ) { diff --git a/testing/btest/Baseline/scripts.base.frameworks.input.raw.offset/out b/testing/btest/Baseline/scripts.base.frameworks.input.raw.offset/out index 3af2451db9..c8dd06805b 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.input.raw.offset/out +++ b/testing/btest/Baseline/scripts.base.frameworks.input.raw.offset/out @@ -1,2 +1,3 @@ fkh:KH;fdkncv;ISEUp34:Fkdj;YVpIODhfDF F +hi diff --git a/testing/btest/scripts/base/frameworks/input/raw/offset.bro b/testing/btest/scripts/base/frameworks/input/raw/offset.bro index 8161785fdd..5ab2d84655 100644 --- a/testing/btest/scripts/base/frameworks/input/raw/offset.bro +++ b/testing/btest/scripts/base/frameworks/input/raw/offset.bro @@ -1,5 +1,8 @@ +# @TEST-EXEC: cp input.log input2.log # @TEST-EXEC: btest-bg-run bro bro -b %INPUT -# @TEST-EXEC: btest-bg-wait 5 +# @TEST-EXEC: sleep 2 +# @TEST-EXEC: echo "hi" >> input2.log +# @TEST-EXEC: btest-bg-wait 10 # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff out @TEST-START-FILE input.log @@ -7,6 +10,7 @@ sdfkh:KH;fdkncv;ISEUp34:Fkdj;YVpIODhfDF @TEST-END-FILE redef exit_only_after_terminate = T; +@load base/frameworks/communication # keep network time running global outfile: file; global try: count; @@ -21,9 +25,8 @@ event line(description: Input::EventDescription, tpe: Input::Event, s: string) { print outfile, s; try = try + 1; - if ( try == 2 ) + if ( try == 3 ) { - Input::remove("input"); close(outfile); terminate(); } @@ -39,7 +42,11 @@ event bro_init() local config_strings_two: table[string] of string = { ["offset"] = "-3", # 2 characters before end, last char is newline. }; + local config_strings_three: table[string] of string = { + ["offset"] = "-1", # End of file + }; Input::add_event([$source="../input.log", $config=config_strings, $reader=Input::READER_RAW, $mode=Input::STREAM, $name="input", $fields=Val, $ev=line, $want_record=F]); Input::add_event([$source="../input.log", $config=config_strings_two, $reader=Input::READER_RAW, $mode=Input::STREAM, $name="input2", $fields=Val, $ev=line, $want_record=F]); + Input::add_event([$source="../input2.log", $config=config_strings_three, $reader=Input::READER_RAW, $mode=Input::STREAM, $name="input3", $fields=Val, $ev=line, $want_record=F]); }