(__kernel_standard): Pole errors in atanh should set ERANGE.
[glibc/history.git] / misc / tst-pselect.c
blob35d51d8ee04ac49e94e4b1decc41f0d08e586bd2
1 #include <errno.h>
2 #include <signal.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <sys/select.h>
6 #include <sys/wait.h>
9 static volatile int handler_called;
11 static void
12 handler (int sig)
14 handler_called = 1;
18 static int
19 do_test (void)
21 struct sigaction sa;
22 sa.sa_handler = handler;
23 sa.sa_flags = 0;
24 sigemptyset (&sa.sa_mask);
26 if (sigaction (SIGUSR1, &sa, NULL) != 0)
28 puts ("sigaction failed");
29 return 1;
32 sa.sa_handler = SIG_IGN;
33 sa.sa_flags = SA_NOCLDWAIT;
35 if (sigaction (SIGCHLD, &sa, NULL) != 0)
37 puts ("2nd sigaction failed");
38 return 1;
41 if (sigblock (sigmask (SIGUSR1)) != 0)
43 puts ("sigblock failed");
44 return 1;
47 int fds[2][2];
49 if (pipe (fds[0]) != 0 || pipe (fds[1]) != 0)
51 puts ("pipe failed");
52 return 1;
55 fd_set rfds;
56 FD_ZERO (&rfds);
58 sigset_t ss;
59 sigprocmask (SIG_SETMASK, NULL, &ss);
60 sigdelset (&ss, SIGUSR1);
62 struct timespec to = { .tv_sec = 0, .tv_nsec = 500000000 };
64 pid_t parent = getpid ();
65 pid_t p = fork ();
66 if (p == 0)
68 close (fds[0][1]);
69 close (fds[1][0]);
71 FD_SET (fds[0][0], &rfds);
73 int e;
76 if (getppid () != parent)
77 exit (2);
79 errno = 0;
80 e = pselect (fds[0][0] + 1, &rfds, NULL, NULL, &to, &ss);
82 while (e == 0);
84 if (e != -1)
86 puts ("child: pselect did not fail");
87 return 0;
89 if (errno != EINTR)
91 puts ("child: pselect did not set errno to EINTR");
92 return 0;
95 TEMP_FAILURE_RETRY (write (fds[1][1], "foo", 3));
97 exit (0);
100 close (fds[0][0]);
101 close (fds[1][1]);
103 FD_SET (fds[1][0], &rfds);
105 kill (p, SIGUSR1);
107 int e = pselect (fds[1][0] + 1, &rfds, NULL, NULL, NULL, &ss);
108 if (e == -1)
110 puts ("parent: pselect failed");
111 return 1;
113 if (e != 1)
115 puts ("parent: pselect did not report readable fd");
116 return 1;
118 if (!FD_ISSET (fds[1][0], &rfds))
120 puts ("parent: pselect reports wrong fd");
121 return 1;
124 return 0;
127 #define TEST_FUNCTION do_test ()
128 #include "../test-skeleton.c"