3-1.c revision 2c28215423293e443469a07ae7011135d058b671
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 DOES NOT support queued signals), then there should be no remaining 17 * pending signals for that signal number. 18 * Steps are: 19 * 1) Block a signal that doesn't support queueing from delivery. 20 * 2) Raise that signal 4 times. 21 * 3) Call sigwait() 22 * 4) Verify it cleared the signal from the pending signals and there 23 * are no signals left in the pending list. 24 * 25 */ 26 27int main() 28{ 29 sigset_t newmask, pendingset; 30 int sig; 31 32 /* Empty set of blocked signals */ 33 if ((sigemptyset(&newmask) == -1) || 34 (sigemptyset(&pendingset) == -1)) 35 { 36 printf("Error in sigemptyset()\n"); 37 return PTS_UNRESOLVED; 38 } 39 40 /* Add SIGALRM to the set of blocked signals */ 41 if (sigaddset(&newmask, SIGALRM) == -1) 42 { 43 perror("Error in sigaddset()\n"); 44 return PTS_UNRESOLVED; 45 } 46 47 /* Block SIGALRM */ 48 if (sigprocmask(SIG_SETMASK, &newmask, NULL) == -1) 49 { 50 printf("Error in sigprocmask()\n"); 51 return PTS_UNRESOLVED; 52 } 53 54 /* Send SIGALRM signal 4 times to this process. Since it is blocked, 55 * it should be pending. */ 56 if (raise(SIGALRM) != 0) { 57 printf("Could not raise SIGALRM\n"); 58 return PTS_UNRESOLVED; 59 } 60 if (raise(SIGALRM) != 0) { 61 printf("Could not raise SIGALRM\n"); 62 return PTS_UNRESOLVED; 63 } 64 if (raise(SIGALRM) != 0) { 65 printf("Could not raise SIGALRM\n"); 66 return PTS_UNRESOLVED; 67 } 68 if (raise(SIGALRM) != 0) { 69 printf("Could not raise SIGALRM\n"); 70 return PTS_UNRESOLVED; 71 } 72 73 /* Obtain a set of pending signals */ 74 if (sigpending(&pendingset) == -1) { 75 printf("Error calling sigpending()\n"); 76 return PTS_UNRESOLVED; 77 } 78 79 /* Make sure SIGALRM is pending */ 80 if (sigismember(&pendingset, SIGALRM) == 0) { 81 printf("Error: signal SIGALRM not pending\n"); 82 return PTS_UNRESOLVED; 83 } 84 85 /* Call sigwait */ 86 if (sigwait(&newmask, &sig) != 0) 87 { 88 printf("Error in sigwait\n"); 89 return PTS_UNRESOLVED; 90 } 91 92 /* Make sure SIGALRM is not in the pending list anymore */ 93 if (sigpending(&pendingset) == -1) { 94 printf("Error calling sigpending()\n"); 95 return PTS_UNRESOLVED; 96 } 97 98 if (sigismember(&pendingset, SIGALRM) == 1) 99 { 100 printf("Test FAILED\n"); 101 return PTS_FAIL; 102 } 103 104 printf("Test PASSED\n"); 105 return PTS_PASS; 106 107}