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. 14 * If prior to the call to sigwait() there are multiple pending instances of 15 * a single signal number (and it is implementation-defined that the signal 16 * number supports queued signals), then there should be remaining 17 * pending signals for that signal number. 18 * Steps are: 19 * 1) Block a signal that supports queueing (the realtime signal SIGRTMIN). 20 * 2) Raise that signal 2 times. 21 * 3) Call sigwait() 22 * 4) Verify that is cleared only one instance of the signal in the pending 23 * set. 24 * 5) Call sigwait() again to clear the second instance of the signal in the 25 * pending list. 26 * 6) Verify that there are no more instances for SIGRTMIN in the pending list. * 27 */ 28 29 int main(void) 30 { 31 sigset_t newmask, pendingset; 32 int sig; 33 34 /* Empty set of blocked signals */ 35 36 if ((sigemptyset(&newmask) == -1) || (sigemptyset(&pendingset) == -1)) { 37 printf("Error in sigemptyset()\n"); 38 return PTS_UNRESOLVED; 39 } 40 41 /* Add SIGRTMIN to the set of blocked signals */ 42 if (sigaddset(&newmask, SIGRTMIN) == -1) { 43 perror("Error in sigaddset()\n"); 44 return PTS_UNRESOLVED; 45 } 46 47 /* Obtain a set of pending signals and make sure SIGRTMIN 48 * isn't pending. */ 49 if (sigpending(&pendingset) == -1) { 50 printf("Error calling sigpending()\n"); 51 return PTS_UNRESOLVED; 52 } 53 54 if (sigismember(&pendingset, SIGRTMIN) == 1) { 55 printf("Error: signal SIGRTMIN is pending\n"); 56 return PTS_UNRESOLVED; 57 } 58 59 /* Block SIGALRM */ 60 if (sigprocmask(SIG_SETMASK, &newmask, NULL) == -1) { 61 printf("Error in sigprocmask()\n"); 62 return PTS_UNRESOLVED; 63 } 64 65 /* Send SIGALRM signal 2 times to this process. Since it is blocked, 66 * it should be pending and queued. */ 67 if (raise(SIGRTMIN) != 0) { 68 printf("Could not raise SIGALRM\n"); 69 return PTS_UNRESOLVED; 70 } 71 72 if (raise(SIGRTMIN) != 0) { 73 printf("Could not raise SIGALRM\n"); 74 return PTS_UNRESOLVED; 75 } 76 77 /* Obtain a set of pending signals */ 78 if (sigpending(&pendingset) == -1) { 79 printf("Error calling sigpending()\n"); 80 return PTS_UNRESOLVED; 81 } 82 83 /* Make sure SIGRTMIN is still pending since sigwait should have only 84 * deleted one instance of SIGRTMIN from the pending set. */ 85 if (sigismember(&pendingset, SIGRTMIN) == 0) { 86 printf("Test FAILED\n"); 87 return -1; 88 } 89 90 /* Call sigwait to remove first SIGRTMIN instance from the 91 * pending list. */ 92 if (sigwait(&newmask, &sig) != 0) { 93 printf("Error in sigwait\n"); 94 return PTS_FAIL; 95 } 96 97 /* Make sure SIGRTMIN is still in the pending list */ 98 if (sigpending(&pendingset) == -1) { 99 printf("Error calling sigpending()\n"); 100 return PTS_UNRESOLVED; 101 } 102 103 if (sigismember(&pendingset, SIGRTMIN) == 0) { 104 printf("Test FAILED\n"); 105 return PTS_FAIL; 106 } 107 108 /* Call sigwait again to remove last SIGRTMIN instance from the 109 * pending list. */ 110 if (sigwait(&newmask, &sig) != 0) { 111 printf("Error in sigwait\n"); 112 return PTS_FAIL; 113 } 114 115 /* Make sure SIGRTMIN is NOT in the pending list anymore, since 116 * the previous sigwait() should have taken it out of the 117 * pending list. */ 118 if (sigpending(&pendingset) == -1) { 119 printf("Error calling sigpending()\n"); 120 return PTS_UNRESOLVED; 121 } 122 123 if (sigismember(&pendingset, SIGRTMIN) != 0) { 124 printf("Test FAILED\n"); 125 return PTS_FAIL; 126 } 127 128 printf("Test PASSED\n"); 129 return PTS_PASS; 130 131 } 132