public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/cygwin-3_3-branch] Cygwin: poll: Fix a bug on inquiring same fd with different events.
@ 2022-06-30 18:41 Takashi Yano
  0 siblings, 0 replies; only message in thread
From: Takashi Yano @ 2022-06-30 18:41 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=5603daa90003aba39454b0e9b53d3ab79a9e041d

commit 5603daa90003aba39454b0e9b53d3ab79a9e041d
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Mon Jun 27 10:03:04 2022 +0900

    Cygwin: poll: Fix a bug on inquiring same fd with different events.
    
    - 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 = 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 |= (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 |= POLLOUT;
-		  if (FD_ISSET(fds[i].fd, except_fds))
+		  if ((fds[i].events & POLLPRI)
+		      && FD_ISSET(fds[i].fd, except_fds))
 		    fds[i].revents |= 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
 
 - 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-30 18:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 18:41 [newlib-cygwin/cygwin-3_3-branch] Cygwin: poll: Fix a bug on inquiring same fd with different events Takashi Yano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).