From fdd6dfd096cd5a70a74114975334e6926985df26 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Wed, 14 Jun 2023 17:23:26 +0200 Subject: [PATCH] plugin/Manager: Warn when plugin with the same name is found This was brought up on Slack as a potential source of confusion during development as it's not visible when plugin directories are ignored outside of looking into the plugin debug stream. I'd actually prefer to just FatalError() this, but a warning seems reasonably visible for interactive usage. --- src/plugin/Manager.cc | 6 +++--- testing/btest/Baseline/plugins.duplicate-pktsrc/output | 5 +++++ testing/btest/plugins/duplicate-pktsrc.zeek | 8 ++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 testing/btest/Baseline/plugins.duplicate-pktsrc/output create mode 100644 testing/btest/plugins/duplicate-pktsrc.zeek diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index 12884fdc6b..4d427a1ddf 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -112,10 +112,10 @@ void Manager::SearchDynamicPlugins(const std::string& dir) if ( name.empty() ) reporter->FatalError("empty plugin magic file %s", magic.c_str()); - if ( dynamic_plugins.find(lower_name) != dynamic_plugins.end() ) + if ( const auto& other = dynamic_plugins.find(lower_name); other != dynamic_plugins.end() ) { - DBG_LOG(DBG_PLUGINS, "Found already known plugin %s in %s, ignoring", name.c_str(), - dir.c_str()); + reporter->Warning("ignoring dynamic plugin %s from %s, already found in %s", + name.c_str(), dir.c_str(), other->second.c_str()); return; } diff --git a/testing/btest/Baseline/plugins.duplicate-pktsrc/output b/testing/btest/Baseline/plugins.duplicate-pktsrc/output new file mode 100644 index 0000000000..19f5d4978e --- /dev/null +++ b/testing/btest/Baseline/plugins.duplicate-pktsrc/output @@ -0,0 +1,5 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +warning in <...>/init-bare.zeek, line 1: ignoring dynamic plugin Demo::Foo from <...>/build, already found in <...>/build_backup +Demo::Foo - A Foo packet source (dynamic, version 1.0.0) + [Packet Source] FooPktSrc (interface prefix "foo"; supports live and trace input) + diff --git a/testing/btest/plugins/duplicate-pktsrc.zeek b/testing/btest/plugins/duplicate-pktsrc.zeek new file mode 100644 index 0000000000..aecc6190c6 --- /dev/null +++ b/testing/btest/plugins/duplicate-pktsrc.zeek @@ -0,0 +1,8 @@ +# @TEST-DOC: Loading two plugins with the same name triggers a warning. + +# @TEST-EXEC: ${DIST}/auxil/zeek-aux/plugin-support/init-plugin -u . Demo Foo +# @TEST-EXEC: cp -r %DIR/pktsrc-plugin/* . +# @TEST-EXEC: ./configure --zeek-dist=${DIST} && make +# @TEST-EXEC: cp -R build build_backup +# @TEST-EXEC: ZEEK_PLUGIN_PATH=`pwd`/build_backup:`pwd`/build zeek -NN Demo::Foo >output 2>&1 +# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output