Re: Make __EV_POLL flag specific to kqueue-based poll(2)

2021-12-10 Thread Todd C . Miller
On Thu, 09 Dec 2021 15:38:36 +, Visa Hankala wrote:

> The system now has two flags for poll and select system calls,
> __EV_POLL which currently covers both calls, and __EV_SELECT which is
> used with select only.
>
> To make the code easier to follow, this diff makes __EV_POLL specific
> to poll(2). Consequently, __EV_SELECT has to be added when the condition
> is relevant to select(2). __EV_HUP will be specific to kqueue-based
> poll(2), so the code that sets __EV_HUP can keep on checking just
> __EV_POLL.

Yes, I think this is easier to understand.  OK millert@

 - todd



Make __EV_POLL flag specific to kqueue-based poll(2)

2021-12-09 Thread Visa Hankala
The system now has two flags for poll and select system calls,
__EV_POLL which currently covers both calls, and __EV_SELECT which is
used with select only.

To make the code easier to follow, this diff makes __EV_POLL specific
to poll(2). Consequently, __EV_SELECT has to be added when the condition
is relevant to select(2). __EV_HUP will be specific to kqueue-based
poll(2), so the code that sets __EV_HUP can keep on checking just
__EV_POLL.

OK?

Index: isofs/cd9660/cd9660_vnops.c
===
RCS file: src/sys/isofs/cd9660/cd9660_vnops.c,v
retrieving revision 1.90
diff -u -p -r1.90 cd9660_vnops.c
--- isofs/cd9660/cd9660_vnops.c 2 Oct 2021 08:51:41 -   1.90
+++ isofs/cd9660/cd9660_vnops.c 9 Dec 2021 14:59:41 -
@@ -1017,7 +1017,7 @@ filt_cd9660read(struct knote *kn, long h
return (1);
}
 
-   if (kn->kn_flags & __EV_POLL)
+   if (kn->kn_flags & (__EV_POLL | __EV_SELECT))
return (1);
 
return (kn->kn_data != 0);
Index: kern/kern_event.c
===
RCS file: src/sys/kern/kern_event.c,v
retrieving revision 1.174
diff -u -p -r1.174 kern_event.c
--- kern/kern_event.c   29 Nov 2021 15:54:04 -  1.174
+++ kern/kern_event.c   9 Dec 2021 14:59:41 -
@@ -1779,7 +1779,7 @@ knote_remove(struct proc *p, struct kque
 * This reuses the original knote for delivering the
 * notification so as to avoid allocating memory.
 */
-   if (!purge && (kn->kn_flags & __EV_POLL) &&
+   if (!purge && (kn->kn_flags & (__EV_POLL | __EV_SELECT)) &&
!(p->p_kq == kq &&
  p->p_kq_serial > (unsigned long)kn->kn_udata) &&
kn->kn_fop != &badfd_filtops) {
Index: kern/spec_vnops.c
===
RCS file: src/sys/kern/spec_vnops.c,v
retrieving revision 1.106
diff -u -p -r1.106 spec_vnops.c
--- kern/spec_vnops.c   15 Oct 2021 06:30:06 -  1.106
+++ kern/spec_vnops.c   9 Dec 2021 14:59:41 -
@@ -404,7 +404,7 @@ spec_kqfilter(void *v)
 
switch (ap->a_vp->v_type) {
default:
-   if (ap->a_kn->kn_flags & __EV_POLL)
+   if (ap->a_kn->kn_flags & (__EV_POLL | __EV_SELECT))
return seltrue_kqfilter(dev, ap->a_kn);
break;
case VCHR:
Index: kern/sys_generic.c
===
RCS file: src/sys/kern/sys_generic.c,v
retrieving revision 1.145
diff -u -p -r1.145 sys_generic.c
--- kern/sys_generic.c  8 Dec 2021 13:03:52 -   1.145
+++ kern/sys_generic.c  9 Dec 2021 14:59:41 -
@@ -762,7 +762,7 @@ pselregister(struct proc *p, fd_set *pib
DPRINTFN(2, "select fd %d mask %d serial %lu\n",
fd, msk, p->p_kq_serial);
EV_SET(&kev, fd, evf[msk],
-   EV_ADD|EV_ENABLE|__EV_POLL|__EV_SELECT,
+   EV_ADD|EV_ENABLE|__EV_SELECT,
evff[msk], 0, (void *)(p->p_kq_serial));
 #ifdef KTRACE
if (KTRPOINT(p, KTR_STRUCT))
Index: kern/tty_tty.c
===
RCS file: src/sys/kern/tty_tty.c,v
retrieving revision 1.28
diff -u -p -r1.28 tty_tty.c
--- kern/tty_tty.c  10 Mar 2021 10:21:47 -  1.28
+++ kern/tty_tty.c  9 Dec 2021 14:59:41 -
@@ -159,7 +159,7 @@ cttykqfilter(dev_t dev, struct knote *kn
struct vnode *ttyvp = cttyvp(curproc);
 
if (ttyvp == NULL) {
-   if (kn->kn_flags & __EV_POLL)
+   if (kn->kn_flags & (__EV_POLL | __EV_SELECT))
return (seltrue_kqfilter(dev, kn));
return (ENXIO);
}
Index: miscfs/fifofs/fifo_vnops.c
===
RCS file: src/sys/miscfs/fifofs/fifo_vnops.c,v
retrieving revision 1.86
diff -u -p -r1.86 fifo_vnops.c
--- miscfs/fifofs/fifo_vnops.c  8 Dec 2021 13:03:52 -   1.86
+++ miscfs/fifofs/fifo_vnops.c  9 Dec 2021 14:59:41 -
@@ -531,7 +531,7 @@ fifo_kqfilter(void *v)
case EVFILT_WRITE:
if (!(ap->a_fflag & FWRITE)) {
/* Tell upper layer to ask for POLLUP only */
-   if (ap->a_kn->kn_flags & __EV_POLL)
+   if (ap->a_kn->kn_flags & (__EV_POLL | __EV_SELECT))
return (EPERM);
return (EINVAL);
}
Index: miscfs/fuse/fuse_vnops.c
===
RCS file: src/sys/miscfs/fuse/fuse_vnops.c,v
retrieving revision 1.64
diff -u -p -r1.64 fuse_vnops.c
--- miscfs/fuse/fuse_vnops.c2 Oct 2021 17:2