The original poll(2) implementation resumed and returned error POLLNVAL
if the file descriptor was closed by another thread.
This patch adds POLLNVAL translation to ppollcollect(). Currently,
the function returns POLLIN, POLLOUT or something else depending
on the event filter.
OK?
Index: kern/sys_generic.c
===================================================================
RCS file: src/sys/kern/sys_generic.c,v
retrieving revision 1.141
diff -u -p -r1.141 sys_generic.c
--- kern/sys_generic.c 16 Nov 2021 13:48:23 -0000 1.141
+++ kern/sys_generic.c 21 Nov 2021 06:24:50 -0000
@@ -1263,6 +1263,14 @@ ppollcollect(struct proc *p, struct keve
*/
already_seen = (pl[i].revents != 0);
+ /* POLLNVAL preempts other events. */
+ if ((kevp->flags & EV_ERROR) && kevp->data == EBADF) {
+ pl[i].revents = POLLNVAL;
+ goto done;
+ } else if (pl[i].revents & POLLNVAL) {
+ goto done;
+ }
+
switch (kevp->filter) {
case EVFILT_READ:
if (kevp->flags & __EV_HUP)
@@ -1294,6 +1302,7 @@ ppollcollect(struct proc *p, struct keve
KASSERT(0);
}
+done:
DPRINTFN(1, "poll get %lu/%d fd %d revents %02x serial %lu filt %d\n",
i+1, nfds, pl[i].fd, pl[i].revents, (unsigned long)kevp->udata,
kevp->filter);