]> Zhao Yanbai Git Server - minix.git/commitdiff
libc: more poll(3) wrapper fixes 94/3394/1
authorDavid van Moolenbroek <david@minix3.org>
Wed, 15 Feb 2017 19:13:43 +0000 (19:13 +0000)
committerDavid van Moolenbroek <david@minix3.org>
Thu, 16 Feb 2017 10:18:26 +0000 (10:18 +0000)
- POLLRDBAND is reported by select(2) as errorfd, not readfd;
- POLLERR is not the same as errorfd of select(2);
- flags that are not requested should not be returned.

Change-Id: I9cb3c2c260ead5a2852a2fbbc10280c2b5b0dff9

minix/lib/libc/sys/poll.c

index 8735833c2c08a235120463442a8f4e8e3e0e09f4..0c375f480a7d79f68ab89fa67d3281c14bb563e5 100644 (file)
@@ -67,11 +67,12 @@ poll(struct pollfd *p, nfds_t nfds, int timout)
                if (p[i].fd > highfd)
                        highfd = p[i].fd;
 
-               if (p[i].events & (POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI))
+               if (p[i].events & (POLLIN|POLLRDNORM))
                        FD_SET(p[i].fd, &rd);
                if (p[i].events & (POLLOUT|POLLWRNORM|POLLWRBAND))
                        FD_SET(p[i].fd, &wr);
-               FD_SET(p[i].fd, &except);
+               if (p[i].events & (POLLRDBAND|POLLPRI))
+                       FD_SET(p[i].fd, &except);
        }
 
        tv.tv_sec = timout / 1000;
@@ -87,12 +88,13 @@ poll(struct pollfd *p, nfds_t nfds, int timout)
                if (p[i].fd < 0)
                        continue;
                if (FD_ISSET(p[i].fd, &rd))
-                       p[i].revents |= POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI;
+                       p[i].revents |= p[i].events & (POLLIN|POLLRDNORM);
                if (FD_ISSET(p[i].fd, &wr))
-                       p[i].revents |= POLLOUT|POLLWRNORM|POLLWRBAND;
+                       p[i].revents |=
+                           p[i].events & (POLLOUT|POLLWRNORM|POLLWRBAND);
                if (FD_ISSET(p[i].fd, &except))
-                       p[i].revents |= POLLERR;
-               /* XXX: POLLHUP/POLLNVAL? */
+                       p[i].revents |= p[i].events & (POLLRDBAND|POLLPRI);
+               /* XXX: POLLERR/POLLHUP/POLLNVAL? */
                if (p[i].revents != 0)
                        rval++;
        }