*/
#include "platform.h"
-#include <libltdl/ltdl.h>
+#include <ltdl.h>
#include "gnunet_common.h"
#include "gnunet_os_lib.h"
#include "gnunet_plugin_lib.h"
};
+/**
+ * Have we been initialized?
+ */
+static int initialized;
+
+
/**
* Libtool search path before we started.
*/
/**
* Setup libtool paths.
*/
-void __attribute__ ((constructor)) GNUNET_PLUGIN_init ()
+static void
+plugin_init ()
{
int err;
const char *opath;
char *path;
char *cpath;
-#ifdef MINGW
- InitWinEnv (NULL);
-#endif
-
err = lt_dlinit ();
if (err > 0)
{
{
if (opath != NULL)
{
- cpath = GNUNET_malloc (strlen (path) + strlen (opath) + 4);
- strcpy (cpath, opath);
- strcat (cpath, ":");
- strcat (cpath, path);
+ GNUNET_asprintf (&cpath,
+ "%s:%s",
+ opath,
+ path);
lt_dlsetsearchpath (cpath);
GNUNET_free (path);
GNUNET_free (cpath);
/**
* Shutdown libtool.
*/
-void __attribute__ ((destructor)) GNUNET_PLUGIN_fini ()
+static void
+plugin_fini ()
{
lt_dlsetsearchpath (old_dlsearchpath);
if (old_dlsearchpath != NULL)
GNUNET_free (old_dlsearchpath);
old_dlsearchpath = NULL;
}
-
-#ifdef MINGW
- ShutdownWinEnv ();
-#endif
-
lt_dlexit ();
}
GNUNET_PLUGIN_Callback init;
void *ret;
+ if (! initialized)
+ {
+ initialized = GNUNET_YES;
+ plugin_init ();
+ }
libhandle = lt_dlopenext (library_name);
if (libhandle == NULL)
{
plugins = pos->next;
else
prev->next = pos->next;
- // lt_dlclose (pos->handle);
+ lt_dlclose (pos->handle);
GNUNET_free (pos->name);
GNUNET_free (pos);
+ if (plugins == NULL)
+ {
+ plugin_fini();
+ initialized = GNUNET_NO;
+ }
return ret;
}