Dmitry V. Levin | d9fb450 | 2015-07-30 19:46:11 +0000 | [diff] [blame] | 1 | #ifdef HAVE_CONFIG_H |
| 2 | # include "config.h" |
| 3 | #endif |
| 4 | |
| 5 | #include <poll.h> |
| 6 | #include <signal.h> |
| 7 | #include <unistd.h> |
| 8 | |
| 9 | static int |
| 10 | test1(void) |
| 11 | { |
| 12 | sigset_t mask; |
| 13 | const struct timespec timeout = { .tv_sec = 42, .tv_nsec = 999999999 }; |
| 14 | struct pollfd fds[] = { |
| 15 | { .fd = 0, .events = POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND }, |
| 16 | { .fd = 1, .events = POLLOUT | POLLWRNORM | POLLWRBAND }, |
| 17 | { .fd = 3, .events = POLLIN | POLLPRI }, |
| 18 | { .fd = 4, .events = POLLOUT } |
| 19 | }; |
| 20 | |
| 21 | sigemptyset(&mask); |
| 22 | sigaddset(&mask, SIGUSR2); |
| 23 | sigaddset(&mask, SIGCHLD); |
| 24 | |
| 25 | return ppoll(fds, sizeof(fds) / sizeof(*fds), &timeout, &mask) == 2 ? 0 : 77; |
| 26 | } |
| 27 | |
| 28 | static int |
| 29 | test2(void) |
| 30 | { |
| 31 | sigset_t mask; |
| 32 | const struct timespec timeout = { .tv_sec = 0, .tv_nsec = 999 }; |
| 33 | struct pollfd fds[] = { |
| 34 | { .fd = 1, .events = POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND }, |
| 35 | { .fd = 0, .events = POLLOUT | POLLWRNORM | POLLWRBAND } |
| 36 | }; |
| 37 | |
| 38 | sigfillset(&mask); |
Dmitry V. Levin | 0c0453a | 2015-08-01 08:55:32 +0000 | [diff] [blame] | 39 | sigdelset(&mask, SIGHUP); |
Dmitry V. Levin | d9fb450 | 2015-07-30 19:46:11 +0000 | [diff] [blame] | 40 | sigdelset(&mask, SIGKILL); |
| 41 | sigdelset(&mask, SIGSTOP); |
| 42 | |
| 43 | return ppoll(fds, sizeof(fds) / sizeof(*fds), &timeout, &mask) == 0 ? 0 : 77; |
| 44 | } |
| 45 | |
| 46 | int |
| 47 | main(void) |
| 48 | { |
| 49 | int rc; |
| 50 | int fds[2]; |
| 51 | |
| 52 | (void) close(0); |
| 53 | (void) close(1); |
| 54 | (void) close(3); |
| 55 | (void) close(4); |
| 56 | if (pipe(fds) || pipe(fds)) |
| 57 | return 77; |
| 58 | |
| 59 | |
| 60 | if ((rc = test1())) |
| 61 | return rc; |
| 62 | |
| 63 | if ((rc = test2())) |
| 64 | return rc; |
| 65 | |
| 66 | return ppoll(NULL, 42, NULL, NULL) < 0 ? 0 : 77; |
| 67 | } |