Browse Source

fix /proc/PID/maps parser format string

Christian Grothoff 3 years ago
parent
commit
0d4337da23
3 changed files with 64 additions and 33 deletions
  1. 2 1
      contrib/Makefile.inc
  2. 13 10
      src/util/os_installation.c
  3. 49 22
      src/util/plugin.c

+ 2 - 1
contrib/Makefile.inc

@@ -8,7 +8,8 @@ BUILDCOMMON_SHLIB_FILES = \
     build-common/sh/lib.sh/existence_python.sh \
     build-common/sh/lib.sh/msg.sh \
     build-common/sh/lib.sh/progname.sh \
-    build-common/sh/lib.sh/version_gnunet.sh
+    build-common/sh/lib.sh/version_gnunet.sh \
+    build-common/LICENSE
 
 BUILDCOMMON_CONF_FILES = \
     build-common/conf/.dir-locals.el \

+ 13 - 10
src/util/os_installation.c

@@ -142,7 +142,7 @@ GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd)
  * @return NULL on error
  */
 static char *
-get_path_from_proc_maps ()
+get_path_from_proc_maps (void)
 {
   char fn[64];
   char line[1024];
@@ -152,15 +152,19 @@ get_path_from_proc_maps ()
 
   if (NULL == current_pd->libname)
     return NULL;
-  GNUNET_snprintf (fn, sizeof(fn), "/proc/%u/maps", getpid ());
+  GNUNET_snprintf (fn,
+                   sizeof(fn),
+                   "/proc/%u/maps",
+                   getpid ());
   if (NULL == (f = fopen (fn, "r")))
     return NULL;
   while (NULL != fgets (line, sizeof(line), f))
   {
     if ((1 == sscanf (line,
-                      "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s",
+                      "%*p-%*p %*c%*c%*c%*c %*x %*x:%*x %*u%*[ ]%1023s",
                       dir)) &&
-        (NULL != (lgu = strstr (dir, current_pd->libname))))
+        (NULL != (lgu = strstr (dir,
+                                current_pd->libname))))
     {
       lgu[0] = '\0';
       fclose (f);
@@ -178,7 +182,7 @@ get_path_from_proc_maps ()
  * @return NULL on error
  */
 static char *
-get_path_from_proc_exe ()
+get_path_from_proc_exe (void)
 {
   char fn[64];
   char lnk[1024];
@@ -232,7 +236,7 @@ typedef int (*MyNSGetExecutablePathProto) (char *buf, size_t *bufsize);
  * @return NULL on error
  */
 static char *
-get_path_from_NSGetExecutablePath ()
+get_path_from_NSGetExecutablePath (void)
 {
   static char zero = '\0';
   char *path;
@@ -270,7 +274,7 @@ get_path_from_NSGetExecutablePath ()
  * @return NULL on error
  */
 static char *
-get_path_from_dyld_image ()
+get_path_from_dyld_image (void)
 {
   const char *path;
   char *p;
@@ -359,7 +363,7 @@ get_path_from_PATH (const char *binary)
  * @return NULL on error (environment variable not set)
  */
 static char *
-get_path_from_GNUNET_PREFIX ()
+get_path_from_GNUNET_PREFIX (void)
 {
   const char *p;
 
@@ -380,7 +384,7 @@ get_path_from_GNUNET_PREFIX ()
  * @return a pointer to the executable path, or NULL on error
  */
 static char *
-os_get_gnunet_path ()
+os_get_gnunet_path (void)
 {
   char *ret;
 
@@ -461,7 +465,6 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
    * guess for the current app */
   if (NULL == execpath)
     execpath = os_get_gnunet_path ();
-
   if (NULL == execpath)
     return NULL;
 

+ 49 - 22
src/util/plugin.c

@@ -72,7 +72,7 @@ static struct PluginList *plugins;
  * Setup libtool paths.
  */
 static void
-plugin_init ()
+plugin_init (void)
 {
   int err;
   const char *opath;
@@ -95,7 +95,10 @@ plugin_init ()
   {
     if (NULL != opath)
     {
-      GNUNET_asprintf (&cpath, "%s:%s", opath, path);
+      GNUNET_asprintf (&cpath,
+                       "%s:%s",
+                       opath,
+                       path);
       lt_dlsetsearchpath (cpath);
       GNUNET_free (path);
       GNUNET_free (cpath);
@@ -113,7 +116,7 @@ plugin_init ()
  * Shutdown libtool.
  */
 static void
-plugin_fini ()
+plugin_fini (void)
 {
   lt_dlsetsearchpath (old_dlsearchpath);
   if (NULL != old_dlsearchpath)
@@ -133,15 +136,21 @@ plugin_fini ()
  * @return NULL if the symbol was not found
  */
 static GNUNET_PLUGIN_Callback
-resolve_function (struct PluginList *plug, const char *name)
+resolve_function (struct PluginList *plug,
+                  const char *name)
 {
   char *initName;
   void *mptr;
 
-  GNUNET_asprintf (&initName, "_%s_%s", plug->name, name);
-  mptr = lt_dlsym (plug->handle, &initName[1]);
+  GNUNET_asprintf (&initName,
+                   "_%s_%s",
+                   plug->name,
+                   name);
+  mptr = lt_dlsym (plug->handle,
+                   &initName[1]);
   if (NULL == mptr)
-    mptr = lt_dlsym (plug->handle, initName);
+    mptr = lt_dlsym (plug->handle,
+                     initName);
   if (NULL == mptr)
     LOG (GNUNET_ERROR_TYPE_ERROR,
          _ ("`%s' failed to resolve method '%s' with error: %s\n"),
@@ -179,7 +188,8 @@ GNUNET_PLUGIN_test (const char *library_name)
     return GNUNET_NO;
   plug.handle = libhandle;
   plug.name = (char *) library_name;
-  init = resolve_function (&plug, "init");
+  init = resolve_function (&plug,
+                           "init");
   if (NULL == init)
   {
     GNUNET_break (0);
@@ -204,7 +214,8 @@ GNUNET_PLUGIN_test (const char *library_name)
  * @return whatever the initialization function returned
  */
 void *
-GNUNET_PLUGIN_load (const char *library_name, void *arg)
+GNUNET_PLUGIN_load (const char *library_name,
+                    void *arg)
 {
   void *libhandle;
   struct PluginList *plug;
@@ -217,7 +228,7 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
     plugin_init ();
   }
   libhandle = lt_dlopenext (library_name);
-  if (libhandle == NULL)
+  if (NULL == libhandle)
   {
     LOG (GNUNET_ERROR_TYPE_ERROR,
          _ ("`%s' failed for library `%s' with error: %s\n"),
@@ -231,8 +242,10 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
   plug->name = GNUNET_strdup (library_name);
   plug->next = plugins;
   plugins = plug;
-  init = resolve_function (plug, "init");
-  if ((init == NULL) || (NULL == (ret = init (arg))))
+  init = resolve_function (plug,
+                           "init");
+  if ( (NULL == init) ||
+       (NULL == (ret = init (arg))) )
   {
     lt_dlclose (libhandle);
     GNUNET_free (plug->name);
@@ -253,7 +266,8 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
  * @return whatever the shutdown function returned
  */
 void *
-GNUNET_PLUGIN_unload (const char *library_name, void *arg)
+GNUNET_PLUGIN_unload (const char *library_name,
+                      void *arg)
 {
   struct PluginList *pos;
   struct PluginList *prev;
@@ -262,7 +276,9 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg)
 
   prev = NULL;
   pos = plugins;
-  while ((NULL != pos) && (0 != strcmp (pos->name, library_name)))
+  while ( (NULL != pos) &&
+          (0 != strcmp (pos->name,
+                        library_name)) )
   {
     prev = pos;
     pos = pos->next;
@@ -270,7 +286,8 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg)
   if (NULL == pos)
     return NULL;
 
-  done = resolve_function (pos, "done");
+  done = resolve_function (pos,
+                           "done");
   ret = NULL;
   if (NULL != done)
     ret = done (arg);
@@ -327,7 +344,8 @@ struct LoadAllContext
  * @return #GNUNET_OK (continue loading)
  */
 static int
-find_libraries (void *cls, const char *filename)
+find_libraries (void *cls,
+                const char *filename)
 {
   struct LoadAllContext *lac = cls;
   const char *slashpos;
@@ -338,19 +356,26 @@ find_libraries (void *cls, const char *filename)
   size_t n;
 
   libname = filename;
-  while (NULL != (slashpos = strstr (libname, DIR_SEPARATOR_STR)))
+  while (NULL != (slashpos = strstr (libname,
+                                     DIR_SEPARATOR_STR)))
     libname = slashpos + 1;
   n = strlen (libname);
-  if (0 != strncmp (lac->basename, libname, strlen (lac->basename)))
+  if (0 != strncmp (lac->basename,
+                    libname,
+                    strlen (lac->basename)))
     return GNUNET_OK; /* wrong name */
-  if ((n > 3) && (0 == strcmp (&libname[n - 3], ".la")))
+  if ( (n > 3) &&
+       (0 == strcmp (&libname[n - 3], ".la")) )
     return GNUNET_OK; /* .la file */
   basename = GNUNET_strdup (libname);
   if (NULL != (dot = strstr (basename, ".")))
     *dot = '\0';
-  lib_ret = GNUNET_PLUGIN_load (basename, lac->arg);
+  lib_ret = GNUNET_PLUGIN_load (basename,
+                                lac->arg);
   if (NULL != lib_ret)
-    lac->cb (lac->cb_cls, basename, lib_ret);
+    lac->cb (lac->cb_cls,
+             basename,
+             lib_ret);
   GNUNET_free (basename);
   return GNUNET_OK;
 }
@@ -388,7 +413,9 @@ GNUNET_PLUGIN_load_all (const char *basename,
   lac.arg = arg;
   lac.cb = cb;
   lac.cb_cls = cb_cls;
-  GNUNET_DISK_directory_scan (path, &find_libraries, &lac);
+  GNUNET_DISK_directory_scan (path,
+                              &find_libraries,
+                              &lac);
   GNUNET_free (path);
 }