* Scan, update kn_data (if not ONESHOT), and copyout triggered events. * We treat KN_MARKER knotes as if they are in flux. */
| 1788 | * We treat KN_MARKER knotes as if they are in flux. |
| 1789 | */ |
| 1790 | static int |
| 1791 | kqueue_scan(struct kqueue *kq, int maxevents, struct kevent_copyops *k_ops, |
| 1792 | const struct timespec *tsp, struct kevent *keva, struct thread *td) |
| 1793 | { |
| 1794 | struct kevent *kevp; |
| 1795 | struct knote *kn, *marker; |
| 1796 | struct knlist *knl; |
| 1797 | sbintime_t asbt, rsbt; |
| 1798 | int count, error, haskqglobal, influx, nkev, touch; |
| 1799 | |
| 1800 | count = maxevents; |
| 1801 | nkev = 0; |
| 1802 | error = 0; |
| 1803 | haskqglobal = 0; |
| 1804 | |
| 1805 | if (maxevents == 0) |
| 1806 | goto done_nl; |
| 1807 | |
| 1808 | rsbt = 0; |
| 1809 | if (tsp != NULL) { |
| 1810 | if (tsp->tv_sec < 0 || tsp->tv_nsec < 0 || |
| 1811 | tsp->tv_nsec >= 1000000000) { |
| 1812 | error = EINVAL; |
| 1813 | goto done_nl; |
| 1814 | } |
| 1815 | if (timespecisset(tsp)) { |
| 1816 | if (tsp->tv_sec <= INT32_MAX) { |
| 1817 | rsbt = tstosbt(*tsp); |
| 1818 | if (TIMESEL(&asbt, rsbt)) |
| 1819 | asbt += tc_tick_sbt; |
| 1820 | if (asbt <= SBT_MAX - rsbt) |
| 1821 | asbt += rsbt; |
| 1822 | else |
| 1823 | asbt = 0; |
| 1824 | rsbt >>= tc_precexp; |
| 1825 | } else |
| 1826 | asbt = 0; |
| 1827 | } else |
| 1828 | asbt = -1; |
| 1829 | } else |
| 1830 | asbt = 0; |
| 1831 | marker = knote_alloc(M_WAITOK); |
| 1832 | marker->kn_status = KN_MARKER; |
| 1833 | KQ_LOCK(kq); |
| 1834 | |
| 1835 | retry: |
| 1836 | kevp = keva; |
| 1837 | if (kq->kq_count == 0) { |
| 1838 | if (asbt == -1) { |
| 1839 | error = EWOULDBLOCK; |
| 1840 | } else { |
| 1841 | kq->kq_state |= KQ_SLEEP; |
| 1842 | error = msleep_sbt(kq, &kq->kq_lock, PSOCK | PCATCH, |
| 1843 | "kqread", asbt, rsbt, C_ABSOLUTE); |
| 1844 | } |
| 1845 | if (error == 0) |
| 1846 | goto retry; |
| 1847 | /* don't restart after signals... */ |
no test coverage detected