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 | |
parent | 155aa7bb9c96c9eed6f3ce1007ecbb7d7ee823c7 (diff) | |
download | gnunet-0d4337da23548f4779d44c1416f51f087261141e.tar.gz gnunet-0d4337da23548f4779d44c1416f51f087261141e.zip |
fix /proc/PID/maps parser format string
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/os_installation.c | 23 | ||||
-rw-r--r-- | src/util/plugin.c | 71 |
2 files changed, 62 insertions, 32 deletions
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index 6e783a95a..d1e5e0da5 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -142,7 +142,7 @@ GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd) | |||
142 | * @return NULL on error | 142 | * @return NULL on error |
143 | */ | 143 | */ |
144 | static char * | 144 | static char * |
145 | get_path_from_proc_maps () | 145 | get_path_from_proc_maps (void) |
146 | { | 146 | { |
147 | char fn[64]; | 147 | char fn[64]; |
148 | char line[1024]; | 148 | char line[1024]; |
@@ -152,15 +152,19 @@ get_path_from_proc_maps () | |||
152 | 152 | ||
153 | if (NULL == current_pd->libname) | 153 | if (NULL == current_pd->libname) |
154 | return NULL; | 154 | return NULL; |
155 | GNUNET_snprintf (fn, sizeof(fn), "/proc/%u/maps", getpid ()); | 155 | GNUNET_snprintf (fn, |
156 | sizeof(fn), | ||
157 | "/proc/%u/maps", | ||
158 | getpid ()); | ||
156 | if (NULL == (f = fopen (fn, "r"))) | 159 | if (NULL == (f = fopen (fn, "r"))) |
157 | return NULL; | 160 | return NULL; |
158 | while (NULL != fgets (line, sizeof(line), f)) | 161 | while (NULL != fgets (line, sizeof(line), f)) |
159 | { | 162 | { |
160 | if ((1 == sscanf (line, | 163 | if ((1 == sscanf (line, |
161 | "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s", | 164 | "%*p-%*p %*c%*c%*c%*c %*x %*x:%*x %*u%*[ ]%1023s", |
162 | dir)) && | 165 | dir)) && |
163 | (NULL != (lgu = strstr (dir, current_pd->libname)))) | 166 | (NULL != (lgu = strstr (dir, |
167 | current_pd->libname)))) | ||
164 | { | 168 | { |
165 | lgu[0] = '\0'; | 169 | lgu[0] = '\0'; |
166 | fclose (f); | 170 | fclose (f); |
@@ -178,7 +182,7 @@ get_path_from_proc_maps () | |||
178 | * @return NULL on error | 182 | * @return NULL on error |
179 | */ | 183 | */ |
180 | static char * | 184 | static char * |
181 | get_path_from_proc_exe () | 185 | get_path_from_proc_exe (void) |
182 | { | 186 | { |
183 | char fn[64]; | 187 | char fn[64]; |
184 | char lnk[1024]; | 188 | char lnk[1024]; |
@@ -232,7 +236,7 @@ typedef int (*MyNSGetExecutablePathProto) (char *buf, size_t *bufsize); | |||
232 | * @return NULL on error | 236 | * @return NULL on error |
233 | */ | 237 | */ |
234 | static char * | 238 | static char * |
235 | get_path_from_NSGetExecutablePath () | 239 | get_path_from_NSGetExecutablePath (void) |
236 | { | 240 | { |
237 | static char zero = '\0'; | 241 | static char zero = '\0'; |
238 | char *path; | 242 | char *path; |
@@ -270,7 +274,7 @@ get_path_from_NSGetExecutablePath () | |||
270 | * @return NULL on error | 274 | * @return NULL on error |
271 | */ | 275 | */ |
272 | static char * | 276 | static char * |
273 | get_path_from_dyld_image () | 277 | get_path_from_dyld_image (void) |
274 | { | 278 | { |
275 | const char *path; | 279 | const char *path; |
276 | char *p; | 280 | char *p; |
@@ -359,7 +363,7 @@ get_path_from_PATH (const char *binary) | |||
359 | * @return NULL on error (environment variable not set) | 363 | * @return NULL on error (environment variable not set) |
360 | */ | 364 | */ |
361 | static char * | 365 | static char * |
362 | get_path_from_GNUNET_PREFIX () | 366 | get_path_from_GNUNET_PREFIX (void) |
363 | { | 367 | { |
364 | const char *p; | 368 | const char *p; |
365 | 369 | ||
@@ -380,7 +384,7 @@ get_path_from_GNUNET_PREFIX () | |||
380 | * @return a pointer to the executable path, or NULL on error | 384 | * @return a pointer to the executable path, or NULL on error |
381 | */ | 385 | */ |
382 | static char * | 386 | static char * |
383 | os_get_gnunet_path () | 387 | os_get_gnunet_path (void) |
384 | { | 388 | { |
385 | char *ret; | 389 | char *ret; |
386 | 390 | ||
@@ -461,7 +465,6 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
461 | * guess for the current app */ | 465 | * guess for the current app */ |
462 | if (NULL == execpath) | 466 | if (NULL == execpath) |
463 | execpath = os_get_gnunet_path (); | 467 | execpath = os_get_gnunet_path (); |
464 | |||
465 | if (NULL == execpath) | 468 | if (NULL == execpath) |
466 | return NULL; | 469 | return NULL; |
467 | 470 | ||
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 | ||