From: Martin Willi Date: Tue, 23 Nov 2010 10:06:46 +0000 (+0100) Subject: Load plugins only once, even if listed twice X-Git-Tag: 4.5.1~263 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1535913aedd2a34002d385083d78822c598ea5b3;p=thirdparty%2Fstrongswan.git Load plugins only once, even if listed twice --- diff --git a/src/libstrongswan/plugins/plugin_loader.c b/src/libstrongswan/plugins/plugin_loader.c index e1427bf150..67aa178b6e 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) {