1 /*
2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
3  * Created by:  julie.n.fleischer 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  *  Test that the sigpending() function stores the set of signals that
9  *  are blocked from delivery.  Steps are:
10  *  1)  Block three signals from delivery.
11  *  2)  Raise two of those signals.
12  *  3)  Verify that the two signals raised are shown via sigpending.
13  *  4)  Verify the one signal not raised is not shown.
14  */
15 
16 #include <signal.h>
17 #include <stdio.h>
18 #include "posixtest.h"
19 
main(void)20 int main(void)
21 {
22 	sigset_t blockset;
23 	sigset_t prevset;
24 	sigset_t pendingset;
25 
26 	if ((sigemptyset(&blockset) == -1) ||
27 	    (sigemptyset(&prevset) == -1) || (sigemptyset(&pendingset) == -1)) {
28 		printf("Could not call sigemptyset()\n");
29 		return PTS_UNRESOLVED;
30 	}
31 
32 	if ((sigaddset(&blockset, SIGUSR2) == -1) ||
33 	    (sigaddset(&blockset, SIGHUP) == -1) ||
34 	    (sigaddset(&blockset, SIGQUIT) == -1)) {
35 		perror("Error calling sigaddset()\n");
36 		return PTS_UNRESOLVED;
37 	}
38 
39 	if (sigprocmask(SIG_SETMASK, &blockset, &prevset) == -1) {
40 		printf("Could not call sigprocmask()\n");
41 		return PTS_UNRESOLVED;
42 	}
43 
44 	if (raise(SIGUSR2) != 0) {
45 		printf("Could not raise SIGUSR2\n");
46 		return PTS_UNRESOLVED;
47 	}
48 	if (raise(SIGQUIT) != 0) {
49 		printf("Could not raise SIGQUIT\n");
50 		return PTS_UNRESOLVED;
51 	}
52 
53 	if (sigpending(&pendingset) == -1) {
54 		printf("Error calling sigpending()\n");
55 		return PTS_UNRESOLVED;
56 	}
57 
58 	if (sigismember(&pendingset, SIGUSR2) == 1) {
59 		if (sigismember(&pendingset, SIGQUIT) == 1) {
60 			printf("All pending signals found\n");
61 			if (sigismember(&pendingset, SIGHUP) == 0) {
62 				printf("Unsent signals not found.\n");
63 				printf("Test PASSED\n");
64 				return PTS_PASS;
65 			} else {
66 				printf("Error with unsent signals\n");
67 				printf("Test FAILED\n");
68 				return PTS_FAIL;
69 			}
70 		}
71 	}
72 	printf("Not all pending signals found\n");
73 	return PTS_FAIL;
74 }
75