From df40e82fd63f47c6032031fe144f865e5985f02a Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Fri, 6 Nov 2020 11:58:41 +0000 Subject: [PATCH] When attempting to activate a plugin, load dynamic libraries first. Just moving code. This is so that we can abort if dlopen() fails without having changed any other state yet. --- src/plugin/Manager.cc | 104 +++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index 6f20c7b516..8598e3fe3d 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -175,58 +175,6 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_ DBG_LOG(DBG_PLUGINS, "Activating plugin %s", name.c_str()); - // Add the "scripts" and "bif" directories to ZEEKPATH. - std::string scripts = dir + "scripts"; - - if ( util::is_dir(scripts) ) - { - DBG_LOG(DBG_PLUGINS, " Adding %s to ZEEKPATH", scripts.c_str()); - util::detail::add_to_zeek_path(scripts); - } - - string init; - - // First load {scripts}/__preload__.zeek automatically. - for (const string& ext : util::detail::script_extensions) - { - init = dir + "scripts/__preload__" + ext; - - if ( util::is_file(init) ) - { - DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str()); - util::detail::warn_if_legacy_script(init); - scripts_to_load.push_back(init); - break; - } - } - - // Load {bif,scripts}/__load__.zeek automatically. - for (const string& ext : util::detail::script_extensions) - { - init = dir + "lib/bif/__load__" + ext; - - if ( util::is_file(init) ) - { - DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str()); - util::detail::warn_if_legacy_script(init); - scripts_to_load.push_back(init); - break; - } - } - - for (const string& ext : util::detail::script_extensions) - { - init = dir + "scripts/__load__" + ext; - - if ( util::is_file(init) ) - { - DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str()); - util::detail::warn_if_legacy_script(init); - scripts_to_load.push_back(init); - break; - } - } - // Load shared libraries. string dypattern = dir + "/lib/*." + HOST_ARCHITECTURE + DYNAMIC_PLUGIN_SUFFIX; @@ -288,6 +236,58 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_ DBG_LOG(DBG_PLUGINS, " No shared library found"); } + // Add the "scripts" and "bif" directories to ZEEKPATH. + std::string scripts = dir + "scripts"; + + if ( util::is_dir(scripts) ) + { + DBG_LOG(DBG_PLUGINS, " Adding %s to ZEEKPATH", scripts.c_str()); + util::detail::add_to_zeek_path(scripts); + } + + string init; + + // First load {scripts}/__preload__.zeek automatically. + for (const string& ext : util::detail::script_extensions) + { + init = dir + "scripts/__preload__" + ext; + + if ( util::is_file(init) ) + { + DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str()); + util::detail::warn_if_legacy_script(init); + scripts_to_load.push_back(init); + break; + } + } + + // Load {bif,scripts}/__load__.zeek automatically. + for (const string& ext : util::detail::script_extensions) + { + init = dir + "lib/bif/__load__" + ext; + + if ( util::is_file(init) ) + { + DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str()); + util::detail::warn_if_legacy_script(init); + scripts_to_load.push_back(init); + break; + } + } + + for (const string& ext : util::detail::script_extensions) + { + init = dir + "scripts/__load__" + ext; + + if ( util::is_file(init) ) + { + DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str()); + util::detail::warn_if_legacy_script(init); + scripts_to_load.push_back(init); + break; + } + } + // Mark this plugin as activated by clearing the path. m->second.clear();