diff options
author | Ken Brown <kbrown@cornell.edu> | 2022-09-23 17:24:04 +0300 |
---|---|---|
committer | Ken Brown <kbrown@cornell.edu> | 2022-10-19 15:17:50 +0300 |
commit | 5781871775fcba783938bc4ac645eba866711fc5 (patch) | |
tree | 525f5855d36f6d30a5da2f8dc539caa90e71cb69 /winsup/cygwin/fhandler/fifo.cc | |
parent | 0b6342c97f08765e9873b3c52d61657c2aa596e5 (diff) |
Cygwin: select: don't report read ready on a FIFO never opened for writing
According to POSIX and the Linux man page, select(2) is supposed to
report read ready if a file is at EOF. In the case of a FIFO, this
means that the pipe is empty and there are no writers. But there
seems to be an undocumented exception, observed on Linux and other
platforms: If no writer has ever been opened, then select(2) does not
report read ready. This can happen if a reader is opened with
O_NONBLOCK before any writers have opened.
This commit makes Cygwin consistent with those other platforms by
introducing a special EOF test, fhandler_fifo::select_hit_eof, which
returns false if there's never been a writer opened.
To implement this we use a new variable '_writer_opened' in the FIFO's
shared memory, which is set to 1 the first time a writer opens. New
methods writer_opened() and set_writer_opened() are used to test and
set this variable.
Addresses: https://cygwin.com/pipermail/cygwin/2022-September/252223.html
Diffstat (limited to 'winsup/cygwin/fhandler/fifo.cc')
-rw-r--r-- | winsup/cygwin/fhandler/fifo.cc | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/winsup/cygwin/fhandler/fifo.cc b/winsup/cygwin/fhandler/fifo.cc index 1d3e42908..efea508ae 100644 --- a/winsup/cygwin/fhandler/fifo.cc +++ b/winsup/cygwin/fhandler/fifo.cc @@ -1043,6 +1043,7 @@ writer_shmem: set_pipe_non_blocking (get_handle (), flags & O_NONBLOCK); nwriters_lock (); inc_nwriters (); + set_writer_opened (); SetEvent (write_ready); ResetEvent (writer_opening); nwriters_unlock (); |