about summary refs log tree commit diff
path: root/elf/neededtest4.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-12-31 06:09:08 +0000
committerUlrich Drepper <drepper@redhat.com>2000-12-31 06:09:08 +0000
commitc77a447822c8ccc6866216bad737189fff3a0b93 (patch)
tree83529a631cd6887c71795711ce58620d57bf7d7b /elf/neededtest4.c
parentd9af88677f42690b7ad4cacecc7f9b6a62fe50ce (diff)
downloadglibc-c77a447822c8ccc6866216bad737189fff3a0b93.tar.gz
glibc-c77a447822c8ccc6866216bad737189fff3a0b93.tar.xz
glibc-c77a447822c8ccc6866216bad737189fff3a0b93.zip
Update.
2000-12-30  Ulrich Drepper  <drepper@redhat.com>

	* elf/dl-close.c (_dl_close): We can ignore the NODELETE flag if the
	object was not yet initialized.

2000-12-28  H.J. Lu  <hjl@gnu.org>

	* elf/dl-deps.c (_dl_map_object_deps): Make sure the DSO state
	is always consistent even if its dependency is failed.

	* elf/dl-open.c (_dl_open): Increment the open count before
	calling _dl_close () in case of failure.

	* elf/neededtest4.c: New file.
	* elf/neededobj5.c: New file.
	* elf/neededobj6.c: New file.

	* elf/Makefile (distribute): Add neededobj5.c and neededobj6.c.
	(tests): Add neededtest4.
	(modules-names): Add neededobj5 and neededobj6.
	($(objpfx)neededobj6.so): New target.
	($(objpfx)neededtest4): New target.
	($(objpfx)neededtest4.out): New target.
Diffstat (limited to 'elf/neededtest4.c')
-rw-r--r--elf/neededtest4.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/elf/neededtest4.c b/elf/neededtest4.c
new file mode 100644
index 0000000000..04ab10e4c9
--- /dev/null
+++ b/elf/neededtest4.c
@@ -0,0 +1,156 @@
+#include <dlfcn.h>
+#include <libintl.h>
+#include <link.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int
+check_loaded_objects (const char **loaded)
+{
+  struct link_map *lm;
+  int n;
+  int *found = NULL;
+  int errors = 0;
+
+  for (n = 0; loaded[n]; n++)
+    /* NOTHING */;
+
+  if (n)
+    {
+      found = (int *) alloca (sizeof (int) * n);
+      memset (found, 0, sizeof (int) * n);
+    }
+
+  printf("   Name\n");
+  printf(" --------------------------------------------------------\n");
+  for (lm = _r_debug.r_map; lm; lm = lm->l_next)
+    {
+      if (lm->l_name && lm->l_name[0])
+	printf(" %s, count = %d\n", lm->l_name, (int) lm->l_opencount);
+      if (lm->l_type == lt_loaded && lm->l_name)
+	{
+	  int match = 0;
+	  for (n = 0; loaded[n] != NULL; n++)
+	    {
+	      if (strcmp (basename (loaded[n]), basename (lm->l_name)) == 0)
+	        {
+		  found[n] = 1;
+		  match = 1;
+		  break;
+		}
+	    }
+
+	  if (match == 0)
+	    {
+	      ++errors;
+	      printf ("ERRORS: %s is not unloaded\n", lm->l_name);
+	    }
+	}
+    }
+
+  for (n = 0; loaded[n] != NULL; n++)
+    {
+      if (found[n] == 0)
+        {
+	  ++errors;
+	  printf ("ERRORS: %s is not loaded\n", loaded[n]);
+	}
+    }
+
+  return errors;
+}
+
+extern void c_function (void);
+extern char *dirname (__const char *__filename);
+
+int
+main (int argc, char **argv)
+{
+  void *obj;
+  const char *loaded[] = { NULL, NULL, NULL};
+  int errors = 0;
+  void (*f) (void);
+  const char *dir = dirname (argv [0]);
+  char *oldfilename;
+  char *newfilename;
+
+  c_function ();
+
+  printf ("\nThis is what is in memory now:\n");
+  errors += check_loaded_objects (loaded);
+
+  printf( "Loading shared object neededobj6.so\n");
+  obj = dlopen( "neededobj6.so", RTLD_LAZY);
+  if (obj == NULL)
+    {
+      printf ("%s\n", dlerror ());
+      exit (1);
+    }
+  f = dlsym (obj, "a2_function");
+  if (f == NULL)
+    {
+      printf ("%s\n", dlerror ());
+      exit (1);
+    }
+  f ();
+  loaded[0] = "neededobj5.so";
+  loaded[1] = "neededobj6.so";
+  errors += check_loaded_objects (loaded);
+
+  printf ("Closing neededobj6.so\n");
+  dlclose (obj);
+  loaded[0] = NULL;
+  errors += check_loaded_objects (loaded);
+
+  printf ("Rename neededobj5.so\n");
+  oldfilename = alloca (strlen (dir) + 1 + sizeof ("neededobj5.so"));
+  strcpy (oldfilename, dir);
+  strcat (oldfilename, "/");
+  strcat (oldfilename, "neededobj5.so");
+  newfilename = alloca (strlen (oldfilename) + sizeof (".renamed"));
+  strcpy (newfilename, oldfilename);
+  strcat (newfilename, ".renamed");
+  if (rename (oldfilename, newfilename))
+    {
+      perror ("rename");
+      exit (1);
+    }
+
+  printf( "Loading shared object neededobj6.so\n");
+  obj = dlopen( "neededobj6.so", RTLD_LAZY);
+  if (obj == NULL)
+    printf ("%s\n", dlerror ());
+  else
+    {
+      printf ("neededobj6.so should fail to load\n");
+      exit (1);
+    }
+
+  printf( "Loading shared object neededobj1.so\n");
+  obj = dlopen( "neededobj1.so", RTLD_LAZY);
+  if (obj == NULL)
+    {
+      printf ("%s\n", dlerror ());
+      exit (1);
+    }
+  errors += check_loaded_objects (loaded);
+  f = dlsym (obj, "c_function");
+  if (f == NULL)
+    {
+      printf ("%s\n", dlerror ());
+      exit (1);
+    }
+  f ();
+
+  printf ("Restore neededobj5.so\n");
+  if (rename (newfilename, oldfilename))
+    {
+      perror ("rename");
+      exit (1);
+    }
+
+  if (errors != 0)
+    printf ("%d errors found\n", errors);
+  return errors;
+}