Allow to activate plugins from the command line by specifying their

fully-qualified name.
This commit is contained in:
Robin Sommer 2014-07-21 16:58:10 +02:00
parent c9524757d2
commit 38c69f9cd0
4 changed files with 21 additions and 4 deletions

View file

@ -855,14 +855,14 @@ int main(int argc, char** argv)
! (id_name || bst_file) && ! command_line_policy && ! print_plugins )
add_input_file("-");
// Process remaining arguments. X=Y arguments indicate script
// variable/parameter assignments. The remainder are treated
// as scripts to load.
// Process remaining arguments. X=Y arguments indicate script
// variable/parameter assignments. X::Y arguments indicate plugins to
// activate/query. The remainder are treated as scripts to load.
while ( optind < argc )
{
if ( strchr(argv[optind], '=') )
params.push_back(argv[optind++]);
else if ( print_plugins && strstr(argv[optind], "::") )
else if ( strstr(argv[optind], "::") )
requested_plugins.insert(argv[optind++]);
else
add_input_file(argv[optind++]);
@ -890,6 +890,10 @@ int main(int argc, char** argv)
file_mgr->InitPreScript();
broxygen_mgr->InitPreScript();
for ( set<string>::const_iterator i = requested_plugins.begin();
i != requested_plugins.end(); i++ )
plugin_mgr->ActivateDynamicPlugin(*i);
plugin_mgr->ActivateDynamicPlugins(! bare_mode);
if ( events_file )

View file

@ -146,6 +146,10 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
return false;
}
if ( m->second == "" )
// Already activated.
return true;
std::string dir = m->second + "/";
if ( dir.empty() )
@ -283,6 +287,8 @@ void Manager::UpdateInputFiles()
for ( file_list::const_reverse_iterator i = scripts_to_load.rbegin();
i != scripts_to_load.rend(); i++ )
add_input_file_at_front((*i).c_str());
scripts_to_load.clear();
}
static bool plugin_cmp(const Plugin* a, const Plugin* b)

View file

@ -18,3 +18,7 @@ calling bif, Hello from the plugin!
plugin: automatically loaded at startup
calling bif, Hello from the plugin!
plugin: manually loaded
===
plugin: automatically loaded at startup
calling bif, Hello from the plugin!
plugin: manually loaded

View file

@ -18,6 +18,9 @@
# @TEST-EXEC: echo === >>output
# @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -b ./activate.bro demo/foo -r $TRACES/empty.trace >>output
# @TEST-EXEC: echo === >>output
# @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -b Demo::Foo demo/foo -r $TRACES/empty.trace >>output
# @TEST-EXEC: TEST_DIFF_CANONIFIER= btest-diff output
cat >scripts/__load__.bro <<EOF