elf: Do not duplicate the GLIBC_TUNABLES string
[platform/upstream/glibc.git] / elf / loadtest.c
index 863dc53..b5eab5e 100644 (file)
@@ -5,6 +5,7 @@
 #include <mcheck.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 
 /* How many load/unload operations do we do.  */
@@ -69,12 +70,18 @@ static const struct
 
 #include <include/link.h>
 
-#define OUT \
-  for (map = _r_debug.r_map; map != NULL; map = map->l_next)                 \
-    if (map->l_type == lt_loaded)                                            \
-      printf ("name = \"%s\", opencount = %d\n",                             \
-             map->l_name, (int) map->l_opencount);                           \
-  fflush (stdout)
+#define MAPS ((struct link_map *) _r_debug.r_map)
+
+#define OUT                                                    \
+  do                                                           \
+    {                                                          \
+      for (map = MAPS; map != NULL; map = map->l_next)         \
+       if (map->l_type == lt_loaded)                           \
+         printf ("name = \"%s\", direct_opencount = %d\n",     \
+                 map->l_name, (int) map->l_direct_opencount);  \
+      fflush (stdout);                                         \
+    }                                                          \
+  while (0)
 
 
 int
@@ -139,6 +146,23 @@ main (int argc, char *argv[])
                    testobjs[index].name, testobjs[index].handle);
 
          testobjs[index].handle = NULL;
+
+         if (testobjs[0].handle == NULL
+             && testobjs[1].handle == NULL
+             && testobjs[5].handle == NULL)
+           {
+             /* In this case none of the objects above should be
+                present.  */
+             for (map = MAPS; map != NULL; map = map->l_next)
+               if (map->l_type == lt_loaded
+                   && (strstr (map->l_name, testobjs[0].name) != NULL
+                       || strstr (map->l_name, testobjs[1].name) != NULL
+                       || strstr (map->l_name, testobjs[5].name) != NULL))
+                 {
+                   printf ("`%s' is still loaded\n", map->l_name);
+                   result = 1;
+                 }
+           }
        }
 
       if (debug)
@@ -151,8 +175,8 @@ main (int argc, char *argv[])
       {
        printf ("\nclose: %s: l_initfini = %p, l_versions = %p\n",
                testobjs[count].name,
-               ((struct link_map*)testobjs[count].handle)->l_initfini,
-               ((struct link_map*)testobjs[count].handle)->l_versions);
+               ((struct link_map *) testobjs[count].handle)->l_initfini,
+               ((struct link_map *) testobjs[count].handle)->l_versions);
 
        if (dlclose (testobjs[count].handle) != 0)
          {
@@ -162,11 +186,11 @@ main (int argc, char *argv[])
       }
 
   /* Check whether all files are unloaded.  */
-  for (map = _r_debug.r_map; map != NULL; map = map->l_next)
+  for (map = MAPS; map != NULL; map = map->l_next)
     if (map->l_type == lt_loaded)
       {
-       printf ("name = \"%s\", opencount = %d\n",
-               map->l_name, (int) map->l_opencount);
+       printf ("name = \"%s\", direct_opencount = %d\n",
+               map->l_name, (int) map->l_direct_opencount);
        result = 1;
       }