@@ -28,9 +28,17 @@
#include <string.h>
#include <errno.h>
-void *handle;
+static void *handle;
+static void (*foo) (void);
-void *
+static void
+segv_handler (int sig)
+{
+ /* All good. */
+ _exit (0);
+}
+
+static void *
load (void *u)
{
handle = dlopen ("$ORIGIN/tst-tls-atexit-lib.so", RTLD_LAZY);
@@ -40,7 +48,7 @@ load (void *u)
return (void *) (uintptr_t) 1;
}
- void (*foo) (void) = (void (*) (void)) dlsym (handle, "do_foo");
+ foo = (void (*) (void)) dlsym (handle, "do_foo");
if (foo == NULL)
{
@@ -82,29 +90,23 @@ do_test (void)
/* Now this should unload the DSO. */
dlclose (handle);
- /* Run through our maps and ensure that the DSO is unloaded. */
- FILE *f = fopen ("/proc/self/maps", "r");
-
- if (f == NULL)
+ /* Handle SIGSEGV. We don't use the EXPECTED_SIGNAL macro because we want to
+ detect any other SIGSEGVs as failures. */
+ struct sigaction sa, old_sa;
+ sa.sa_handler = segv_handler;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+ if (sigaction (SIGSEGV, &sa, &old_sa) < 0)
{
- perror ("Failed to open /proc/self/maps");
- fprintf (stderr, "Skipping verification of DSO unload\n");
- return 0;
+ printf ("Failed to set SIGSEGV handler: %m\n");
+ return 1;
}
- char *line = NULL;
- size_t s = 0;
- while (getline (&line, &s, f) > 0)
- {
- if (strstr (line, "tst-tls-atexit-lib.so"))
- {
- printf ("DSO not unloaded yet:\n%s", line);
- return 1;
- }
- }
- free (line);
+ /* This should crash... */
+ foo ();
- return 0;
+ /* ... or else we fail. */
+ return 1;
}
#define TEST_FUNCTION do_test ()