tst-mallocfork.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Derived from the test case in
  2. http://sourceware.org/bugzilla/show_bug.cgi?id=838. */
  3. #include <assert.h>
  4. #include <errno.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <sys/types.h>
  9. #include <sys/wait.h>
  10. #include "../test-skeleton.h"
  11. #ifdef __ARCH_USE_MMU__
  12. static void
  13. sig_handler (int signum)
  14. {
  15. pid_t child = fork ();
  16. if (child == 0)
  17. exit (0);
  18. TEMP_FAILURE_RETRY (waitpid (child, NULL, 0));
  19. }
  20. static int
  21. do_test (void)
  22. {
  23. pid_t parent = getpid ();
  24. struct sigaction action = { .sa_handler = sig_handler };
  25. sigemptyset (&action.sa_mask);
  26. malloc (sizeof (int));
  27. if (sigaction (SIGALRM, &action, NULL) != 0)
  28. {
  29. puts ("sigaction failed");
  30. return 1;
  31. }
  32. /* Create a child that sends the signal to be caught. */
  33. pid_t child = fork ();
  34. if (child == 0)
  35. {
  36. if (kill (parent, SIGALRM) == -1)
  37. perror ("kill");
  38. exit (0);
  39. }
  40. TEMP_FAILURE_RETRY (waitpid (child, NULL, 0));
  41. return 0;
  42. }
  43. #else
  44. static int
  45. do_test (void)
  46. {
  47. printf("Skipping test on non-mmu host!\n");
  48. return EXIT_SUCCESS;
  49. }
  50. #endif
  51. #define TEST_FUNCTION do_test ()
  52. #include "../test-skeleton.c"