1 /* Copyright (C) 2002-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
31 static pthread_barrier_t
*b
;
37 sigdelset (&ss
, SIGINT
);
39 if (pthread_sigmask (SIG_SETMASK
, &ss
, NULL
) != 0)
41 puts ("2nd pthread_sigmask failed");
45 pthread_barrier_wait (b
);
48 int res
= sigwait (&ss
, &sig
);
51 printf ("sigwait returned successfully with signal %d\n", sig
);
55 printf ("sigwait returned with %s (%d)\n", strerror (res
), res
);
66 /* Make sure the process doesn't run forever. */
71 if (pthread_sigmask (SIG_SETMASK
, &ss
, NULL
) != 0)
73 puts ("1st pthread_sigmask failed");
77 if (pthread_create (&th
, NULL
, tf
, NULL
) != 0)
79 puts ("pthread_create failed");
83 if (pthread_join (th
, NULL
) == 0)
85 puts ("thread joined?!");
96 char tmp
[] = "/tmp/tst-signal1-XXXXXX";
98 int fd
= mkstemp (tmp
);
101 puts ("mkstemp failed");
108 for (i
= 0; i
< 20; ++i
)
109 write (fd
, "foobar xyzzy", 12);
111 b
= mmap (NULL
, sizeof (pthread_barrier_t
), PROT_READ
| PROT_WRITE
,
115 puts ("mmap failed");
119 pthread_barrierattr_t ba
;
120 if (pthread_barrierattr_init (&ba
) != 0)
122 puts ("barrierattr_init failed");
126 if (pthread_barrierattr_setpshared (&ba
, PTHREAD_PROCESS_SHARED
) != 0)
128 puts ("barrierattr_setpshared failed");
132 if (pthread_barrier_init (b
, &ba
, 2) != 0)
134 puts ("barrier_init failed");
138 if (pthread_barrierattr_destroy (&ba
) != 0)
140 puts ("barrierattr_destroy failed");
147 puts ("fork failed");
154 pthread_barrier_wait (b
);
156 /* Wait a bit more. */
157 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 10000000 };
158 nanosleep (&ts
, NULL
);
160 /* Send the signal. */
161 puts ("sending the signal now");
164 /* Wait for the process to terminate. */
166 if (TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0)) != pid
)
168 puts ("wrong child reported terminated");
172 if (!WIFSIGNALED (status
))
174 puts ("child wasn't signalled");
178 if (WTERMSIG (status
) != SIGINT
)
180 puts ("child not terminated with SIGINT");
187 #define TEST_FUNCTION do_test ()
188 #include "../test-skeleton.c"