From 1535913aedd2a34002d385083d78822c598ea5b3 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Tue, 23 Nov 2010 11:06:46 +0100 Subject: [PATCH] Load plugins only once, even if listed twice --- src/libstrongswan/plugins/plugin_loader.c | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c index e1427bf15..67aa178b6 100644 --- a/src/libstrongswan/plugins/plugin_loader.c +++ b/src/libstrongswan/plugins/plugin_loader.c @@ -156,6 +156,28 @@ static plugin_t* load_plugin(private_plugin_loader_t *this, } #endif +/** + * Check if a plugin is already loaded + */ +static bool plugin_loaded(private_plugin_loader_t *this, char *name) +{ + enumerator_t *enumerator; + bool found = FALSE; + char *current; + + enumerator = this->names->create_enumerator(this->names); + while (enumerator->enumerate(enumerator, ¤t)) + { + if (streq(name, current)) + { + found = TRUE; + break; + } + } + enumerator->destroy(enumerator); + return found; +} + /** * Implementation of plugin_loader_t.load_plugins. */ @@ -186,6 +208,11 @@ static bool load(private_plugin_loader_t *this, char *path, char *list) critical = TRUE; token[len-1] = '\0'; } + if (plugin_loaded(this, token)) + { + free(token); + continue; + } plugin = load_plugin(this, path, token); if (plugin) {