1 /* 2 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. 3 * Created by: salwan.searty 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 sigtimedwait() sets errno to [EAGAIN] if no signal specified by 9 set was generated within the specified timeout period. 10 11 NOTE: This program has commented out areas. The commented out functionality 12 sets a timer in case sigtimedwait() never returns, to help the program 13 from hanging. To make this program 14 runnable on a typical system, I've commented out the timer functionality 15 by default. However, if you do have a timers implementation on your 16 system, then it is recommened that you uncomment the timers-related lines 17 of code in this program. 18 19 Steps: 20 1. Register signal TIMERSIGNAL with the handler myhandler 21 (2.)Create and set a timer that expires in TIMERSEC seconds incase sigtimedwait() 22 never returns. 23 3. Call sigtimedwait() to wait for non-pending signal SIGTOTEST for SIGTIMEDWAITSEC 24 seconds. 25 4. Verify that sigtimedwait() sets errno to [EAGAIN]. 26 */ 27 28 #define _XOPEN_SOURCE 600 29 #define _XOPEN_REALTIME 1 30 31 #define TIMERSIGNAL SIGUSR1 32 #define SIGTOTEST SIGUSR2 33 #define TIMERSEC 2 34 #define SIGTIMEDWAITSEC 1 35 36 #include <errno.h> 37 #include <signal.h> 38 #include <stdio.h> 39 #include <stdlib.h> 40 #include <time.h> 41 #include <unistd.h> 42 #include <sys/wait.h> 43 #include "posixtest.h" 44 45 void myhandler(int signo) 46 { 47 printf 48 ("Test FAILED: %d seconds have elapsed and sigtimedwait() has not yet returned.\n", 49 TIMERSEC); 50 exit(PTS_FAIL); 51 } 52 53 int main(void) 54 { 55 struct sigaction act; 56 57 sigset_t selectset; 58 struct timespec ts; 59 /* 60 struct sigevent ev; 61 timer_t tid; 62 struct itimerspec its; 63 64 its.it_interval.tv_sec = 0; 65 its.it_interval.tv_nsec = 0; 66 its.it_value.tv_sec = TIMERSEC; 67 its.it_value.tv_nsec = 0; 68 69 ev.sigev_notify = SIGEV_SIGNAL; 70 ev.sigev_signo = TIMERSIGNAL; 71 */ 72 act.sa_flags = 0; 73 act.sa_handler = myhandler; 74 sigemptyset(&act.sa_mask); 75 sigaction(TIMERSIGNAL, &act, 0); 76 77 sigemptyset(&selectset); 78 sigaddset(&selectset, SIGTOTEST); 79 80 ts.tv_sec = SIGTIMEDWAITSEC; 81 ts.tv_nsec = 0; 82 /* 83 if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { 84 perror("timer_create() did not return success\n"); 85 return PTS_UNRESOLVED; 86 } 87 88 if (timer_settime(tid, 0, &its, NULL) != 0) { 89 perror("timer_settime() did not return success\n"); 90 return PTS_UNRESOLVED; 91 } 92 */ 93 if (sigtimedwait(&selectset, NULL, &ts) != -1) { 94 printf("Test UNRESOLVED: sigtimedwait() did not return -1\n"); 95 return PTS_UNRESOLVED; 96 } 97 98 if (errno != EAGAIN) { 99 printf("Test FAILED: sigtimedwait() did set errno to EAGAIN\n"); 100 return PTS_FAIL; 101 } 102 103 printf("Test PASSED\n"); 104 return PTS_PASS; 105 } 106