On 29/10/21(Fri) 10:50, Anton Lindqvist wrote:
> On Fri, Oct 29, 2021 at 09:13:58AM +0100, Larry Hynes wrote:
> > Hi
> > 
> > In last two snapshots I installed, poll seems to hang in certain
> > circumstances.
> > 
> > Here's a reproducer, from Leah Neukirchen (cc'ed on this mail):

Thanks, do you agree to license it under ISC, as in 
/usr/share/misc/license.template, so we can put it in src/regress?

> > 
> > ------
> > 
> > #include <stdio.h>
> > #include <poll.h>
> > #include <unistd.h>
> > 
> > int
> > main()
> > {
> >     struct pollfd fds[1];
> >     
> >     fds[0].fd = 0;
> >     fds[0].events = POLLIN | POLLHUP;
> >     close(0);
> > 
> >     printf("%d\n", poll(fds, 1, -1));
> >     printf("%d\n", fds[0].revents & POLLNVAL);
> > }
> > 
> > ------
> > 
> > When compiled and run, that should hang on latest snap. It would be
> > expected to return immediately with POLLNVAL set.
> 
> I think poll() needs similar handling as select() recently gained.
> Caution, only compile tested.

Here's a simpler fix, do not sleep at all if we already have something
to report.

This works for me, ok?

Index: kern/sys_generic.c
===================================================================
RCS file: /cvs/src/sys/kern/sys_generic.c,v
retrieving revision 1.138
diff -u -p -r1.138 sys_generic.c
--- kern/sys_generic.c  24 Oct 2021 11:23:22 -0000      1.138
+++ kern/sys_generic.c  29 Oct 2021 12:26:48 -0000
@@ -1155,6 +1155,8 @@ doppoll(struct proc *p, struct pollfd *f
 
        /* Register kqueue events */
        *retval = ppollregister(p, pl, nfds, &nevents);
+       if (*retval != 0)
+               goto done;
 
        /*
         * The poll/select family of syscalls has been designed to

Reply via email to