• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_REALTIME 1
29 
30 #define TIMERSIGNAL SIGUSR1
31 #define SIGTOTEST SIGUSR2
32 #define TIMERSEC 2
33 #define SIGTIMEDWAITSEC 1
34 
35 #include <errno.h>
36 #include <signal.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <time.h>
40 #include <unistd.h>
41 #include <sys/wait.h>
42 #include "posixtest.h"
43 
myhandler(int signo)44 void myhandler(int signo)
45 {
46 	printf
47 	    ("Test FAILED: %d seconds have elapsed and sigtimedwait() has not yet returned.\n",
48 	     TIMERSEC);
49 	exit(PTS_FAIL);
50 }
51 
main(void)52 int main(void)
53 {
54 	struct sigaction act;
55 
56 	sigset_t selectset;
57 	struct timespec ts;
58 /*
59 	struct sigevent ev;
60 	timer_t tid;
61 	struct itimerspec its;
62 
63         its.it_interval.tv_sec = 0;
64         its.it_interval.tv_nsec = 0;
65         its.it_value.tv_sec = TIMERSEC;
66         its.it_value.tv_nsec = 0;
67 
68         ev.sigev_notify = SIGEV_SIGNAL;
69         ev.sigev_signo = TIMERSIGNAL;
70 */
71 	act.sa_flags = 0;
72 	act.sa_handler = myhandler;
73 	sigemptyset(&act.sa_mask);
74 	sigaction(TIMERSIGNAL, &act, 0);
75 
76 	sigemptyset(&selectset);
77 	sigaddset(&selectset, SIGTOTEST);
78 
79 	ts.tv_sec = SIGTIMEDWAITSEC;
80 	ts.tv_nsec = 0;
81 /*
82         if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
83                 perror("timer_create() did not return success\n");
84                 return PTS_UNRESOLVED;
85         }
86 
87         if (timer_settime(tid, 0, &its, NULL) != 0) {
88                 perror("timer_settime() did not return success\n");
89                 return PTS_UNRESOLVED;
90         }
91 */
92 	if (sigtimedwait(&selectset, NULL, &ts) != -1) {
93 		printf("Test UNRESOLVED: sigtimedwait() did not return -1\n");
94 		return PTS_UNRESOLVED;
95 	}
96 
97 	if (errno != EAGAIN) {
98 		printf("Test FAILED: sigtimedwait() did set errno to EAGAIN\n");
99 		return PTS_FAIL;
100 	}
101 
102 	printf("Test PASSED\n");
103 	return PTS_PASS;
104 }
105