1 /* 2 * Copyright (c) 2003, Intel Corporation. All rights reserved. 3 * Created by: salwan.searty REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 8 This program tests the assertion that the process's signal mask will be 9 restored to the state that it was in prior to the delivery of the signal 10 11 Steps: 12 1. Empty the signal mask 13 2. Deliver the signal 14 3. When we return from the signal handler, verify that the signal mask 15 is still empty, otherwise fail. 16 17 */ 18 19 20 #include <signal.h> 21 #include <stdio.h> 22 #include <stdlib.h> 23 #include "posixtest.h" 24 25 #define NUMSIGNALS (sizeof(siglist) / sizeof(siglist[0])) 26 27 int is_empty(sigset_t * set) 28 { 29 30 int i; 31 int siglist[] = { SIGABRT, SIGALRM, SIGBUS, SIGCHLD, 32 SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, 33 SIGPIPE, SIGQUIT, SIGSEGV, 34 SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, 35 SIGUSR1, SIGUSR2, 36 #ifdef SIGPOLL 37 SIGPOLL, 38 #endif 39 #ifdef SIGPROF 40 SIGPROF, 41 #endif 42 SIGSYS, 43 SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ 44 }; 45 46 for (i = 0; i < NUMSIGNALS; i++) { 47 if (sigismember(set, siglist[i]) != 0) 48 return 0; 49 } 50 return 1; 51 } 52 53 void myhandler(int signo) 54 { 55 } 56 57 int main(void) 58 { 59 sigset_t mask; 60 sigemptyset(&mask); 61 62 if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) { 63 perror("sigprocmask(SIG_SETMASK, &mask, NULL) failed"); 64 return PTS_UNRESOLVED; 65 } 66 67 if (sigset(SIGCHLD, myhandler) == SIG_ERR) { 68 perror("Unexpected error while using sigset()"); 69 return PTS_UNRESOLVED; 70 } 71 72 raise(SIGCHLD); 73 sigprocmask(SIG_SETMASK, NULL, &mask); 74 75 if (is_empty(&mask) != 1) { 76 printf("Test FAILED: signal mask should be empty\n"); 77 return PTS_FAIL; 78 } 79 return PTS_PASS; 80 } 81