mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +00:00
Avoid searching a directory for dynamic plugins multiple times
This commit is contained in:
parent
f2d3bf3037
commit
36099c5553
2 changed files with 20 additions and 0 deletions
|
@ -7,6 +7,8 @@
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <limits.h> // for PATH_MAX
|
||||||
|
#include <cstdlib>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -70,6 +72,19 @@ void Manager::SearchDynamicPlugins(const std::string& dir)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char canon_path[PATH_MAX];
|
||||||
|
if ( ! realpath(dir.data(), canon_path) )
|
||||||
|
{
|
||||||
|
DBG_LOG(DBG_PLUGINS, "skip dynamic plugin search in %s, realpath failed: %s",
|
||||||
|
dir.data(), strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( searched_dirs.count(canon_path) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
searched_dirs.emplace(canon_path);
|
||||||
|
|
||||||
// Check if it's a plugin dirctory.
|
// Check if it's a plugin dirctory.
|
||||||
|
|
||||||
const std::string magic = dir + "/__bro_plugin__";
|
const std::string magic = dir + "/__bro_plugin__";
|
||||||
|
|
|
@ -416,6 +416,11 @@ private:
|
||||||
void MetaHookPre(HookType hook, const HookArgumentList& args) const;
|
void MetaHookPre(HookType hook, const HookArgumentList& args) const;
|
||||||
void MetaHookPost(HookType hook, const HookArgumentList& args, const HookArgument& result) const;
|
void MetaHookPost(HookType hook, const HookArgumentList& args, const HookArgument& result) const;
|
||||||
|
|
||||||
|
// Directories that have already been searched for dynamic plugins.
|
||||||
|
// Used to prevent multiple searches of the same dirs (e.g. via symlinks).
|
||||||
|
// The paths stored in the set are made canonical via realpath().
|
||||||
|
std::set<std::string, std::less<>> searched_dirs;
|
||||||
|
|
||||||
// Plugins that were explicitly requested to be activated, but failed to
|
// Plugins that were explicitly requested to be activated, but failed to
|
||||||
// load at first.
|
// load at first.
|
||||||
std::set<std::string> requested_plugins;
|
std::set<std::string> requested_plugins;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue