• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 when there are signals blocked both
10  *  in the main function and in the signal handler.
11  *  1)  Block two signals from delivery to main process.
12  *  2)  Block three signals from delivery to a signal handler.
13  *  3)  Raise the signal to get into that signal handler.
14  *  From the signal handler:
15  *    4)  Raise one blocked signal in the signal handler.
16  *    5)  Raise one blocked signal in the main process.
17  *    5)  Verify that the two signals raised are shown via sigpending.
18  *    6)  Verify the three signals not raised are not shown.
19  */
20 
21 /*
22  * Copyright (c) 2002, Intel Corporation. All rights reserved.
23  * Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com
24  * This file is licensed under the GPL license.  For the full content
25  * of this license, see the COPYING file at the top level of this
26  * source tree.
27 
28  *  Signal handler uses exit() to leave so that the signals are not executed.
29  */
30 
31 #include <signal.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include "posixtest.h"
35 
handler(int signo)36 void handler(int signo)
37 {
38 	sigset_t pendingset;
39 
40 	if (sigemptyset(&pendingset) == -1) {
41 		printf("Could not call sigemptyset()\n");
42 		exit(-1);
43 	}
44 	if (raise(SIGUSR2) != 0) {
45 		printf("Could not raise SIGUSR2\n");
46 		exit(-1);
47 	}
48 	if (raise(SIGCONT) != 0) {
49 		printf("Could not raise SIGCONT\n");
50 		exit(-1);
51 	}
52 
53 	if (sigpending(&pendingset) == -1) {
54 		printf("Error calling sigpending()\n");
55 		exit(-1);
56 	}
57 
58 	if (sigismember(&pendingset, SIGUSR2) == 1 &&
59 	    sigismember(&pendingset, SIGCONT) == 1) {
60 		printf("All pending signals found\n");
61 		if ((sigismember(&pendingset, SIGHUP) == 0) &&
62 		    (sigismember(&pendingset, SIGABRT) == 0) &&
63 		    (sigismember(&pendingset, SIGUSR1) == 0)) {
64 			printf("Unsent signals not found\n");
65 			printf("Test PASSED\n");
66 			exit(0);
67 		} else {
68 			printf("Error with unsent signals\n");
69 			printf("Test FAILED\n");
70 			exit(-1);
71 		}
72 	} else {
73 		printf("Error with send signals\n");
74 		printf("Test FAILED\n");
75 		exit(-1);
76 	}
77 }
78 
main(void)79 int main(void)
80 {
81 	sigset_t blockset;
82 	sigset_t prevset;
83 	struct sigaction act;
84 
85 	act.sa_handler = handler;
86 	act.sa_flags = 0;
87 
88 	if ((sigemptyset(&blockset) == -1) ||
89 	    (sigemptyset(&prevset) == -1) ||
90 	    (sigemptyset(&act.sa_mask) == -1)) {
91 		printf("Could not call sigemptyset()\n");
92 		return PTS_UNRESOLVED;
93 	}
94 
95 	if ((sigaddset(&blockset, SIGUSR2) == -1) ||
96 	    (sigaddset(&blockset, SIGHUP) == -1)) {
97 		perror("Error calling sigaddset()\n");
98 		return PTS_UNRESOLVED;
99 	}
100 
101 	if (sigprocmask(SIG_SETMASK, &blockset, &prevset) == -1) {
102 		printf("Could not call sigprocmask()\n");
103 		return PTS_UNRESOLVED;
104 	}
105 
106 	if ((sigaddset(&act.sa_mask, SIGCONT) == -1) ||
107 	    (sigaddset(&act.sa_mask, SIGABRT) == -1) ||
108 	    (sigaddset(&act.sa_mask, SIGUSR1) == -1)) {
109 		perror("Error calling sigaddset()\n");
110 		return PTS_UNRESOLVED;
111 	}
112 
113 	if (sigaction(SIGTTOU, &act, 0) == -1) {
114 		perror("Could not call sigaction()");
115 		return PTS_UNRESOLVED;
116 	}
117 
118 	if (raise(SIGTTOU) == -1) {
119 		perror("Could not raise SIGTTOU");
120 		return PTS_UNRESOLVED;
121 	}
122 	printf("This code should not be reachable\n");
123 	return PTS_UNRESOLVED;
124 }
125