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. #include "../test-skeleton.h"
  23. static void
  24. final_test (void)
  25. {
  26. puts ("final_test has been called");
  27. #define THE_SIGNAL SIGUSR1
  28. kill (getpid (), SIGUSR1);
  29. }
  30. static void *
  31. tf (void *a)
  32. {
  33. pid_t pid = fork ();
  34. if (pid == -1)
  35. {
  36. puts ("fork failed");
  37. exit (1);
  38. }
  39. if (pid == 0)
  40. {
  41. atexit (final_test);
  42. pthread_exit (NULL);
  43. }
  44. int r;
  45. int e = TEMP_FAILURE_RETRY (waitpid (pid, &r, 0));
  46. if (e != pid)
  47. {
  48. puts ("waitpid failed");
  49. exit (1);
  50. }
  51. if (! WIFSIGNALED (r))
  52. {
  53. puts ("child not signled");
  54. exit (1);
  55. }
  56. if (WTERMSIG (r) != THE_SIGNAL)
  57. {
  58. puts ("child's termination signal wrong");
  59. exit (1);
  60. }
  61. return NULL;
  62. }
  63. int
  64. do_test (void)
  65. {
  66. pthread_t th;
  67. if (pthread_create (&th, NULL, tf, NULL) != 0)
  68. {
  69. puts ("create failed");
  70. _exit (1);
  71. }
  72. if (pthread_join (th, NULL) != 0)
  73. {
  74. puts ("join failed");
  75. exit (1);
  76. }
  77. return 0;
  78. }
  79. #define TEST_FUNCTION do_test ()
  80. #include "../test-skeleton.c"