1 /* Copyright (C) 2002-2015 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 <http://www.gnu.org/licenses/>. */
31 static pthread_barrier_t
*b
;
37 pthread_barrier_wait (b
);
39 puts ("child: calling sigwait now");
43 err
= sigwait (&ss
, &sig
);
46 printf ("sigwait returned unsuccessfully: %s (%d)\n",
51 puts ("sigwait returned");
55 printf ("caught signal %d, expected %d (SIGINT)\n", sig
, SIGINT
);
59 puts ("child thread terminating now");
70 /* Make sure the process doesn't run forever. */
75 if (pthread_sigmask (SIG_SETMASK
, &ss
, NULL
) != 0)
77 puts ("1st pthread_sigmask failed");
81 if (pthread_create (&th
, NULL
, tf
, NULL
) != 0)
83 puts ("pthread_create failed");
87 if (pthread_join (th
, NULL
) != 0)
89 puts ("thread didn't join");
93 puts ("join succeeded");
102 char tmp
[] = "/tmp/tst-signal1-XXXXXX";
104 int fd
= mkstemp (tmp
);
107 puts ("mkstemp failed");
114 for (i
= 0; i
< 20; ++i
)
115 write (fd
, "foobar xyzzy", 12);
117 b
= mmap (NULL
, sizeof (pthread_barrier_t
), PROT_READ
| PROT_WRITE
,
121 puts ("mmap failed");
125 pthread_barrierattr_t ba
;
126 if (pthread_barrierattr_init (&ba
) != 0)
128 puts ("barrierattr_init failed");
132 if (pthread_barrierattr_setpshared (&ba
, PTHREAD_PROCESS_SHARED
) != 0)
134 puts ("barrierattr_setpshared failed");
138 if (pthread_barrier_init (b
, &ba
, 2) != 0)
140 puts ("barrier_init failed");
144 if (pthread_barrierattr_destroy (&ba
) != 0)
146 puts ("barrierattr_destroy failed");
153 puts ("fork failed");
160 pthread_barrier_wait (b
);
162 /* Wait a bit more. */
163 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 10000000 };
164 nanosleep (&ts
, NULL
);
166 /* Send the signal. */
167 puts ("sending the signal now");
170 /* Wait for the process to terminate. */
172 if (TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0)) != pid
)
174 puts ("wrong child reported terminated");
178 if (!WIFEXITED (status
))
180 if (WIFSIGNALED (status
))
181 printf ("child exited with signal %d\n", WTERMSIG (status
));
183 puts ("child didn't exit normally");
187 if (WEXITSTATUS (status
) != 0)
189 printf ("exit status %d != 0\n", WEXITSTATUS (status
));
196 #define TEST_FUNCTION do_test ()
197 #include "../test-skeleton.c"