1 /* $OpenBSD: sigmask.c,v 1.2 2003/07/14 22:01:42 marc Exp $ */ 2 /* PUBLIC DOMAIN July 2003 Marco S Hyman <marc@snafu.org> */ 3 4 #include <sys/time.h> 5 6 #include <pthread.h> 7 #include <signal.h> 8 #include <unistd.h> 9 10 #include "test.h" 11 12 /* 13 * Test that masked signals with a default action of terminate process 14 * do NOT terminate the process. 15 */ 16 int main (int argc, char *argv[]) 17 { 18 sigset_t mask; 19 int sig; 20 21 /* any two (or more) command line args should cause the program 22 to die */ 23 if (argc > 2) { 24 printf("trigger sigalrm[1] [test should die]\n"); 25 ualarm(100000, 0); 26 CHECKe(sleep(1)); 27 } 28 29 /* mask sigalrm */ 30 CHECKe(sigemptyset(&mask)); 31 CHECKe(sigaddset(&mask, SIGALRM)); 32 CHECKe(pthread_sigmask(SIG_BLOCK, &mask, NULL)); 33 34 /* now trigger sigalrm and wait for it */ 35 printf("trigger sigalrm[2] [masked, test should not die]\n"); 36 ualarm(100000, 0); 37 CHECKe(sleep(1)); 38 39 /* sigwait for sigalrm, it should be pending. If it is not 40 the test will hang. */ 41 CHECKe(sigwait(&mask, &sig)); 42 ASSERT(sig == SIGALRM); 43 44 /* make sure sigwait didn't muck with the mask by triggering 45 sigalrm, again */ 46 printf("trigger sigalrm[3] after sigwait [masked, test should not die]\n"); 47 ualarm(100000, 0); 48 CHECKe(sleep(1)); 49 50 /* any single command line arg will run this code wich unmasks the 51 signal and then makes sure the program terminates when sigalrm 52 is triggered. */ 53 if (argc > 1) { 54 printf("trigger sigalrm[4] [unmasked, test should die]\n"); 55 CHECKe(pthread_sigmask(SIG_UNBLOCK, &mask, NULL)); 56 ualarm(100000, 0); 57 CHECKe(sleep(1)); 58 } 59 60 SUCCEED; 61 } 62