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 #define _XOPEN_SOURCE 600 20 21 #include <signal.h> 22 #include <stdio.h> 23 #include <stdlib.h> 24 #include "posixtest.h" 25 26 #define NUMSIGNALS (sizeof(siglist) / sizeof(siglist[0])) 27 28 int is_empty(sigset_t * set) 29 { 30 31 int i; 32 int siglist[] = { SIGABRT, SIGALRM, SIGBUS, SIGCHLD, 33 SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, 34 SIGPIPE, SIGQUIT, SIGSEGV, 35 SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, 36 SIGUSR1, SIGUSR2, 37 #ifdef SIGPOLL 38 SIGPOLL, 39 #endif 40 #ifdef SIGPROF 41 SIGPROF, 42 #endif 43 SIGSYS, 44 SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ 45 }; 46 47 for (i = 0; i < NUMSIGNALS; i++) { 48 if (sigismember(set, siglist[i]) != 0) 49 return 0; 50 } 51 return 1; 52 } 53 54 void myhandler(int signo) 55 { 56 } 57 58 int main(void) 59 { 60 sigset_t mask; 61 sigemptyset(&mask); 62 63 if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) { 64 perror("sigprocmask(SIG_SETMASK, &mask, NULL) failed"); 65 return PTS_UNRESOLVED; 66 } 67 68 if (sigset(SIGCHLD, myhandler) == SIG_ERR) { 69 perror("Unexpected error while using sigset()"); 70 return PTS_UNRESOLVED; 71 } 72 73 raise(SIGCHLD); 74 sigprocmask(SIG_SETMASK, NULL, &mask); 75 76 if (is_empty(&mask) != 1) { 77 printf("Test FAILED: signal mask should be empty\n"); 78 return PTS_FAIL; 79 } 80 return PTS_PASS; 81 } 82