1 /* Copyright (C) 2003-2022 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
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 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <https://www.gnu.org/licenses/>.  */
17 
18 #include <errno.h>
19 #include <pthread.h>
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <sys/wait.h>
25 
26 
27 static void
final_test(void)28 final_test (void)
29 {
30   puts ("final_test has been called");
31 
32 #define THE_SIGNAL SIGUSR1
33   kill (getpid (), SIGUSR1);
34 }
35 
36 
37 static void *
tf(void * a)38 tf (void *a)
39 {
40   pid_t pid = fork ();
41   if (pid == -1)
42     {
43       puts ("fork failed");
44       exit (1);
45     }
46 
47   if (pid == 0)
48     {
49       atexit (final_test);
50 
51       pthread_exit (NULL);
52     }
53 
54   int r;
55   int e = TEMP_FAILURE_RETRY (waitpid (pid, &r, 0));
56   if (e != pid)
57     {
58       puts ("waitpid failed");
59       exit (1);
60     }
61 
62   if (! WIFSIGNALED (r))
63     {
64       puts ("child not signled");
65       exit (1);
66     }
67 
68   if (WTERMSIG (r) != THE_SIGNAL)
69     {
70       puts ("child's termination signal wrong");
71       exit (1);
72     }
73 
74   return NULL;
75 }
76 
77 
78 int
do_test(void)79 do_test (void)
80 {
81   pthread_t th;
82 
83   if (pthread_create (&th, NULL, tf, NULL) != 0)
84     {
85       puts ("create failed");
86       _exit (1);
87     }
88 
89   if (pthread_join (th, NULL) != 0)
90     {
91       puts ("join failed");
92       exit (1);
93     }
94 
95   return 0;
96 }
97 
98 #define TEST_FUNCTION do_test ()
99 #include "../test-skeleton.c"
100