1 /*
2
3 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
4 * Created by: rusty.lynch REMOVE-THIS AT intel DOT com
5 * This file is licensed under the GPL license. For the full content
6 * of this license, see the COPYING file at the top level of this
7 * source tree.
8
9 Test assertion #17 by verifying that select returns -1 with
10 errno set to EINTR if a handler for the SIGALRM signal is setup with
11 the SA_RESTART flag cleared.
12 * 12/18/02 - Adding in include of sys/time.h per
13 * rodrigc REMOVE-THIS AT attbi DOT com input that it needs
14 * to be included whenever the timeval struct is used.
15 */
16
17 #include <signal.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <sys/select.h>
21 #include <sys/wait.h>
22 #include <sys/time.h>
23 #include <sys/types.h>
24 #include <unistd.h>
25 #include <errno.h>
26 #include "posixtest.h"
27
28 static volatile sig_atomic_t wakeup = 1;
29
handler(int signo PTS_ATTRIBUTE_UNUSED)30 static void handler(int signo PTS_ATTRIBUTE_UNUSED)
31 {
32 wakeup++;
33 }
34
main(void)35 int main(void)
36 {
37 pid_t pid;
38 struct timeval tv;
39
40 if ((pid = fork()) == 0) {
41 /* child */
42 struct sigaction act;
43
44 act.sa_handler = handler;
45 act.sa_flags = 0;
46 sigemptyset(&act.sa_mask);
47 sigaction(SIGALRM, &act, 0);
48
49 while (wakeup == 1) {
50 tv.tv_sec = 3;
51 tv.tv_usec = 0;
52 if (select(0, NULL, NULL, NULL, &tv) == -1 &&
53 errno == EINTR) {
54 perror("select");
55 return PTS_PASS;
56 }
57 }
58
59 return PTS_FAIL;
60 } else {
61 /* parent */
62 int s;
63
64 /*
65 There is a race condition between the parent
66 process sending the SIGALRM signal, and the
67 child process being inside the 'select' function
68 call.
69
70 I could not find a pure POSIX method for determining
71 the state of the child process, so I just added a delay
72 so that the test is valid in most conditions. (The
73 problem is that it would be perfectly legal for a
74 POSIX conformant OS to not schedule the child process
75 for a long time.)
76 */
77 tv.tv_sec = 1;
78 tv.tv_usec = 0;
79 select(0, NULL, NULL, NULL, &tv);
80
81 kill(pid, SIGALRM);
82 waitpid(pid, &s, 0);
83 if (WEXITSTATUS(s) == PTS_PASS) {
84 printf("Test PASSED\n");
85 return PTS_PASS;
86 }
87 }
88
89 printf("Test FAILED\n");
90 return PTS_FAIL;
91 }
92