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  The resulting set shall be the signal set pointed to by set, if the value
9  of the argument how is SIG_SETMASK
10 */
11 
12 #include <signal.h>
13 #include <stdio.h>
14 #include "posixtest.h"
15 
16 int handler_called = 0;
17 
handler(int signo)18 void handler(int signo)
19 {
20 	handler_called = 1;
21 }
22 
main(void)23 int main(void)
24 {
25 	struct sigaction act;
26 	sigset_t blocked_set, pending_set;
27 	sigemptyset(&blocked_set);
28 	sigaddset(&blocked_set, SIGABRT);
29 
30 	act.sa_handler = handler;
31 	act.sa_flags = 0;
32 	sigemptyset(&act.sa_mask);
33 	if (sigaction(SIGABRT, &act, 0) == -1) {
34 		perror("Unexpected error while attempting to setup test "
35 		       "pre-conditions");
36 		return PTS_UNRESOLVED;
37 	}
38 
39 	if (sigprocmask(SIG_SETMASK, &blocked_set, NULL) == -1) {
40 		perror
41 		    ("Unexpected error while attempting to use sigprocmask.\n");
42 		return PTS_UNRESOLVED;
43 	}
44 
45 	if (raise(SIGABRT) == -1) {
46 		perror("Unexpected error while attempting to setup test "
47 		       "pre-conditions");
48 		return PTS_UNRESOLVED;
49 	}
50 
51 	if (handler_called) {
52 		printf("FAIL: Signal was not blocked\n");
53 		return PTS_FAIL;
54 	}
55 
56 	if (sigpending(&pending_set) == -1) {
57 		perror("Unexpected error while attempting to use sigpending\n");
58 		return PTS_UNRESOLVED;
59 	}
60 
61 	if (sigismember(&pending_set, SIGABRT) == -1) {
62 		perror
63 		    ("Unexpected error while attempting to use sigismember.\n");
64 		return PTS_UNRESOLVED;
65 	}
66 
67 	if (sigismember(&pending_set, SIGABRT) != 1) {
68 		perror("FAIL: sigismember did not return 1\n");
69 		return PTS_UNRESOLVED;
70 	}
71 
72 	printf("Test PASSED: signal was added to the process's signal mask\n");
73 	return PTS_PASS;
74 }
75