1 /* Copyright (C) 2002-2023 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/>. */
30 static pthread_barrier_t
*b
;
36 pthread_barrier_wait (b
);
38 puts ("child: calling sigwait now");
42 err
= sigwait (&ss
, &sig
);
45 printf ("sigwait returned unsuccessfully: %s (%d)\n",
50 puts ("sigwait returned");
54 printf ("caught signal %d, expected %d (SIGINT)\n", sig
, SIGINT
);
58 puts ("child thread terminating now");
69 /* Make sure the process doesn't run forever. */
74 if (pthread_sigmask (SIG_SETMASK
, &ss
, NULL
) != 0)
76 puts ("1st pthread_sigmask failed");
80 if (pthread_create (&th
, NULL
, tf
, NULL
) != 0)
82 puts ("pthread_create failed");
86 if (pthread_join (th
, NULL
) != 0)
88 puts ("thread didn't join");
92 puts ("join succeeded");
101 char tmp
[] = "/tmp/tst-signal1-XXXXXX";
103 int fd
= mkstemp (tmp
);
106 puts ("mkstemp failed");
113 for (i
= 0; i
< 20; ++i
)
114 write (fd
, "foobar xyzzy", 12);
116 b
= mmap (NULL
, sizeof (pthread_barrier_t
), PROT_READ
| PROT_WRITE
,
120 puts ("mmap failed");
124 pthread_barrierattr_t ba
;
125 if (pthread_barrierattr_init (&ba
) != 0)
127 puts ("barrierattr_init failed");
131 if (pthread_barrierattr_setpshared (&ba
, PTHREAD_PROCESS_SHARED
) != 0)
133 puts ("barrierattr_setpshared failed");
137 if (pthread_barrier_init (b
, &ba
, 2) != 0)
139 puts ("barrier_init failed");
143 if (pthread_barrierattr_destroy (&ba
) != 0)
145 puts ("barrierattr_destroy failed");
152 puts ("fork failed");
159 pthread_barrier_wait (b
);
161 /* Wait a bit more. */
162 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 10000000 };
163 nanosleep (&ts
, NULL
);
165 /* Send the signal. */
166 puts ("sending the signal now");
169 /* Wait for the process to terminate. */
171 if (TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0)) != pid
)
173 puts ("wrong child reported terminated");
177 if (!WIFEXITED (status
))
179 if (WIFSIGNALED (status
))
180 printf ("child exited with signal %d\n", WTERMSIG (status
));
182 puts ("child didn't exit normally");
186 if (WEXITSTATUS (status
) != 0)
188 printf ("exit status %d != 0\n", WEXITSTATUS (status
));
195 #define TEST_FUNCTION do_test ()
196 #include "../test-skeleton.c"