| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <config.h> |
| 20 |
|
| 21 |
#include <signal.h> |
| 22 |
|
| 23 |
#include <errno.h> |
| 24 |
#include <pthread.h> |
| 25 |
#include <stdio.h> |
| 26 |
#include <unistd.h> |
| 27 |
|
| 28 |
#include "macros.h" |
| 29 |
|
| 30 |
#if USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS |
| 31 |
|
| 32 |
static pthread_t main_thread; |
| 33 |
static pthread_t killer_thread; |
| 34 |
|
| 35 |
static void * |
| 36 |
killer_thread_func (void *arg) |
| 37 |
{ |
| 38 |
sleep (1); |
| 39 |
pthread_kill (main_thread, SIGINT); |
| 40 |
return NULL; |
| 41 |
} |
| 42 |
|
| 43 |
static volatile int sigint_occurred; |
| 44 |
|
| 45 |
static void |
| 46 |
sigint_handler (int sig) |
| 47 |
{ |
| 48 |
sigint_occurred++; |
| 49 |
} |
| 50 |
|
| 51 |
int |
| 52 |
main (int argc, char *argv[]) |
| 53 |
{ |
| 54 |
sigset_t set; |
| 55 |
|
| 56 |
signal (SIGINT, sigint_handler); |
| 57 |
|
| 58 |
sigemptyset (&set); |
| 59 |
sigaddset (&set, SIGINT); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
#if !defined __NetBSD__ |
| 64 |
ASSERT (pthread_sigmask (1729, &set, NULL) == EINVAL); |
| 65 |
#endif |
| 66 |
|
| 67 |
|
| 68 |
ASSERT (pthread_sigmask (SIG_BLOCK, &set, NULL) == 0); |
| 69 |
|
| 70 |
|
| 71 |
main_thread = pthread_self (); |
| 72 |
ASSERT (pthread_create (&killer_thread, NULL, killer_thread_func, NULL) == 0); |
| 73 |
|
| 74 |
|
| 75 |
sleep (2); |
| 76 |
|
| 77 |
|
| 78 |
ASSERT (sigint_occurred == 0); |
| 79 |
|
| 80 |
|
| 81 |
ASSERT (pthread_sigmask (SIG_UNBLOCK, &set, NULL) == 0); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
ASSERT (sigint_occurred == 1); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
ASSERT (pthread_join (killer_thread, NULL) == 0); |
| 92 |
|
| 93 |
return 0; |
| 94 |
} |
| 95 |
|
| 96 |
#else |
| 97 |
|
| 98 |
int |
| 99 |
main () |
| 100 |
{ |
| 101 |
fputs ("Skipping test: POSIX threads not enabled\n", stderr); |
| 102 |
return 77; |
| 103 |
} |
| 104 |
|
| 105 |
#endif |