3-1.c revision a1262411bc2cc97541830aa543ac6f7c9cffc074
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 27 28int main() 29{ 30 sigset_t newmask, pendingset; 31 int sig; 32 33 /* Empty set of blocked signals */ 34 if ((sigemptyset(&newmask) == -1) || 35<<<<<<< HEAD 36 (sigemptyset(&pendingset) == -1) ) 37======= 38 (sigemptyset(&pendingset) == -1)) 39>>>>>>> origin 40 { 41 printf("Error in sigemptyset()\n"); 42 return PTS_UNRESOLVED; 43 } 44 45 /* Add SIGALRM to the set of blocked signals */ 46 if (sigaddset(&newmask, SIGALRM) == -1) 47 { 48 perror("Error in sigaddset()\n"); 49 return PTS_UNRESOLVED; 50 } 51 52 /* Block SIGALRM */ 53 if (sigprocmask(SIG_SETMASK, &newmask, NULL) == -1) 54 { 55 printf("Error in sigprocmask()\n"); 56 return PTS_UNRESOLVED; 57 } 58 59 /* Send SIGALRM signal 4 times to this process. Since it is blocked, 60 * it should be pending. */ 61 if (raise(SIGALRM) != 0) { 62 printf("Could not raise SIGALRM\n"); 63 return PTS_UNRESOLVED; 64 } 65 if (raise(SIGALRM) != 0) { 66 printf("Could not raise SIGALRM\n"); 67 return PTS_UNRESOLVED; 68 } 69 if (raise(SIGALRM) != 0) { 70 printf("Could not raise SIGALRM\n"); 71 return PTS_UNRESOLVED; 72 } 73 if (raise(SIGALRM) != 0) { 74 printf("Could not raise SIGALRM\n"); 75 return PTS_UNRESOLVED; 76 } 77 78 /* Obtain a set of pending signals */ 79 if (sigpending(&pendingset) == -1) { 80 printf("Error calling sigpending()\n"); 81 return PTS_UNRESOLVED; 82 } 83 84 /* Make sure SIGALRM is pending */ 85 if (sigismember(&pendingset, SIGALRM) == 0) { 86 printf("Error: signal SIGALRM not pending\n"); 87 return PTS_UNRESOLVED; 88 } 89 90 /* Call sigwait */ 91 if (sigwait(&newmask, &sig) != 0) 92 { 93 printf("Error in sigwait\n"); 94 return PTS_UNRESOLVED; 95 } 96 97 /* Make sure SIGALRM is not in the pending list anymore */ 98 if (sigpending(&pendingset) == -1) { 99 printf("Error calling sigpending()\n"); 100 return PTS_UNRESOLVED; 101 } 102 103 if (sigismember(&pendingset, SIGALRM) == 1) 104 { 105 printf("Test FAILED\n"); 106 return PTS_FAIL; 107 } 108 109 printf("Test PASSED\n"); 110 return PTS_PASS; 111 112} 113