9 check_loaded_objects (const char **loaded
)
16 for (n
= 0; loaded
[n
]; n
++)
21 found
= (int *) alloca (sizeof (int) * n
);
22 memset (found
, 0, sizeof (int) * 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_direct_opencount
);
31 if (lm
->l_type
== lt_loaded
&& lm
->l_name
)
34 for (n
= 0; loaded
[n
] != NULL
; n
++)
36 if (strcmp (basename (loaded
[n
]), basename (lm
->l_name
)) == 0)
47 printf ("ERRORS: %s is not unloaded\n", lm
->l_name
);
52 for (n
= 0; loaded
[n
] != NULL
; n
++)
57 printf ("ERRORS: %s is not loaded\n", loaded
[n
]);
64 extern void c_function (void);
65 extern char *dirname (__const
char *__filename
);
68 main (int argc
, char **argv
)
71 const char *loaded
[] = { NULL
, NULL
, NULL
};
74 const char *dir
= dirname (argv
[0]);
80 printf ("\nThis is what is in memory now:\n");
81 errors
+= check_loaded_objects (loaded
);
83 printf( "Loading shared object neededobj6.so\n");
84 obj
= dlopen( "neededobj6.so", RTLD_LAZY
);
87 printf ("%s\n", dlerror ());
90 f
= dlsym (obj
, "a2_function");
93 printf ("%s\n", dlerror ());
97 loaded
[0] = "neededobj5.so";
98 loaded
[1] = "neededobj6.so";
99 errors
+= check_loaded_objects (loaded
);
101 printf ("Closing neededobj6.so\n");
104 errors
+= check_loaded_objects (loaded
);
106 printf ("Rename neededobj5.so\n");
107 oldfilename
= alloca (strlen (dir
) + 1 + sizeof ("neededobj5.so"));
108 strcpy (oldfilename
, dir
);
109 strcat (oldfilename
, "/");
110 strcat (oldfilename
, "neededobj5.so");
111 newfilename
= alloca (strlen (oldfilename
) + sizeof (".renamed"));
112 strcpy (newfilename
, oldfilename
);
113 strcat (newfilename
, ".renamed");
114 if (rename (oldfilename
, newfilename
))
120 printf( "Loading shared object neededobj6.so\n");
121 obj
= dlopen( "neededobj6.so", RTLD_LAZY
);
123 printf ("%s\n", dlerror ());
126 printf ("neededobj6.so should fail to load\n");
130 printf( "Loading shared object neededobj1.so\n");
131 obj
= dlopen( "neededobj1.so", RTLD_LAZY
);
134 printf ("%s\n", dlerror ());
137 errors
+= check_loaded_objects (loaded
);
138 f
= dlsym (obj
, "c_function");
141 printf ("%s\n", dlerror ());
146 printf ("Restore neededobj5.so\n");
147 if (rename (newfilename
, oldfilename
))
154 printf ("%d errors found\n", errors
);