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