aboutsummaryrefslogtreecommitdiff
path: root/src/util/plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/plugin.c')
-rw-r--r--src/util/plugin.c123
1 files changed, 60 insertions, 63 deletions
diff --git a/src/util/plugin.c b/src/util/plugin.c
index 4e960b4fe..b1c979dff 100644
--- a/src/util/plugin.c
+++ b/src/util/plugin.c
@@ -73,7 +73,7 @@ static struct PluginList *plugins;
73/** 73/**
74 * Setup libtool paths. 74 * Setup libtool paths.
75 */ 75 */
76static void 76static void
77plugin_init () 77plugin_init ()
78{ 78{
79 int err; 79 int err;
@@ -83,34 +83,31 @@ plugin_init ()
83 83
84 err = lt_dlinit (); 84 err = lt_dlinit ();
85 if (err > 0) 85 if (err > 0)
86 { 86 {
87 fprintf (stderr, 87 fprintf (stderr,
88 _("Initialization of plugin mechanism failed: %s!\n"), 88 _("Initialization of plugin mechanism failed: %s!\n"),
89 lt_dlerror ()); 89 lt_dlerror ());
90 return; 90 return;
91 } 91 }
92 opath = lt_dlgetsearchpath (); 92 opath = lt_dlgetsearchpath ();
93 if (opath != NULL) 93 if (opath != NULL)
94 old_dlsearchpath = GNUNET_strdup (opath); 94 old_dlsearchpath = GNUNET_strdup (opath);
95 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR); 95 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
96 if (path != NULL) 96 if (path != NULL)
97 {
98 if (opath != NULL)
97 { 99 {
98 if (opath != NULL) 100 GNUNET_asprintf (&cpath, "%s:%s", opath, path);
99 { 101 lt_dlsetsearchpath (cpath);
100 GNUNET_asprintf (&cpath, 102 GNUNET_free (path);
101 "%s:%s", 103 GNUNET_free (cpath);
102 opath,
103 path);
104 lt_dlsetsearchpath (cpath);
105 GNUNET_free (path);
106 GNUNET_free (cpath);
107 }
108 else
109 {
110 lt_dlsetsearchpath (path);
111 GNUNET_free (path);
112 }
113 } 104 }
105 else
106 {
107 lt_dlsetsearchpath (path);
108 GNUNET_free (path);
109 }
110 }
114} 111}
115 112
116 113
@@ -122,10 +119,10 @@ plugin_fini ()
122{ 119{
123 lt_dlsetsearchpath (old_dlsearchpath); 120 lt_dlsetsearchpath (old_dlsearchpath);
124 if (old_dlsearchpath != NULL) 121 if (old_dlsearchpath != NULL)
125 { 122 {
126 GNUNET_free (old_dlsearchpath); 123 GNUNET_free (old_dlsearchpath);
127 old_dlsearchpath = NULL; 124 old_dlsearchpath = NULL;
128 } 125 }
129 lt_dlexit (); 126 lt_dlexit ();
130} 127}
131 128
@@ -167,23 +164,23 @@ GNUNET_PLUGIN_test (const char *library_name)
167 GNUNET_PLUGIN_Callback init; 164 GNUNET_PLUGIN_Callback init;
168 struct PluginList plug; 165 struct PluginList plug;
169 166
170 if (! initialized) 167 if (!initialized)
171 { 168 {
172 initialized = GNUNET_YES; 169 initialized = GNUNET_YES;
173 plugin_init (); 170 plugin_init ();
174 } 171 }
175 libhandle = lt_dlopenext (library_name); 172 libhandle = lt_dlopenext (library_name);
176 if (libhandle == NULL) 173 if (libhandle == NULL)
177 return GNUNET_NO; 174 return GNUNET_NO;
178 plug.handle = libhandle; 175 plug.handle = libhandle;
179 plug.name = (char*) library_name; 176 plug.name = (char *) library_name;
180 init = resolve_function (&plug, "init"); 177 init = resolve_function (&plug, "init");
181 if (init == NULL) 178 if (init == NULL)
182 { 179 {
183 GNUNET_break (0); 180 GNUNET_break (0);
184 lt_dlclose (libhandle); 181 lt_dlclose (libhandle);
185 return GNUNET_NO; 182 return GNUNET_NO;
186 } 183 }
187 lt_dlclose (libhandle); 184 lt_dlclose (libhandle);
188 return GNUNET_YES; 185 return GNUNET_YES;
189} 186}
@@ -209,19 +206,19 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
209 GNUNET_PLUGIN_Callback init; 206 GNUNET_PLUGIN_Callback init;
210 void *ret; 207 void *ret;
211 208
212 if (! initialized) 209 if (!initialized)
213 { 210 {
214 initialized = GNUNET_YES; 211 initialized = GNUNET_YES;
215 plugin_init (); 212 plugin_init ();
216 } 213 }
217 libhandle = lt_dlopenext (library_name); 214 libhandle = lt_dlopenext (library_name);
218 if (libhandle == NULL) 215 if (libhandle == NULL)
219 { 216 {
220 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
221 _("`%s' failed for library `%s' with error: %s\n"), 218 _("`%s' failed for library `%s' with error: %s\n"),
222 "lt_dlopenext", library_name, lt_dlerror ()); 219 "lt_dlopenext", library_name, lt_dlerror ());
223 return NULL; 220 return NULL;
224 } 221 }
225 plug = GNUNET_malloc (sizeof (struct PluginList)); 222 plug = GNUNET_malloc (sizeof (struct PluginList));
226 plug->handle = libhandle; 223 plug->handle = libhandle;
227 plug->name = GNUNET_strdup (library_name); 224 plug->name = GNUNET_strdup (library_name);
@@ -229,13 +226,13 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
229 plugins = plug; 226 plugins = plug;
230 init = resolve_function (plug, "init"); 227 init = resolve_function (plug, "init");
231 if ((init == NULL) || (NULL == (ret = init (arg)))) 228 if ((init == NULL) || (NULL == (ret = init (arg))))
232 { 229 {
233 lt_dlclose (libhandle); 230 lt_dlclose (libhandle);
234 GNUNET_free (plug->name); 231 GNUNET_free (plug->name);
235 plugins = plug->next; 232 plugins = plug->next;
236 GNUNET_free (plug); 233 GNUNET_free (plug);
237 return NULL; 234 return NULL;
238 } 235 }
239 return ret; 236 return ret;
240} 237}
241 238
@@ -259,10 +256,10 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg)
259 prev = NULL; 256 prev = NULL;
260 pos = plugins; 257 pos = plugins;
261 while ((pos != NULL) && (0 != strcmp (pos->name, library_name))) 258 while ((pos != NULL) && (0 != strcmp (pos->name, library_name)))
262 { 259 {
263 prev = pos; 260 prev = pos;
264 pos = pos->next; 261 pos = pos->next;
265 } 262 }
266 if (pos == NULL) 263 if (pos == NULL)
267 return NULL; 264 return NULL;
268 265
@@ -278,10 +275,10 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg)
278 GNUNET_free (pos->name); 275 GNUNET_free (pos->name);
279 GNUNET_free (pos); 276 GNUNET_free (pos);
280 if (plugins == NULL) 277 if (plugins == NULL)
281 { 278 {
282 plugin_fini(); 279 plugin_fini ();
283 initialized = GNUNET_NO; 280 initialized = GNUNET_NO;
284 } 281 }
285 return ret; 282 return ret;
286} 283}
287 284