1 /* Copyright (C) 2002, 2003, 2004 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 sigdelset (&ss
, SIGINT
);
40 if (pthread_sigmask (SIG_SETMASK
, &ss
, NULL
) != 0)
42 puts ("2nd pthread_sigmask failed");
46 pthread_barrier_wait (b
);
49 int res
= sigwait (&ss
, &sig
);
52 printf ("sigwait returned successfully with signal %d\n", sig
);
56 printf ("sigwait returned with %s (%d)\n", strerror (res
), res
);
67 /* Make sure the process doesn't run forever. */
72 if (pthread_sigmask (SIG_SETMASK
, &ss
, NULL
) != 0)
74 puts ("1st pthread_sigmask failed");
78 if (pthread_create (&th
, NULL
, tf
, NULL
) != 0)
80 puts ("pthread_create failed");
84 if (pthread_join (th
, NULL
) == 0)
86 puts ("thread joined?!");
97 char tmp
[] = "/tmp/tst-signal1-XXXXXX";
99 int fd
= mkstemp (tmp
);
102 puts ("mkstemp failed");
109 for (i
= 0; i
< 20; ++i
)
110 write (fd
, "foobar xyzzy", 12);
112 b
= mmap (NULL
, sizeof (pthread_barrier_t
), PROT_READ
| PROT_WRITE
,
116 puts ("mmap failed");
120 pthread_barrierattr_t ba
;
121 if (pthread_barrierattr_init (&ba
) != 0)
123 puts ("barrierattr_init failed");
127 if (pthread_barrierattr_setpshared (&ba
, PTHREAD_PROCESS_SHARED
) != 0)
129 puts ("barrierattr_setpshared failed");
133 if (pthread_barrier_init (b
, &ba
, 2) != 0)
135 puts ("barrier_init failed");
139 if (pthread_barrierattr_destroy (&ba
) != 0)
141 puts ("barrierattr_destroy failed");
148 puts ("fork failed");
155 pthread_barrier_wait (b
);
157 /* Wait a bit more. */
158 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 10000000 };
159 nanosleep (&ts
, NULL
);
161 /* Send the signal. */
162 puts ("sending the signal now");
165 /* Wait for the process to terminate. */
167 if (TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0)) != pid
)
169 puts ("wrong child reported terminated");
173 if (!WIFSIGNALED (status
))
175 puts ("child wasn't signalled");
179 if (WTERMSIG (status
) != SIGINT
)
181 puts ("child not terminated with SIGINT");
188 #define TEST_FUNCTION do_test ()
189 #include "../test-skeleton.c"