- zero(pollfd);
-
- pollfd[POLL_TTY].fd = ttyfd >= 0 ? ttyfd : STDIN_FILENO;
- pollfd[POLL_TTY].events = POLLIN;
- pollfd[POLL_INOTIFY].fd = notify;
- pollfd[POLL_INOTIFY].events = POLLIN;
-
- for (;;) {
- char c;
- int sleep_for = -1, k;
- ssize_t n;
-
- if (until > 0) {
- usec_t y;
-
- y = now(CLOCK_MONOTONIC);
-
- if (y > until) {
- r = -ETIMEDOUT;
- goto finish;
- }
-
- sleep_for = (int) ((until - y) / USEC_PER_MSEC);
- }
-
- if (flag_file)
- if (access(flag_file, F_OK) < 0) {
- r = -errno;
- goto finish;
- }
-
- if ((k = poll(pollfd, notify > 0 ? 2 : 1, sleep_for)) < 0) {
-
- if (errno == EINTR)
- continue;
-
- r = -errno;
- goto finish;
- } else if (k == 0) {
- r = -ETIMEDOUT;
- goto finish;
- }
-
- if (notify > 0 && pollfd[POLL_INOTIFY].revents != 0)
- flush_fd(notify);
-
- if (pollfd[POLL_TTY].revents == 0)
- continue;
-
- if ((n = read(ttyfd >= 0 ? ttyfd : STDIN_FILENO, &c, 1)) < 0) {
-
- if (errno == EINTR || errno == EAGAIN)
- continue;