bug-atexit2.c 726 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Derived from a test case in
  2. https://sourceware.org/bugzilla/show_bug.cgi?id=1158. */
  3. #include <dlfcn.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. static int next = 3;
  8. static void
  9. f1 (void)
  10. {
  11. puts ("f1");
  12. if (next-- != 1)
  13. _exit (1);
  14. }
  15. static void
  16. f2 (void)
  17. {
  18. puts ("f2");
  19. if (next-- != 2)
  20. _exit (1);
  21. }
  22. static void
  23. f3 (void)
  24. {
  25. puts ("f3");
  26. if (next-- != 3)
  27. _exit (1);
  28. }
  29. static int
  30. do_test (void)
  31. {
  32. atexit (f1);
  33. void *dso = dlopen ("$ORIGIN/bug-atexit2-lib.so", RTLD_NOW);
  34. void (*fn) (void) = (void (*) (void)) dlsym (dso, "foo");
  35. fn ();
  36. atexit (f2);
  37. dlclose (dso);
  38. atexit (f3);
  39. return 0;
  40. }
  41. #define TEST_FUNCTION do_test ()
  42. #include "../test-skeleton.c"