|
Packit Service |
82fcde |
#include <dlfcn.h>
|
|
Packit Service |
82fcde |
#include <libintl.h>
|
|
Packit Service |
82fcde |
#include <link.h>
|
|
Packit Service |
82fcde |
#include <stdio.h>
|
|
Packit Service |
82fcde |
#include <stdlib.h>
|
|
Packit Service |
82fcde |
#include <string.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define MAPS ((struct link_map *) _r_debug.r_map)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static int
|
|
Packit Service |
82fcde |
check_loaded_objects (const char **loaded)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
struct link_map *lm;
|
|
Packit Service |
82fcde |
int n;
|
|
Packit Service |
82fcde |
int *found = NULL;
|
|
Packit Service |
82fcde |
int errors = 0;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
for (n = 0; loaded[n]; n++)
|
|
Packit Service |
82fcde |
/* NOTHING */;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (n)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
found = (int *) alloca (sizeof (int) * n);
|
|
Packit Service |
82fcde |
memset (found, 0, sizeof (int) * n);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf(" Name\n");
|
|
Packit Service |
82fcde |
printf(" --------------------------------------------------------\n");
|
|
Packit Service |
82fcde |
for (lm = MAPS; lm; lm = lm->l_next)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (lm->l_name && lm->l_name[0])
|
|
Packit Service |
82fcde |
printf(" %s, count = %d\n", lm->l_name, (int) lm->l_direct_opencount);
|
|
Packit Service |
82fcde |
if (lm->l_type == lt_loaded && lm->l_name)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int match = 0;
|
|
Packit Service |
82fcde |
for (n = 0; loaded[n] != NULL; n++)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (strcmp (basename (loaded[n]), basename (lm->l_name)) == 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
found[n] = 1;
|
|
Packit Service |
82fcde |
match = 1;
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (match == 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
++errors;
|
|
Packit Service |
82fcde |
printf ("ERRORS: %s is not unloaded\n", lm->l_name);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
for (n = 0; loaded[n] != NULL; n++)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (found[n] == 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
++errors;
|
|
Packit Service |
82fcde |
printf ("ERRORS: %s is not loaded\n", loaded[n]);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return errors;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
int
|
|
Packit Service |
82fcde |
main (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
void *obj2[2];
|
|
Packit Service |
82fcde |
void *obj3;
|
|
Packit Service |
82fcde |
const char *loaded[] = { NULL, NULL, NULL, NULL };
|
|
Packit Service |
82fcde |
int errors = 0;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf ("\nThis is what is in memory now:\n");
|
|
Packit Service |
82fcde |
errors += check_loaded_objects (loaded);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf( "Loading shared object neededobj3.so\n");
|
|
Packit Service |
82fcde |
obj3 = dlopen( "neededobj3.so", RTLD_LAZY);
|
|
Packit Service |
82fcde |
if (obj3 == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("%s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
loaded[0] = "neededobj1.so";
|
|
Packit Service |
82fcde |
loaded[1] = "neededobj2.so";
|
|
Packit Service |
82fcde |
loaded[2] = "neededobj3.so";
|
|
Packit Service |
82fcde |
errors += check_loaded_objects (loaded);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf ("Now loading shared object neededobj2.so\n");
|
|
Packit Service |
82fcde |
obj2[0] = dlopen ("neededobj2.so", RTLD_LAZY);
|
|
Packit Service |
82fcde |
if (obj2[0] == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("%s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
errors += check_loaded_objects (loaded);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf ("And loading shared object neededobj2.so again\n");
|
|
Packit Service |
82fcde |
obj2[1] = dlopen ("neededobj2.so", RTLD_LAZY);
|
|
Packit Service |
82fcde |
if (obj2[1] == NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("%s\n", dlerror ());
|
|
Packit Service |
82fcde |
exit (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
errors += check_loaded_objects (loaded);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf ("Closing neededobj2.so for the first time\n");
|
|
Packit Service |
82fcde |
dlclose (obj2[0]);
|
|
Packit Service |
82fcde |
errors += check_loaded_objects (loaded);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf ("Closing neededobj3.so\n");
|
|
Packit Service |
82fcde |
dlclose (obj3);
|
|
Packit Service |
82fcde |
loaded[2] = NULL;
|
|
Packit Service |
82fcde |
errors += check_loaded_objects (loaded);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
printf ("Closing neededobj2.so for the second time\n");
|
|
Packit Service |
82fcde |
dlclose (obj2[1]);
|
|
Packit Service |
82fcde |
loaded[0] = NULL;
|
|
Packit Service |
82fcde |
loaded[1] = NULL;
|
|
Packit Service |
82fcde |
errors += check_loaded_objects (loaded);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (errors != 0)
|
|
Packit Service |
82fcde |
printf ("%d errors found\n", errors);
|
|
Packit Service |
82fcde |
return errors;
|
|
Packit Service |
82fcde |
}
|