about summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-08-15 08:06:15 +0000
committerUlrich Drepper <drepper@redhat.com>2000-08-15 08:06:15 +0000
commitfc7f617d300f075fe28567391b10b4c5d64be46f (patch)
treeb0a8765937d52ccdb09a796e4e0c322dae9b804b /elf
parent07a3d63e524f13dd09e14adb0ac2623f6600401d (diff)
downloadglibc-fc7f617d300f075fe28567391b10b4c5d64be46f.tar.gz
glibc-fc7f617d300f075fe28567391b10b4c5d64be46f.tar.xz
glibc-fc7f617d300f075fe28567391b10b4c5d64be46f.zip
Update.
	* include/link.h: Include sysd-link.h.
	* sysdeps/generic/sysd-link.h: New file.
	* sysdeps/unix/sysv/linux/sysd-link.h: New file.
	* elf/Makefile (distribute): Add sysd-link.h.
	* elf/dl-load.c: Use definitions from sysd-link.h instead of stat
	types and functions directly.
	* elf/dl-misc.c: Likewise.
	* elf/dl-profile.c: Likewise.

	* elf/loadfail.c (main): Close all successfully loaded objects.
Diffstat (limited to 'elf')
-rw-r--r--elf/Makefile3
-rw-r--r--elf/dl-load.c12
-rw-r--r--elf/dl-misc.c8
-rw-r--r--elf/dl-profile.c4
-rw-r--r--elf/loadfail.c23
5 files changed, 31 insertions, 19 deletions
diff --git a/elf/Makefile b/elf/Makefile
index 3021596428..420db73aee 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -47,7 +47,8 @@ distribute	:= $(rtld-routines:=.c) dynamic-link.h do-rel.h dl-machine.h \
 		   vismain.c vismod1.c vismod2.c vismod3.c \
 		   constload2.c constload3.c filtmod1.c filtmod2.c \
 		   nodlopenmod.c nodelete.c nodelmod1.c nodelmod2.c \
-		   nodelmod3.c nodelmod4.c nodlopen.c
+		   nodelmod3.c nodelmod4.c nodlopen.c \
+		   sysd-link.h
 
 include ../Makeconfig
 
