diff --git a/src/logging/writers/ascii/Ascii.cc b/src/logging/writers/ascii/Ascii.cc index 3d43964422..2a9ed25c7d 100644 --- a/src/logging/writers/ascii/Ascii.cc +++ b/src/logging/writers/ascii/Ascii.cc @@ -749,10 +749,9 @@ void Ascii::RotateLeftoverLogs() { auto ppf = default_ppf; if ( ! ll.post_proc_func.empty() ) { - auto func = id::find_func(ll.post_proc_func.data()); - - if ( func ) - ppf = std::move(func); + const auto& id = id::find(ll.post_proc_func.data()); + if ( id && id->GetVal() && same_type(id->GetVal()->GetType(), default_ppf->GetType()) ) + ppf = id->GetVal()->AsFuncVal()->AsFuncPtr(); else reporter->Warning( "Could not postprocess log '%s' with intended " diff --git a/testing/btest/Baseline/scripts.base.frameworks.logging.rotate-leftover-log-rotation-shadow-files-postprocessor-errors/.stderr b/testing/btest/Baseline/scripts.base.frameworks.logging.rotate-leftover-log-rotation-shadow-files-postprocessor-errors/.stderr new file mode 100644 index 0000000000..0dfb7a961f --- /dev/null +++ b/testing/btest/Baseline/scripts.base.frameworks.logging.rotate-leftover-log-rotation-shadow-files-postprocessor-errors/.stderr @@ -0,0 +1,6 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +### NOTE: This file has been sorted with diff-sort. +Rotated/postprocessed leftover log '<...>/conn.log' -> 'conn.no-date.log' +Rotated/postprocessed leftover log '<...>/dns.log' -> 'dns.no-date.log' +warning: Could not postprocess log '<...>/conn.log' with intended postprocessor function 'non_existing_rotation_postprocessor', proceeding with the default function +warning: Could not postprocess log '<...>/dns.log' with intended postprocessor function 'wrongly_typed_rotation_postprocessor', proceeding with the default function diff --git a/testing/btest/Baseline/scripts.base.frameworks.logging.rotate-leftover-log-rotation-shadow-files-postprocessor-errors/logs.cat b/testing/btest/Baseline/scripts.base.frameworks.logging.rotate-leftover-log-rotation-shadow-files-postprocessor-errors/logs.cat new file mode 100644 index 0000000000..05dd1c9670 --- /dev/null +++ b/testing/btest/Baseline/scripts.base.frameworks.logging.rotate-leftover-log-rotation-shadow-files-postprocessor-errors/logs.cat @@ -0,0 +1,3 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +leftover conn log +leftover dns log diff --git a/testing/btest/scripts/base/frameworks/logging/rotate-leftover-log-rotation-shadow-files-postprocessor-errors.zeek b/testing/btest/scripts/base/frameworks/logging/rotate-leftover-log-rotation-shadow-files-postprocessor-errors.zeek new file mode 100644 index 0000000000..42e25ff17d --- /dev/null +++ b/testing/btest/scripts/base/frameworks/logging/rotate-leftover-log-rotation-shadow-files-postprocessor-errors.zeek @@ -0,0 +1,32 @@ +# @TEST-DOC: Put a non-existing postprocessor function into a shadow file, ensure the default gets picked up. Regression test for #4562 +# +# @TEST-EXEC: echo ".log" >> .shadow.conn.log +# @TEST-EXEC: echo "non_existing_rotation_postprocessor" >> .shadow.conn.log +# @TEST-EXEC: echo "leftover conn log" > conn.log +# +# @TEST-EXEC: echo ".log" >> .shadow.dns.log +# @TEST-EXEC: echo "wrongly_typed_rotation_postprocessor" >> .shadow.dns.log +# @TEST-EXEC: echo "leftover dns log" > dns.log +# +# @TEST-EXEC: zeek -b %INPUT +# @TEST-EXEC: TEST_DIFF_CANONIFIER="$SCRIPTS/diff-remove-abspath | $SCRIPTS/diff-sort" btest-diff .stderr +# +# Ensure leftover files were removed. +# @TEST-EXEC: ! test -f .shadow.conn.log +# @TEST-EXEC: ! test -f conn.log +# @TEST-EXEC: ! test -f .shadow.dns.log +# @TEST-EXEC: ! test -f dns.log +# +# Ensure the rotated conn log ends-up in the current working directory. +# @TEST-EXEC: cat ./conn.*.log ./dns.*.log > logs.cat +# @TEST-EXEC: btest-diff logs.cat + +function wrongly_typed_rotation_postprocessor(): bool + { + exit(1); + return T; + } + +redef LogAscii::enable_leftover_log_rotation = T; +redef Log::default_rotation_interval = 1hr; +redef Log::default_rotation_date_format = "no-date";