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.
This commit is contained in:
Arne Welzel 2023-06-14 17:23:26 +02:00
parent c873857953
commit fdd6dfd096
3 changed files with 16 additions and 3 deletions

View file

@ -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;
}

View file

@ -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)

View file

@ -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