diff --git a/elf/dl-load.c b/elf/dl-load.c
index ebe4c80534..e0c9a61c2f 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -730,10 +730,10 @@ _dl_map_object_from_fd (const char *name, int fd, char *realname,
   int type;
   char *readbuf;
   ssize_t readlength;
-  struct stat st;
+  struct elf_stat st;
 
   /* Get file information.  */
-  if (__fxstat (_STAT_VER, fd, &st) < 0)
+  if (elf_fxstat (_STAT_VER, fd, &st) < 0)
     LOSE (errno, N_("cannot stat shared object"));
 
   /* Look again to see if the real name matched another already loaded.  */
@@ -1260,11 +1260,11 @@ open_path (const char *name, size_t namelen, int preloaded,
 		{
 		  /* We failed to open machine dependent library.  Let's
 		     test whether there is any directory at all.  */
-		  struct stat st;
+		  struct elf_stat st;
 
 		  buf[buflen - namelen - 1] = '\0';
 
-		  if (__xstat (_STAT_VER, buf, &st) != 0
+		  if (elf_xstat (_STAT_VER, buf, &st) != 0
 		      || ! S_ISDIR (st.st_mode))
 		    /* The directory does not exist or it is no directory.  */
 		    this_dir->status[cnt] = nonexisting;
@@ -1281,9 +1281,9 @@ open_path (const char *name, size_t namelen, int preloaded,
 	      /* This is an extra security effort to make sure nobody can
 		 preload broken shared objects which are in the trusted
 		 directories and so exploit the bugs.  */
-	      struct stat st;
+	      struct elf_stat st;
 
-	      if (__fxstat (_STAT_VER, fd, &st) != 0
+	      if (elf_fxstat (_STAT_VER, fd, &st) != 0
 		  || (st.st_mode & S_ISUID) == 0)
 		{
 		  /* The shared object cannot be tested for being SUID
diff --git a/elf/dl-misc.c b/elf/dl-misc.c
index 63f9266422..5261007822 100644
--- a/elf/dl-misc.c
+++ b/elf/dl-misc.c
@@ -1,5 +1,5 @@
 /* Miscellaneous support functions for dynamic linker
-   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -19,7 +19,7 @@
 
 #include <assert.h>
 #include <fcntl.h>
-#include <unistd.h>
+#include <link.h>
 #include <stdarg.h>
 #include <string.h>
 #include <unistd.h>
@@ -45,11 +45,11 @@ void *
 _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
 {
   void *result;
-  struct stat st;
+  struct elf_stat st;
   int fd = __open (file, O_RDONLY);
   if (fd < 0)
     return NULL;
-  if (__fxstat (_STAT_VER, fd, &st) < 0
+  if (elf_fxstat (_STAT_VER, fd, &st) < 0
       /* No need to map the file if it is empty.  */
       || st.st_size == 0)
     result = NULL;
diff --git a/elf/dl-profile.c b/elf/dl-profile.c
index 5d69b718e1..9f5ee14f32 100644
--- a/elf/dl-profile.c
+++ b/elf/dl-profile.c
@@ -175,7 +175,7 @@ _dl_start_profile (struct link_map *map, const char *output_dir)
 {
   char *filename;
   int fd;
-  struct stat st;
+  struct elf_stat st;
   const ElfW(Phdr) *ph;
   ElfW(Addr) mapstart = ~((ElfW(Addr)) 0);
   ElfW(Addr) mapend = 0;
@@ -267,7 +267,7 @@ _dl_start_profile (struct link_map *map, const char *output_dir)
       return;
     }
 
-  if (fstat (fd, &st) < 0 || !S_ISREG (st.st_mode))
+  if (elf_fxstat (_STAT_VER, fd, &st) < 0 || !S_ISREG (st.st_mode))
     {
       /* Not stat'able or not a regular file => don't use it.  */
       char buf[400];
diff --git a/elf/loadfail.c b/elf/loadfail.c
index 60deb7737b..e423356348 100644
--- a/elf/loadfail.c
+++ b/elf/loadfail.c
@@ -1,25 +1,36 @@
 #include <dlfcn.h>
 #include <error.h>
+#include <mcheck.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 int
 main (void)
 {
+  void *su[5];
   void *h;
+  int n;
 
-  if (dlopen ("testobj1.so", RTLD_GLOBAL | RTLD_NOW) == NULL
-      || dlopen ("testobj1.so", RTLD_GLOBAL | RTLD_NOW) == NULL
-      || dlopen ("testobj2.so", RTLD_GLOBAL | RTLD_NOW) == NULL
-      || dlopen ("testobj3.so", RTLD_GLOBAL | RTLD_NOW) == NULL
-      || dlopen ("testobj4.so", RTLD_GLOBAL | RTLD_NOW) == NULL
-      || dlopen ("testobj5.so", RTLD_GLOBAL | RTLD_NOW) == NULL)
+  mtrace ();
+
+  if ((su[0] = dlopen ("testobj1.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
+      || (su[1] = dlopen ("testobj2.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
+      || (su[2] = dlopen ("testobj3.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
+      || (su[3] = dlopen ("testobj4.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
+      || (su[4] = dlopen ("testobj5.so", RTLD_GLOBAL | RTLD_NOW)) == NULL)
     error (EXIT_FAILURE, 0, "failed to load shared object: %s", dlerror ());
 
   h = dlopen ("failobj.so", RTLD_GLOBAL | RTLD_NOW);
 
   printf ("h = %p, %s\n", h, h == NULL ? "ok" : "fail");
 
+  for (n = 0; n < 5; ++n)
+    if (dlclose (su[n]) != 0)
+      {
+	printf ("failed to unload su[%d]: %s\n", n, dlerror ());
+	exit (EXIT_FAILURE);
+      }
+
   return h != NULL;
 }