1 /*
2 Test case for assertion #1 of the sigaction system call that shows
3 sigaction (when used with a non-null act pointer) changes the action
4 for a signal.
5
6 Steps:
7 1. Use sigaction to setup a signal handler for SIGABRT
8 2. Add SIGABRT to the signal mask.
9 3. Raise SIGABRT. Now, SIGABRT is pending.
10 4. Call sigprocmask() again. Verify that global variable
11 sigprocmask_return_val is not set to anything other than
12 it's initial value (which is 1), while we're still inside
13 the signal handler code.
14 5. Once sigprocmask() returns, verify that it returns a zero, and
15 verify that the global handler_called variable has been set to 1;
16 6. If we manage to verify both steps 4 and 5, then we've
17 proved that signal was delivered before sigprocmask() returned.
18
19 */
20
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include "posixtest.h"
25
26 static volatile int handler_called;
27 static int sigprocmask_return_val = 1; /* some value that's not a 1 or 0 */
28
handler(int signo PTS_ATTRIBUTE_UNUSED)29 static void handler(int signo PTS_ATTRIBUTE_UNUSED)
30 {
31 handler_called = 1;
32 if (sigprocmask_return_val != 1) {
33 printf
34 ("FAIL: sigprocmask() returned before signal was delivered.\n");
35 exit(PTS_FAIL);
36 }
37 }
38
main(void)39 int main(void)
40 {
41 struct sigaction act;
42 sigset_t blocked_set1;
43 sigemptyset(&blocked_set1);
44 sigaddset(&blocked_set1, SIGABRT);
45
46 act.sa_handler = handler;
47 act.sa_flags = 0;
48 sigemptyset(&act.sa_mask);
49
50 if (sigaction(SIGABRT, &act, 0) == -1) {
51 perror("Unexpected error while attempting to setup test "
52 "pre-conditions");
53 return PTS_UNRESOLVED;
54 }
55
56 if (sigprocmask(SIG_SETMASK, &blocked_set1, NULL) == -1) {
57 perror
58 ("Unexpected error while attempting to use sigprocmask.\n");
59 return PTS_UNRESOLVED;
60 }
61
62 if ((raise(SIGABRT) == -1)) {
63 perror("Unexpected error while attempting to setup test "
64 "pre-conditions");
65 return PTS_UNRESOLVED;
66 }
67
68 sigprocmask_return_val = sigprocmask(SIG_UNBLOCK, &blocked_set1, NULL);
69
70 if (sigprocmask_return_val != 0) {
71 perror
72 ("Unexpected error while attempting to use sigprocmask.\n");
73 return PTS_UNRESOLVED;
74 }
75
76 if (handler_called != 1) {
77 perror
78 ("Handler wasn't called, implying signal was not delivered.\n");
79 return PTS_UNRESOLVED;
80 }
81
82 printf
83 ("Test PASSED: signal was delivered before the call to sigprocmask returned.\n");
84 return PTS_PASS;
85 }
86