From d743ba1e9bf45b532c18ea437476984c0e2f0c44 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 10 Jun 2000 04:31:24 +0000 Subject: Update. 2000-06-09 H.J. Lu * dlfcn/dlerror.c (_dlerror_run): Set result->errstring to NULL after freeing it. * dlfcn/Makefile (distribute): Add failtestmod.c. (tests): Add failtest. Add rules to build and run failtest. * dlfcn/failtest.c: New file. * dlfcn/failtestmod.c: New file. --- dlfcn/Makefile | 9 ++++++--- dlfcn/dlerror.c | 9 ++++++--- dlfcn/failtest.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ dlfcn/failtestmod.c | 25 +++++++++++++++++++++++ 4 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 dlfcn/failtest.c create mode 100644 dlfcn/failtestmod.c (limited to 'dlfcn') diff --git a/dlfcn/Makefile b/dlfcn/Makefile index d14d382702..ed725639ef 100644 --- a/dlfcn/Makefile +++ b/dlfcn/Makefile @@ -20,7 +20,7 @@ subdir := dlfcn headers := bits/dlfcn.h dlfcn.h extra-libs := libdl libdl-routines := dlopen dlclose dlsym dlvsym dlerror dladdr -distribute := dlopenold.c glreflib1.c glreflib2.c +distribute := dlopenold.c glreflib1.c glreflib2.c failtestmod.c extra-libs-others := libdl @@ -32,9 +32,9 @@ libdl-shared-only-routines := dlopenold endif ifeq (yes,$(build-shared)) -tests = glrefmain +tests = glrefmain failtest endif -modules-names = glreflib1 glreflib2 +modules-names = glreflib1 glreflib2 failtestmod extra-objs += $(modules-names:=.os) include ../Rules @@ -46,3 +46,6 @@ $(test-modules): $(objpfx)%.so: $(objpfx)%.os $(objpfx)glrefmain: $(objpfx)libdl.so $(objpfx)glrefmain.out: $(objpfx)glrefmain \ $(objpfx)glreflib1.so $(objpfx)glreflib2.so + +$(objpfx)failtest: $(libdl) +$(objpfx)failtest.out: $(objpfx)failtestmod.so diff --git a/dlfcn/dlerror.c b/dlfcn/dlerror.c index 972a9ac263..34ea82907e 100644 --- a/dlfcn/dlerror.c +++ b/dlfcn/dlerror.c @@ -120,9 +120,12 @@ _dlerror_run (void (*operate) (void *), void *args) } if (result->errstring != NULL) - /* Free the error string from the last failed command. This can - happen if `dlerror' was not run after an error was found. */ - free ((char *) result->errstring); + { + /* Free the error string from the last failed command. This can + happen if `dlerror' was not run after an error was found. */ + free ((char *) result->errstring); + result->errstring = NULL; + } result->errcode = _dl_catch_error (&result->objname, &result->errstring, operate, args); diff --git a/dlfcn/failtest.c b/dlfcn/failtest.c new file mode 100644 index 0000000000..50bbf10596 --- /dev/null +++ b/dlfcn/failtest.c @@ -0,0 +1,58 @@ +#include +#include + + +/* Number of rounds we perform the test. */ +#define TEST_ROUNDS 10 + + +static const char unknown[] = "a-file-with-this-name-does-not-exist"; +static const char exists[] = "failtestmod.so"; + + +int +main (void) +{ + int i; + + setvbuf (stdout, NULL, _IONBF, 0); + + for (i = 0; i < TEST_ROUNDS; ++i) + { + void *dsc; + + printf ("Round %d: Try loading \"%s\"\n", i, unknown); + + dsc = dlopen (unknown, RTLD_NOW); + if (dsc != NULL) + { + printf ("We found a file of name \"%s\": this should not happen\n", + unknown); + return 1; + } + + printf ("Round %d: loading \"%s\" failed\n", i, unknown); + + /* Don't use `dlerror', just load an existing file. */ + dsc = dlopen (exists, RTLD_NOW); + if (dsc == NULL) + { + printf ("Could not load \"%s\": %s\n", exists, dlerror ()); + return 1; + } + + printf ("Round %d: Loaded \"%s\"\n", i, exists); + + dlclose (dsc); + + printf ("Round %d: Unloaded \"%s\"\n", i, exists); + } + + return 0; +} + + +void +foo (void) +{ +} diff --git a/dlfcn/failtestmod.c b/dlfcn/failtestmod.c new file mode 100644 index 0000000000..595da4d567 --- /dev/null +++ b/dlfcn/failtestmod.c @@ -0,0 +1,25 @@ +#include +#include + + +void +__attribute__ ((__constructor__)) +constr (void) +{ + void *handle; + void *m; + + /* Open the library. */ + handle = dlopen (NULL, RTLD_NOW); + if (handle == NULL) + { + puts ("Cannot get handle to own object"); + return; + } + + /* Get a symbol. */ + m = dlsym (handle, "main"); + puts ("called dlsym() to get main"); + + dlclose (handle); +} -- cgit 1.4.1