Don't use INTDEF/INTUSE with _dl_argv (bug 14132).
[glibc.git] / misc / tst-pselect.c
blob36bc46da6c94174aa2ce6a5e369fd51964d794eb
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>
7 #include <stdlib.h>
10 static volatile int handler_called;
12 static void
13 handler (int sig)
15 handler_called = 1;
19 static int
20 do_test (void)
22 struct sigaction sa;
23 sa.sa_handler = handler;
24 sa.sa_flags = 0;
25 sigemptyset (&sa.sa_mask);
27 if (sigaction (SIGUSR1, &sa, NULL) != 0)
29 puts ("sigaction failed");
30 return 1;
33 sa.sa_handler = SIG_IGN;
34 sa.sa_flags = SA_NOCLDWAIT;
36 if (sigaction (SIGCHLD, &sa, NULL) != 0)
38 puts ("2nd sigaction failed");
39 return 1;
42 if (sigblock (sigmask (SIGUSR1)) != 0)
44 puts ("sigblock failed");
45 return 1;
48 int fds[2][2];
50 if (pipe (fds[0]) != 0 || pipe (fds[1]) != 0)
52 puts ("pipe failed");
53 return 1;
56 fd_set rfds;
57 FD_ZERO (&rfds);
59 sigset_t ss;
60 sigprocmask (SIG_SETMASK, NULL, &ss);
61 sigdelset (&ss, SIGUSR1);
63 struct timespec to = { .tv_sec = 0, .tv_nsec = 500000000 };
65 pid_t parent = getpid ();
66 pid_t p = fork ();
67 if (p == 0)
69 close (fds[0][1]);
70 close (fds[1][0]);
72 FD_SET (fds[0][0], &rfds);
74 int e;
77 if (getppid () != parent)
78 exit (2);
80 errno = 0;
81 e = pselect (fds[0][0] + 1, &rfds, NULL, NULL, &to, &ss);
83 while (e == 0);
85 if (e != -1)
87 puts ("child: pselect did not fail");
88 return 0;
90 if (errno != EINTR)
92 puts ("child: pselect did not set errno to EINTR");
93 return 0;
96 TEMP_FAILURE_RETRY (write (fds[1][1], "foo", 3));
98 exit (0);
101 close (fds[0][0]);
102 close (fds[1][1]);
104 FD_SET (fds[1][0], &rfds);
106 kill (p, SIGUSR1);
108 int e = pselect (fds[1][0] + 1, &rfds, NULL, NULL, NULL, &ss);
109 if (e == -1)
111 puts ("parent: pselect failed");
112 return 1;
114 if (e != 1)
116 puts ("parent: pselect did not report readable fd");
117 return 1;
119 if (!FD_ISSET (fds[1][0], &rfds))
121 puts ("parent: pselect reports wrong fd");
122 return 1;
125 return 0;
128 #define TEST_FUNCTION do_test ()
129 #include "../test-skeleton.c"