aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-01-02 11:24:26 +0100
committerChristian Grothoff <christian@grothoff.org>2021-01-02 11:24:26 +0100
commit0d4337da23548f4779d44c1416f51f087261141e (patch)
treef7245034610181fa0e2b1f8b703465809b130680
parent155aa7bb9c96c9eed6f3ce1007ecbb7d7ee823c7 (diff)
downloadgnunet-0d4337da23548f4779d44c1416f51f087261141e.tar.gz
gnunet-0d4337da23548f4779d44c1416f51f087261141e.zip
fix /proc/PID/maps parser format string
-rw-r--r--contrib/Makefile.inc3
-rw-r--r--src/util/os_installation.c23
-rw-r--r--src/util/plugin.c71
3 files changed, 64 insertions, 33 deletions
diff --git a/contrib/Makefile.inc b/contrib/Makefile.inc
index c737a07f8..a563ef4a1 100644
--- a/contrib/Makefile.inc
+++ b/contrib/Makefile.inc
@@ -8,7 +8,8 @@ BUILDCOMMON_SHLIB_FILES = \
8 build-common/sh/lib.sh/existence_python.sh \ 8 build-common/sh/lib.sh/existence_python.sh \
9 build-common/sh/lib.sh/msg.sh \ 9 build-common/sh/lib.sh/msg.sh \
10 build-common/sh/lib.sh/progname.sh \ 10 build-common/sh/lib.sh/progname.sh \
11 build-common/sh/lib.sh/version_gnunet.sh 11 build-common/sh/lib.sh/version_gnunet.sh \
12 build-common/LICENSE
12 13
13BUILDCOMMON_CONF_FILES = \ 14BUILDCOMMON_CONF_FILES = \
14 build-common/conf/.dir-locals.el \ 15 build-common/conf/.dir-locals.el \
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 */
144static char * 144static char *
145get_path_from_proc_maps () 145get_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 */
180static char * 184static char *
181get_path_from_proc_exe () 185get_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 */
234static char * 238static char *
235get_path_from_NSGetExecutablePath () 239get_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 */
272static char * 276static char *
273get_path_from_dyld_image () 277get_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 */
361static char * 365static char *
362get_path_from_GNUNET_PREFIX () 366get_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 */
382static char * 386static char *
383os_get_gnunet_path () 387os_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 */
74static void 74static void
75plugin_init () 75plugin_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 */
115static void 118static void
116plugin_fini () 119plugin_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 */
135static GNUNET_PLUGIN_Callback 138static GNUNET_PLUGIN_Callback
136resolve_function (struct PluginList *plug, const char *name) 139resolve_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 */
206void * 216void *
207GNUNET_PLUGIN_load (const char *library_name, void *arg) 217GNUNET_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 */
255void * 268void *
256GNUNET_PLUGIN_unload (const char *library_name, void *arg) 269GNUNET_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 */
329static int 346static int
330find_libraries (void *cls, const char *filename) 347find_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