1 /* Copyright (C) 2002, 2003 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
32 static pthread_barrier_t *b;
38 pthread_barrier_wait (b);
40 puts ("child: calling sigwait now");
44 err = sigwait (&ss, &sig);
47 printf ("sigwait returned unsuccessfully: %s (%d)\n",
52 puts ("sigwait returned");
56 printf ("caught signal %d, expected %d (SIGINT)\n", sig, SIGINT);
60 puts ("child thread terminating now");
71 /* Make sure the process doesn't run forever. */
76 if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
78 puts ("1st pthread_sigmask failed");
82 if (pthread_create (&th, NULL, tf, NULL) != 0)
84 puts ("pthread_create failed");
88 if (pthread_join (th, NULL) != 0)
90 puts ("thread didn't join");
94 puts ("join succeeded");
103 char tmp[] = "/tmp/tst-signal1-XXXXXX";
105 int fd = mkstemp (tmp);
108 puts ("mkstemp failed");
115 for (i = 0; i < 20; ++i)
116 write (fd, "foobar xyzzy", 12);
118 b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE,
122 puts ("mmap failed");
126 pthread_barrierattr_t ba;
127 if (pthread_barrierattr_init (&ba) != 0)
129 puts ("barrierattr_init failed");
133 if (pthread_barrierattr_setpshared (&ba, PTHREAD_PROCESS_SHARED) != 0)
135 puts ("barrierattr_setpshared failed");
139 if (pthread_barrier_init (b, &ba, 2) != 0)
141 puts ("barrier_init failed");
145 if (pthread_barrierattr_destroy (&ba) != 0)
147 puts ("barrierattr_destroy failed");
154 puts ("fork failed");
161 pthread_barrier_wait (b);
163 /* Wait a bit more. */
164 struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
165 nanosleep (&ts, NULL);
167 /* Send the signal. */
168 puts ("sending the signal now");
171 /* Wait for the process to terminate. */
173 if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
175 puts ("wrong child reported terminated");
179 if (!WIFEXITED (status))
181 if (WIFSIGNALED (status))
182 printf ("child exited with signal %d\n", WTERMSIG (status));
184 puts ("child didn't exit normally");
188 if (WEXITSTATUS (status) != 0)
190 printf ("exit status %d != 0\n", WEXITSTATUS (status));
197 #define TEST_FUNCTION do_test ()
198 #include "../test-skeleton.c"