diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-01-02 11:24:26 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-01-02 11:24:26 +0100 |
commit | 0d4337da23548f4779d44c1416f51f087261141e (patch) | |
tree | f7245034610181fa0e2b1f8b703465809b130680 /src/util/plugin.c | |
parent | 155aa7bb9c96c9eed6f3ce1007ecbb7d7ee823c7 (diff) | |
download | gnunet-0d4337da23548f4779d44c1416f51f087261141e.tar.gz gnunet-0d4337da23548f4779d44c1416f51f087261141e.zip |
fix /proc/PID/maps parser format string
Diffstat (limited to 'src/util/plugin.c')
-rw-r--r-- | src/util/plugin.c | 71 |
1 files changed, 49 insertions, 22 deletions
diff --git a/src/util/plugin.c b/src/util/plugin.c index bb310ada8..d169bc911 100644 --- a/src/util/plugin.c +++ b/src/util/plugin.c | |||
@@ -72,7 +72,7 @@ static struct PluginList *plugins; | |||
72 | * Setup libtool paths. | 72 | * Setup libtool paths. |
73 | */ | 73 | */ |
74 | static void | 74 | static void |
75 | plugin_init () | 75 | plugin_init (void) |
76 | { | 76 | { |
77 | int err; | 77 | int err; |
78 | const char *opath; | 78 | const char *opath; |
@@ -95,7 +95,10 @@ plugin_init () | |||
95 | { | 95 | { |
96 | if (NULL != opath) | 96 | if (NULL != opath) |
97 | { | 97 | { |
98 | GNUNET_asprintf (&cpath, "%s:%s", opath, path); | 98 | GNUNET_asprintf (&cpath, |
99 | "%s:%s", | ||
100 | opath, | ||
101 | path); | ||
99 | lt_dlsetsearchpath (cpath); | 102 | lt_dlsetsearchpath (cpath); |
100 | GNUNET_free (path); | 103 | GNUNET_free (path); |
101 | GNUNET_free (cpath); | 104 | GNUNET_free (cpath); |
@@ -113,7 +116,7 @@ plugin_init () | |||
113 | * Shutdown libtool. | 116 | * Shutdown libtool. |
114 | */ | 117 | */ |
115 | static void | 118 | static void |
116 | plugin_fini () | 119 | plugin_fini (void) |
117 | { | 120 | { |
118 | lt_dlsetsearchpath (old_dlsearchpath); | 121 | lt_dlsetsearchpath (old_dlsearchpath); |
119 | if (NULL != old_dlsearchpath) | 122 | if (NULL != old_dlsearchpath) |
@@ -133,15 +136,21 @@ plugin_fini () | |||
133 | * @return NULL if the symbol was not found | 136 | * @return NULL if the symbol was not found |
134 | */ | 137 | */ |
135 | static GNUNET_PLUGIN_Callback | 138 | static GNUNET_PLUGIN_Callback |
136 | resolve_function (struct PluginList *plug, const char *name) | 139 | resolve_function (struct PluginList *plug, |
140 | const char *name) | ||
137 | { | 141 | { |
138 | char *initName; | 142 | char *initName; |
139 | void *mptr; | 143 | void *mptr; |
140 | 144 | ||
141 | GNUNET_asprintf (&initName, "_%s_%s", plug->name, name); | 145 | GNUNET_asprintf (&initName, |
142 | mptr = lt_dlsym (plug->handle, &initName[1]); | 146 | "_%s_%s", |
147 | plug->name, | ||
148 | name); | ||
149 | mptr = lt_dlsym (plug->handle, | ||
150 | &initName[1]); | ||
143 | if (NULL == mptr) | 151 | if (NULL == mptr) |
144 | mptr = lt_dlsym (plug->handle, initName); | 152 | mptr = lt_dlsym (plug->handle, |
153 | initName); | ||
145 | if (NULL == mptr) | 154 | if (NULL == mptr) |
146 | LOG (GNUNET_ERROR_TYPE_ERROR, | 155 | LOG (GNUNET_ERROR_TYPE_ERROR, |
147 | _ ("`%s' failed to resolve method '%s' with error: %s\n"), | 156 | _ ("`%s' failed to resolve method '%s' with error: %s\n"), |
@@ -179,7 +188,8 @@ GNUNET_PLUGIN_test (const char *library_name) | |||
179 | return GNUNET_NO; | 188 | return GNUNET_NO; |
180 | plug.handle = libhandle; | 189 | plug.handle = libhandle; |
181 | plug.name = (char *) library_name; | 190 | plug.name = (char *) library_name; |
182 | init = resolve_function (&plug, "init"); | 191 | init = resolve_function (&plug, |
192 | "init"); | ||
183 | if (NULL == init) | 193 | if (NULL == init) |
184 | { | 194 | { |
185 | GNUNET_break (0); | 195 | GNUNET_break (0); |
@@ -204,7 +214,8 @@ GNUNET_PLUGIN_test (const char *library_name) | |||
204 | * @return whatever the initialization function returned | 214 | * @return whatever the initialization function returned |
205 | */ | 215 | */ |
206 | void * | 216 | void * |
207 | GNUNET_PLUGIN_load (const char *library_name, void *arg) | 217 | GNUNET_PLUGIN_load (const char *library_name, |
218 | void *arg) | ||
208 | { | 219 | { |
209 | void *libhandle; | 220 | void *libhandle; |
210 | struct PluginList *plug; | 221 | struct PluginList *plug; |
@@ -217,7 +228,7 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg) | |||
217 | plugin_init (); | 228 | plugin_init (); |
218 | } | 229 | } |
219 | libhandle = lt_dlopenext (library_name); | 230 | libhandle = lt_dlopenext (library_name); |
220 | if (libhandle == NULL) | 231 | if (NULL == libhandle) |
221 | { | 232 | { |
222 | LOG (GNUNET_ERROR_TYPE_ERROR, | 233 | LOG (GNUNET_ERROR_TYPE_ERROR, |
223 | _ ("`%s' failed for library `%s' with error: %s\n"), | 234 | _ ("`%s' failed for library `%s' with error: %s\n"), |
@@ -231,8 +242,10 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg) | |||
231 | plug->name = GNUNET_strdup (library_name); | 242 | plug->name = GNUNET_strdup (library_name); |
232 | plug->next = plugins; | 243 | plug->next = plugins; |
233 | plugins = plug; | 244 | plugins = plug; |
234 | init = resolve_function (plug, "init"); | 245 | init = resolve_function (plug, |
235 | if ((init == NULL) || (NULL == (ret = init (arg)))) | 246 | "init"); |
247 | if ( (NULL == init) || | ||
248 | (NULL == (ret = init (arg))) ) | ||
236 | { | 249 | { |
237 | lt_dlclose (libhandle); | 250 | lt_dlclose (libhandle); |
238 | GNUNET_free (plug->name); | 251 | GNUNET_free (plug->name); |
@@ -253,7 +266,8 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg) | |||
253 | * @return whatever the shutdown function returned | 266 | * @return whatever the shutdown function returned |
254 | */ | 267 | */ |
255 | void * | 268 | void * |
256 | GNUNET_PLUGIN_unload (const char *library_name, void *arg) | 269 | GNUNET_PLUGIN_unload (const char *library_name, |
270 | void *arg) | ||
257 | { | 271 | { |
258 | struct PluginList *pos; | 272 | struct PluginList *pos; |
259 | struct PluginList *prev; | 273 | struct PluginList *prev; |
@@ -262,7 +276,9 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg) | |||
262 | 276 | ||
263 | prev = NULL; | 277 | prev = NULL; |
264 | pos = plugins; | 278 | pos = plugins; |
265 | while ((NULL != pos) && (0 != strcmp (pos->name, library_name))) | 279 | while ( (NULL != pos) && |
280 | (0 != strcmp (pos->name, | ||
281 | library_name)) ) | ||
266 | { | 282 | { |
267 | prev = pos; | 283 | prev = pos; |
268 | pos = pos->next; | 284 | pos = pos->next; |
@@ -270,7 +286,8 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg) | |||
270 | if (NULL == pos) | 286 | if (NULL == pos) |
271 | return NULL; | 287 | return NULL; |
272 | 288 | ||
273 | done = resolve_function (pos, "done"); | 289 | done = resolve_function (pos, |
290 | "done"); | ||
274 | ret = NULL; | 291 | ret = NULL; |
275 | if (NULL != done) | 292 | if (NULL != done) |
276 | ret = done (arg); | 293 | ret = done (arg); |
@@ -327,7 +344,8 @@ struct LoadAllContext | |||
327 | * @return #GNUNET_OK (continue loading) | 344 | * @return #GNUNET_OK (continue loading) |
328 | */ | 345 | */ |
329 | static int | 346 | static int |
330 | find_libraries (void *cls, const char *filename) | 347 | find_libraries (void *cls, |
348 | const char *filename) | ||
331 | { | 349 | { |
332 | struct LoadAllContext *lac = cls; | 350 | struct LoadAllContext *lac = cls; |
333 | const char *slashpos; | 351 | const char *slashpos; |
@@ -338,19 +356,26 @@ find_libraries (void *cls, const char *filename) | |||
338 | size_t n; | 356 | size_t n; |
339 | 357 | ||
340 | libname = filename; | 358 | libname = filename; |
341 | while (NULL != (slashpos = strstr (libname, DIR_SEPARATOR_STR))) | 359 | while (NULL != (slashpos = strstr (libname, |
360 | DIR_SEPARATOR_STR))) | ||
342 | libname = slashpos + 1; | 361 | libname = slashpos + 1; |
343 | n = strlen (libname); | 362 | n = strlen (libname); |
344 | if (0 != strncmp (lac->basename, libname, strlen (lac->basename))) | 363 | if (0 != strncmp (lac->basename, |
364 | libname, | ||
365 | strlen (lac->basename))) | ||
345 | return GNUNET_OK; /* wrong name */ | 366 | return GNUNET_OK; /* wrong name */ |
346 | if ((n > 3) && (0 == strcmp (&libname[n - 3], ".la"))) | 367 | if ( (n > 3) && |
368 | (0 == strcmp (&libname[n - 3], ".la")) ) | ||
347 | return GNUNET_OK; /* .la file */ | 369 | return GNUNET_OK; /* .la file */ |
348 | basename = GNUNET_strdup (libname); | 370 | basename = GNUNET_strdup (libname); |
349 | if (NULL != (dot = strstr (basename, "."))) | 371 | if (NULL != (dot = strstr (basename, "."))) |
350 | *dot = '\0'; | 372 | *dot = '\0'; |
351 | lib_ret = GNUNET_PLUGIN_load (basename, lac->arg); | 373 | lib_ret = GNUNET_PLUGIN_load (basename, |
374 | lac->arg); | ||
352 | if (NULL != lib_ret) | 375 | if (NULL != lib_ret) |
353 | lac->cb (lac->cb_cls, basename, lib_ret); | 376 | lac->cb (lac->cb_cls, |
377 | basename, | ||
378 | lib_ret); | ||
354 | GNUNET_free (basename); | 379 | GNUNET_free (basename); |
355 | return GNUNET_OK; | 380 | return GNUNET_OK; |
356 | } | 381 | } |
@@ -388,7 +413,9 @@ GNUNET_PLUGIN_load_all (const char *basename, | |||
388 | lac.arg = arg; | 413 | lac.arg = arg; |
389 | lac.cb = cb; | 414 | lac.cb = cb; |
390 | lac.cb_cls = cb_cls; | 415 | lac.cb_cls = cb_cls; |
391 | GNUNET_DISK_directory_scan (path, &find_libraries, &lac); | 416 | GNUNET_DISK_directory_scan (path, |
417 | &find_libraries, | ||
418 | &lac); | ||
392 | GNUNET_free (path); | 419 | GNUNET_free (path); |
393 | } | 420 | } |
394 | 421 | ||