1 /* $OpenBSD: signal.c,v 1.2 2001/11/03 04:33:48 marc Exp $ */ 2 /* David Leonard <d@openbsd.org>, 2001. Public Domain. */ 3 4 /* 5 * This program tests signal handler re-entrancy. 6 */ 7 8 #include <pthread.h> 9 #include <stdio.h> 10 #include <stdlib.h> 11 #include <unistd.h> 12 #include <signal.h> 13 #include "test.h" 14 15 volatile int alarmed; 16 17 void * 18 sleeper(arg) 19 void *arg; 20 { 21 sigset_t mask; 22 23 /* Ignore all signals in this thread */ 24 sigfillset(&mask); 25 CHECKe(sigprocmask(SIG_SETMASK, &mask, NULL)); 26 ASSERT(sleep(3) == 0); 27 SUCCEED; 28 } 29 30 void 31 handler(sig) 32 int sig; 33 { 34 alarmed = 1; 35 alarm(1); 36 signal(SIGALRM, handler); 37 } 38 39 int 40 main() 41 { 42 pthread_t slpr; 43 44 ASSERT(signal(SIGALRM, handler) != SIG_ERR); 45 CHECKe(alarm(1)); 46 CHECKr(pthread_create(&slpr, NULL, sleeper, NULL)); 47 /* ASSERT(sleep(1) == 0); */ 48 for (;;) { 49 if (alarmed) { 50 alarmed = 0; 51 CHECKe(write(STDOUT_FILENO, "!", 1)); 52 } 53 } 54 } 55