tst-mallocfork.c 1019 B

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