From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 4C3D8386C590; Thu, 30 Jun 2022 18:41:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C3D8386C590 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: poll: Fix a bug on inquiring same fd with different events. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: e7ffbdb01894cb96a62cb6307f542700d9d38af5 X-Git-Newrev: 54930ae7d7c1a0eaa18e7fbf8b2ae6398a0f5698 Message-Id: <20220630184119.4C3D8386C590@sourceware.org> Date: Thu, 30 Jun 2022 18:41:19 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jun 2022 18:41:19 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D54930ae7d7c= 1a0eaa18e7fbf8b2ae6398a0f5698 commit 54930ae7d7c1a0eaa18e7fbf8b2ae6398a0f5698 Author: Takashi Yano Date: Mon Jun 27 10:03:04 2022 +0900 Cygwin: poll: Fix a bug on inquiring same fd with different events. =20 - poll() has a bug that it returns event which is not inquired if events are inquired in multiple pollfd entries on the same fd at the same time. This patch fixes the issue. Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251732.html Diff: --- winsup/cygwin/poll.cc | 8 +++++--- winsup/cygwin/release/3.3.6 | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/poll.cc b/winsup/cygwin/poll.cc index 440413433..a67507bbd 100644 --- a/winsup/cygwin/poll.cc +++ b/winsup/cygwin/poll.cc @@ -104,7 +104,7 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout) fds[i].revents =3D POLLHUP; else { - if (FD_ISSET(fds[i].fd, read_fds)) + if ((fds[i].events & POLLIN) && FD_ISSET(fds[i].fd, read_fds)) /* This should be sufficient for sockets, too. Using MSG_PEEK, as before, can be considered dangerous at best. Quote from W. Richard Stevens: "The presence @@ -122,9 +122,11 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout) fds[i].revents |=3D (POLLIN | POLLERR); else { - if (FD_ISSET(fds[i].fd, write_fds)) + if ((fds[i].events & POLLOUT) + && FD_ISSET(fds[i].fd, write_fds)) fds[i].revents |=3D POLLOUT; - if (FD_ISSET(fds[i].fd, except_fds)) + if ((fds[i].events & POLLPRI) + && FD_ISSET(fds[i].fd, except_fds)) fds[i].revents |=3D POLLPRI; } } diff --git a/winsup/cygwin/release/3.3.6 b/winsup/cygwin/release/3.3.6 index 49ac58ba4..f1a4b7812 100644 --- a/winsup/cygwin/release/3.3.6 +++ b/winsup/cygwin/release/3.3.6 @@ -17,3 +17,8 @@ Bug Fixes =20 - Handle setting very long window title correctly in console. Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251662.html + +- Fix a bug of poll() that it returns event which is not inquired + if events are inquired in multiple pollfd entries on the same fd + at the same time. + Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251732.html