* sysdeps/generic/allocrtsig.c: Include <testrtsig.h>, not
[glibc.git] / elf / neededtest3.c
blob38b3c6c6b718418c605c80dfea84b284525a453d
1 #include <dlfcn.h>
2 #include <libintl.h>
3 #include <link.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
8 static int
9 check_loaded_objects (const char **loaded)
11 struct link_map *lm;
12 int n;
13 int *found = NULL;
14 int errors = 0;
16 for (n = 0; loaded[n]; n++)
17 /* NOTHING */;
19 if (n)
21 found = (int *) alloca (sizeof (int) * n);
22 memset (found, 0, sizeof (int) * n);
25 printf(" Name\n");
26 printf(" --------------------------------------------------------\n");
27 for (lm = _r_debug.r_map; lm; lm = lm->l_next)
29 if (lm->l_name && lm->l_name[0])
30 printf(" %s, count = %d\n", lm->l_name, (int) lm->l_opencount);
31 if (lm->l_type == lt_loaded && lm->l_name)
33 int match = 0;
34 for (n = 0; loaded[n] != NULL; n++)
36 if (strcmp (basename (loaded[n]), basename (lm->l_name)) == 0)
38 found[n] = 1;
39 match = 1;
40 break;
44 if (match == 0)
46 ++errors;
47 printf ("ERRORS: %s is not unloaded\n", lm->l_name);
52 for (n = 0; loaded[n] != NULL; n++)
54 if (found[n] == 0)
56 ++errors;
57 printf ("ERRORS: %s is not loaded\n", loaded[n]);
61 return errors;
64 int
65 main (void)
67 void *obj2;
68 void *obj3;
69 void *obj4;
70 const char *loaded[] = { NULL, NULL, NULL, NULL, NULL };
71 int errors = 0;
73 printf ("\nThis is what is in memory now:\n");
74 errors += check_loaded_objects (loaded);
76 printf ("Now loading shared object neededobj2.so\n");
77 obj2 = dlopen ("neededobj2.so", RTLD_LAZY);
78 if (obj2 == NULL)
80 printf ("%s\n", dlerror ());
81 exit (1);
83 loaded[0] = "neededobj1.so";
84 loaded[1] = "neededobj2.so";
85 errors += check_loaded_objects (loaded);
87 printf( "Loading shared object neededobj3.so\n");
88 obj3 = dlopen( "neededobj3.so", RTLD_LAZY);
89 if (obj3 == NULL)
91 printf ("%s\n", dlerror ());
92 exit (1);
94 loaded[2] = "neededobj3.so";
95 errors += check_loaded_objects (loaded);
98 printf( "Loading shared object neededobj4.so\n");
99 obj4 = dlopen( "neededobj4.so", RTLD_LAZY);
100 if (obj4 == NULL)
102 printf ("%s\n", dlerror ());
103 exit (1);
105 loaded[3] = "neededobj4.so";
106 errors += check_loaded_objects (loaded);
108 printf ("Closing neededobj2.so\n");
109 dlclose (obj2);
110 errors += check_loaded_objects (loaded);
112 printf ("Closing neededobj3.so\n");
113 dlclose (obj3);
114 errors += check_loaded_objects (loaded);
116 printf ("Closing neededobj4.so\n");
117 dlclose (obj4);
118 loaded[0] = NULL;
119 loaded[1] = NULL;
120 loaded[2] = NULL;
121 loaded[3] = NULL;
122 errors += check_loaded_objects (loaded);
124 if (errors != 0)
125 printf ("%d errors found\n", errors);
126 return errors;