1 #include <signal.h>
2 #include <stdio.h>
3 #include "posixtest.h"
4
5 /*
6
7 * Copyright (c) 2002, Intel Corporation. All rights reserved.
8 * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
9 * This file is licensed under the GPL license. For the full content
10 * of this license, see the COPYING file at the top level of this
11 * source tree.
12
13 * Test that the sigwait() function. Upon successful completion, sigwait()
14 * returns 0 and stores the signal number of the received signal at the
15 * location referenced by 'sig'.
16 * 1) Block a signal from delivery.
17 * 2) Call sigwait()
18 * 3) Raise the signal (to continue the process so we don't pause with
19 * sigwait() forever.
20 * 4) Verify the return value and the 'sig' value is correct.
21 */
22
main(void)23 int main(void)
24 {
25 sigset_t newmask, pendingset;
26 int sig;
27
28 /* Empty set of blocked signals */
29 if (sigemptyset(&newmask) == -1 || sigemptyset(&pendingset) == -1) {
30 printf("Error in sigemptyset()\n");
31 return PTS_UNRESOLVED;
32 }
33
34 /* Add SIGUSR2 to the set of blocked signals */
35 if (sigaddset(&newmask, SIGUSR2) == -1) {
36 perror("Error in sigaddset()\n");
37 return PTS_UNRESOLVED;
38 }
39
40 /* Block SIGUSR2 */
41 if (sigprocmask(SIG_SETMASK, &newmask, NULL) == -1) {
42 printf("Error in sigprocmask()\n");
43 return PTS_UNRESOLVED;
44 }
45
46 /* Send SIGUSR2 signal to this process. Since it is blocked,
47 * it should be pending */
48 if (raise(SIGUSR2) != 0) {
49 printf("Could not raise SIGUSR2\n");
50 return PTS_UNRESOLVED;
51 }
52
53 /* Call sigwait and test if it passed/failed */
54 if (sigwait(&newmask, &sig) != 0) {
55 printf("Error in sigwait()\n");
56 printf("Test FAILED\n");
57 return PTS_FAIL;
58 }
59
60 /* If we get here, then the process was suspended until
61 * SIGUSR2 was raised. */
62 if (sig == SIGUSR2) {
63 printf("Test PASSED\n");
64 return PTS_PASS;
65 } else {
66 printf("Test FAILED\n");
67 return PTS_FAIL;
68 }
69
70 }
71