Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178384772
D62518.1796635691.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D62518.1796635691.diff
View Options
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -2095,6 +2095,11 @@
/*
* Scan, update kn_data (if not ONESHOT), and copyout triggered events.
* We treat KN_MARKER knotes as if they are in flux.
+ *
+ * With peek, specified by k_ops == NULL, the triggered events are
+ * only counted against maxevents, and stay queued. The knotes
+ * without events are still discarded, which leaves kq_count non-zero
+ * only if there are events to report.
*/
static int
kqueue_scan(struct kqueue *kq, int maxevents, struct kevent_copyops *k_ops,
@@ -2208,6 +2213,9 @@
knote_drop(kn, td);
KQ_LOCK(kq);
continue;
+ } else if (k_ops == NULL && (kn->kn_flags & EV_ONESHOT) ==
+ EV_ONESHOT) {
+ TAILQ_INSERT_TAIL(&kq->kq_head, kn, kn_tqe);
} else if ((kn->kn_flags & EV_ONESHOT) == EV_ONESHOT) {
kn->kn_status &= ~KN_QUEUED;
kn_enter_flux(kn);
@@ -2241,13 +2249,17 @@
}
touch = (!kn->kn_fop->f_isfd &&
kn->kn_fop->f_touch != NULL);
- if (touch)
- kn->kn_fop->f_touch(kn, kevp, EVENT_PROCESS);
- else
- *kevp = kn->kn_kevent;
+ if (k_ops != NULL) {
+ if (touch)
+ kn->kn_fop->f_touch(kn, kevp,
+ EVENT_PROCESS);
+ else
+ *kevp = kn->kn_kevent;
+ }
KQ_LOCK(kq);
KQ_GLOBAL_UNLOCK(&kq_global, haskqglobal);
- if (kn->kn_flags & (EV_CLEAR | EV_DISPATCH)) {
+ if (k_ops != NULL &&
+ (kn->kn_flags & (EV_CLEAR | EV_DISPATCH)) != 0) {
/*
* Manually clear knotes who weren't
* 'touch'ed.
@@ -2269,10 +2281,13 @@
influx = 1;
}
+ count--;
+ if (k_ops == NULL)
+ continue;
+
/* we are returning a copy to the user */
kevp++;
nkev++;
- count--;
if (nkev == KQ_NEVENTS) {
influx = 0;
@@ -2293,7 +2308,8 @@
KQ_NOTOWNED(kq);
if (nkev != 0)
error = k_ops->k_copyout(k_ops->arg, keva, nkev);
- td->td_retval[0] = maxevents - count;
+ if (k_ops != NULL)
+ td->td_retval[0] = maxevents - count;
return (error);
}
@@ -2351,12 +2367,21 @@
struct thread *td)
{
struct kqueue *kq;
+ struct timespec ts;
int revents = 0;
int error;
if ((error = kqueue_acquire(fp, &kq)))
- return POLLERR;
+ return (POLLERR);
+ if ((events & (POLLIN | POLLRDNORM)) != 0) {
+ /*
+ * Discard the stale knotes, so that kq_count is non-zero
+ * only if kevent(2) would return an event.
+ */
+ timespecclear(&ts);
+ (void)kqueue_scan(kq, 1, NULL, &ts, NULL, td);
+ }
KQ_LOCK(kq);
if (events & (POLLIN | POLLRDNORM)) {
if (kq->kq_count) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 7, 9:28 AM (12 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42273750
Default Alt Text
D62518.1796635691.diff (2 KB)
Attached To
Mode
D62518: kqueue_poll(): do not report stale knotes
Attached
Detach File
Event Timeline