public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: poll: Fix a bug on inquiring same fd with different events.
Date: Mon, 27 Jun 2022 10:50:32 +0900	[thread overview]
Message-ID: <20220627015032.278-1-takashi.yano@nifty.ne.jp> (raw)

- 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
---
 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
-- 
2.36.1


             reply	other threads:[~2022-06-27  1:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27  1:50 Takashi Yano [this message]
2022-06-30 16:04 ` Ken Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220627015032.278-1-takashi.yano@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).