1 /*
2 
3  * Copyright (c) 2003, Intel Corporation. All rights reserved.
4  * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
5  * This file is licensed under the GPL license.  For the full content
6  * of this license, see the COPYING file at the top level of this
7  * source tree.
8 
9  The resulting set shall be the intersection of the current set and the
10  complement of the signal set pointed to by set, if the value of the
11  argument how is SIG_UNBLOCK
12 */
13 
14 #include <signal.h>
15 #include <stdio.h>
16 #include "posixtest.h"
17 
18 int handler_called = 0;
19 
handler(int signo)20 void handler(int signo)
21 {
22 	handler_called = 1;
23 }
24 
main(void)25 int main(void)
26 {
27 	struct sigaction act;
28 	sigset_t set1, set2, pending_set;
29 
30 	sigemptyset(&set1);
31 	sigaddset(&set1, SIGABRT);
32 	sigaddset(&set1, SIGUSR2);
33 
34 	sigemptyset(&set2);
35 	sigaddset(&set2, SIGUSR2);
36 
37 	act.sa_handler = handler;
38 	act.sa_flags = 0;
39 	sigemptyset(&act.sa_mask);
40 
41 	if (sigaction(SIGABRT, &act, 0) == -1) {
42 		perror("Unexpected error while attempting to setup test "
43 		       "pre-conditions");
44 		return PTS_UNRESOLVED;
45 	}
46 
47 	if (sigaction(SIGUSR2, &act, 0) == -1) {
48 		perror("Unexpected error while attempting to setup test "
49 		       "pre-conditions");
50 		return PTS_UNRESOLVED;
51 	}
52 
53 	if (sigprocmask(SIG_SETMASK, &set1, NULL) == -1) {
54 		perror
55 		    ("Unexpected error while attempting to use sigprocmask.\n");
56 		return PTS_UNRESOLVED;
57 	}
58 
59 	if (sigprocmask(SIG_UNBLOCK, &set2, NULL) == -1) {
60 		perror
61 		    ("Unexpected error while attempting to use sigprocmask.\n");
62 		return PTS_UNRESOLVED;
63 	}
64 
65 	if (raise(SIGUSR2) == -1) {
66 		perror("Unexpected error while attempting to setup test "
67 		       "pre-conditions");
68 		return PTS_UNRESOLVED;
69 	}
70 
71 	if (!handler_called) {
72 		printf
73 		    ("FAIL: Handler was not called for even though signal was removed from the signal mask\n");
74 		return PTS_UNRESOLVED;
75 	}
76 
77 	handler_called = 0;
78 	if (raise(SIGABRT) == -1) {
79 		perror("Unexpected error while attempting to setup test "
80 		       "pre-conditions");
81 		return PTS_UNRESOLVED;
82 	}
83 
84 	if (handler_called) {
85 		printf
86 		    ("FAIL: Hanlder was called for even though signal should have been in the signal mask\n");
87 		return PTS_FAIL;
88 	}
89 
90 	if (sigpending(&pending_set) == -1) {
91 		perror("Unexpected error while attempting to use sigpending\n");
92 		return PTS_UNRESOLVED;
93 	}
94 
95 	if (sigismember(&pending_set, SIGABRT) != 1) {
96 		perror("FAIL: sigismember did not return 1\n");
97 		return PTS_FAIL;
98 	}
99 
100 	if (sigismember(&pending_set, SIGUSR2) != 0) {
101 		perror("FAIL: sigismember did not return 1\n");
102 		return PTS_FAIL;
103 	}
104 
105 	printf("Test PASSED: signal was added to the process's signal mask\n");
106 	return 0;
107 }
108