Remove powerpc, sparc fdim inlines (bug 22987).
[glibc.git] / misc / tst-pselect.c
blobfc28d64238b8ee3905c22ba842db5b30ecea0eed
1 /* Copyright (C) 2006-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <signal.h>
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <sys/select.h>
23 #include <sys/wait.h>
24 #include <stdlib.h>
27 static volatile int handler_called;
29 static void
30 handler (int sig)
32 handler_called = 1;
36 static int
37 do_test (void)
39 struct sigaction sa;
40 sa.sa_handler = handler;
41 sa.sa_flags = 0;
42 sigemptyset (&sa.sa_mask);
44 if (sigaction (SIGUSR1, &sa, NULL) != 0)
46 puts ("sigaction failed");
47 return 1;
50 sa.sa_handler = SIG_IGN;
51 if (sigaction (SIGCHLD, &sa, NULL) != 0)
53 puts ("2nd sigaction failed");
54 return 1;
57 sigset_t ss_usr1;
58 sigemptyset (&ss_usr1);
59 sigaddset (&ss_usr1, SIGUSR1);
60 if (sigprocmask (SIG_BLOCK, &ss_usr1, NULL) != 0)
62 puts ("sigprocmask failed");
63 return 1;
66 int fds[2][2];
68 if (pipe (fds[0]) != 0 || pipe (fds[1]) != 0)
70 puts ("pipe failed");
71 return 1;
74 fd_set rfds;
75 FD_ZERO (&rfds);
77 sigset_t ss;
78 sigprocmask (SIG_SETMASK, NULL, &ss);
79 sigdelset (&ss, SIGUSR1);
81 struct timespec to = { .tv_sec = 0, .tv_nsec = 500000000 };
83 pid_t parent = getpid ();
84 pid_t p = fork ();
85 if (p == 0)
87 close (fds[0][1]);
88 close (fds[1][0]);
90 FD_SET (fds[0][0], &rfds);
92 int e;
95 if (getppid () != parent)
96 exit (2);
98 errno = 0;
99 e = pselect (fds[0][0] + 1, &rfds, NULL, NULL, &to, &ss);
101 while (e == 0);
103 if (e != -1)
105 puts ("child: pselect did not fail");
106 return 0;
108 if (errno != EINTR)
110 puts ("child: pselect did not set errno to EINTR");
111 return 0;
114 TEMP_FAILURE_RETRY (write (fds[1][1], "foo", 3));
116 exit (0);
119 close (fds[0][0]);
120 close (fds[1][1]);
122 FD_SET (fds[1][0], &rfds);
124 kill (p, SIGUSR1);
126 int e = pselect (fds[1][0] + 1, &rfds, NULL, NULL, NULL, &ss);
127 if (e == -1)
129 puts ("parent: pselect failed");
130 return 1;
132 if (e != 1)
134 puts ("parent: pselect did not report readable fd");
135 return 1;
137 if (!FD_ISSET (fds[1][0], &rfds))
139 puts ("parent: pselect reports wrong fd");
140 return 1;
143 return 0;
146 #define TEST_FUNCTION do_test ()
147 #include "../test-skeleton.c"