Load plugins only once, even if listed twice
authorMartin Willi <martin@revosec.ch>
Tue, 23 Nov 2010 10:06:46 +0000 (11:06 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 5 Jan 2011 15:45:49 +0000 (16:45 +0100)
src/libstrongswan/plugins/plugin_loader.c

index e1427bf..67aa178 100644 (file)
@@ -157,6 +157,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, &current))
+       {
+               if (streq(name, current))
+               {
+                       found = TRUE;
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       return found;
+}
+
+/**
  * Implementation of plugin_loader_t.load_plugins.
  */
 static bool load(private_plugin_loader_t *this, char *path, char *list)
@@ -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)
                {