tst-mallocfork.c 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. static void
  11. sig_handler (int signum)
  12. {
  13. pid_t child = vfork ();
  14. if (child == 0)
  15. exit (0);
  16. TEMP_FAILURE_RETRY (waitpid (child, NULL, 0));
  17. }
  18. static int
  19. do_test (void)
  20. {
  21. pid_t parent = getpid ();
  22. struct sigaction action = { .sa_handler = sig_handler };
  23. sigemptyset (&action.sa_mask);
  24. malloc (sizeof (int));
  25. if (sigaction (SIGALRM, &action, NULL) != 0)
  26. {
  27. puts ("sigaction failed");
  28. return 1;
  29. }
  30. /* Create a child that sends the signal to be caught. */
  31. pid_t child = vfork ();
  32. if (child == 0)
  33. {
  34. if (kill (parent, SIGALRM) == -1)
  35. perror ("kill");
  36. exit (0);
  37. }
  38. TEMP_FAILURE_RETRY (waitpid (child, NULL, 0));
  39. return 0;
  40. }
  41. #define TEST_FUNCTION do_test ()
  42. #include "../test-skeleton.c"