robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 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 |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 5 | * of this license, see the COPYING file at the top level of this |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 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 |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 14 | 3. When we return from the signal handler, verify that the signal mask |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 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 | |
Garrett Cooper | a1a9207 | 2011-01-16 18:07:18 -0800 | [diff] [blame] | 26 | #define NUMSIGNALS (sizeof(siglist) / sizeof(siglist[0])) |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 27 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 28 | int is_empty(sigset_t * set) |
| 29 | { |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 30 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 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, |
Garrett Cooper | 6269146 | 2010-07-19 01:29:18 -0700 | [diff] [blame] | 37 | #ifdef SIGPOLL |
| 38 | SIGPOLL, |
| 39 | #endif |
Garrett Cooper | d3df7e0 | 2011-01-16 17:55:25 -0800 | [diff] [blame] | 40 | #ifdef SIGPROF |
| 41 | SIGPROF, |
| 42 | #endif |
| 43 | SIGSYS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 44 | SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ |
| 45 | }; |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 46 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 47 | for (i = 0; i < NUMSIGNALS; i++) { |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 48 | if (sigismember(set, siglist[i]) != 0) |
| 49 | return 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 50 | } |
| 51 | return 1; |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void myhandler(int signo) |
| 55 | { |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | int main() |
| 59 | { |
| 60 | sigset_t mask; |
| 61 | sigemptyset(&mask); |
| 62 | |
Garrett Cooper | 6269146 | 2010-07-19 01:29:18 -0700 | [diff] [blame] | 63 | if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) { |
| 64 | perror("sigprocmask(SIG_SETMASK, &mask, NULL) failed"); |
| 65 | return PTS_UNRESOLVED; |
| 66 | } |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 67 | |
| 68 | if (sigset(SIGCHLD, myhandler) == SIG_ERR) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame^] | 69 | perror("Unexpected error while using sigset()"); |
| 70 | return PTS_UNRESOLVED; |
| 71 | } |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 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; |
Garrett Cooper | d3df7e0 | 2011-01-16 17:55:25 -0800 | [diff] [blame] | 81 | } |