AArch64: Remove SVE erf and erfc tables
[glibc.git] / sysdeps / pthread / tst-signal1.c
blobca145eef3d8e4fdf5932bcaa41e9019367092536
1 /* Copyright (C) 2002-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
18 #include <errno.h>
19 #include <pthread.h>
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <sys/mman.h>
26 #include <sys/wait.h>
28 #include <support/xunistd.h>
29 #include <support/xsignal.h>
31 static sigset_t ss;
32 static pthread_barrier_t *b;
35 static void *
36 tf (void *arg)
38 sigdelset (&ss, SIGINT);
40 if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
42 puts ("2nd pthread_sigmask failed");
43 exit (1);
46 pthread_barrier_wait (b);
48 int sig;
49 int res = sigwait (&ss, &sig);
50 if (res == 0)
52 printf ("sigwait returned successfully with signal %d\n", sig);
53 exit (1);
56 printf ("sigwait returned with %s (%d)\n", strerror (res), res);
58 return NULL;
62 static void
63 receiver (void)
65 pthread_t th;
67 /* Make sure the process doesn't run forever. */
68 alarm (10);
70 sigfillset (&ss);
72 if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
74 puts ("1st pthread_sigmask failed");
75 exit (1);
78 if (pthread_create (&th, NULL, tf, NULL) != 0)
80 puts ("pthread_create failed");
81 exit (1);
84 if (pthread_join (th, NULL) == 0)
86 puts ("thread joined?!");
87 exit (1);
90 _exit (0);
94 static int
95 do_test (void)
97 xsignal (SIGINT, SIG_DFL);
99 char tmp[] = "/tmp/tst-signal1-XXXXXX";
101 int fd = mkstemp (tmp);
102 if (fd == -1)
104 puts ("mkstemp failed");
105 exit (1);
108 unlink (tmp);
110 int i;
111 for (i = 0; i < 20; ++i)
112 xwrite (fd, "foobar xyzzy", 12);
114 b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE,
115 MAP_SHARED, fd, 0);
116 if (b == MAP_FAILED)
118 puts ("mmap failed");
119 exit (1);
122 pthread_barrierattr_t ba;
123 if (pthread_barrierattr_init (&ba) != 0)
125 puts ("barrierattr_init failed");
126 exit (1);
129 if (pthread_barrierattr_setpshared (&ba, PTHREAD_PROCESS_SHARED) != 0)
131 puts ("barrierattr_setpshared failed");
132 exit (1);
135 if (pthread_barrier_init (b, &ba, 2) != 0)
137 puts ("barrier_init failed");
138 exit (1);
141 if (pthread_barrierattr_destroy (&ba) != 0)
143 puts ("barrierattr_destroy failed");
144 exit (1);
147 pid_t pid = fork ();
148 if (pid == -1)
150 puts ("fork failed");
151 exit (1);
154 if (pid == 0)
155 receiver ();
157 pthread_barrier_wait (b);
159 /* Wait a bit more. */
160 struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
161 nanosleep (&ts, NULL);
163 /* Send the signal. */
164 puts ("sending the signal now");
165 kill (pid, SIGINT);
167 /* Wait for the process to terminate. */
168 int status;
169 if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
171 puts ("wrong child reported terminated");
172 exit (1);
175 if (!WIFSIGNALED (status))
177 puts ("child wasn't signalled");
178 exit (1);
181 if (WTERMSIG (status) != SIGINT)
183 puts ("child not terminated with SIGINT");
184 exit (1);
187 return 0;
190 #define TEST_FUNCTION do_test ()
191 #include "../test-skeleton.c"