tst-basic4.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <pthread.h>
  17. #include <signal.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <sys/wait.h>
  22. static void
  23. final_test (void)
  24. {
  25. puts ("final_test has been called");
  26. #define THE_SIGNAL SIGUSR1
  27. kill (getpid (), SIGUSR1);
  28. }
  29. static void *
  30. tf (void *a)
  31. {
  32. pid_t pid = fork ();
  33. if (pid == -1)
  34. {
  35. puts ("fork failed");
  36. exit (1);
  37. }
  38. if (pid == 0)
  39. {
  40. atexit (final_test);
  41. pthread_exit (NULL);
  42. }
  43. int r;
  44. int e = TEMP_FAILURE_RETRY (waitpid (pid, &r, 0));
  45. if (e != pid)
  46. {
  47. puts ("waitpid failed");
  48. exit (1);
  49. }
  50. if (! WIFSIGNALED (r))
  51. {
  52. puts ("child not signled");
  53. exit (1);
  54. }
  55. if (WTERMSIG (r) != THE_SIGNAL)
  56. {
  57. puts ("child's termination signal wrong");
  58. exit (1);
  59. }
  60. return NULL;
  61. }
  62. int
  63. do_test (void)
  64. {
  65. pthread_t th;
  66. if (pthread_create (&th, NULL, tf, NULL) != 0)
  67. {
  68. puts ("create failed");
  69. _exit (1);
  70. }
  71. if (pthread_join (th, NULL) != 0)
  72. {
  73. puts ("join failed");
  74. exit (1);
  75. }
  76. return 0;
  77. }
  78. #define TEST_FUNCTION do_test ()
  79. #include "../test-skeleton.c"