Sv: Sv: Named pipes and multiple writers
Ken Brown
kbrown@cornell.edu
Fri Mar 27 13:10:18 GMT 2020
On 3/26/2020 7:19 PM, Ken Brown via Cygwin wrote:
> On 3/26/2020 6:39 PM, Ken Brown via Cygwin wrote:
>> On 3/26/2020 6:01 PM, sten.kristian.ivarsson@gmail.com wrote:
>>> The ENIXIO occurs when parallel child-processes simultaneously using
>>> O_NONBLOCK opening the descriptor.
>>
>> This is consistent with my guess that the error is generated by
>> fhandler_fifo::wait. I have a feeling that read_ready should have been
>> created as a manual-reset event, and that more care is needed to make sure
>> it's set when it should be.
>>
>>> I could provide a code-snippet
>>> to reproduce it if wanted ?
>>
>> Yes, please!
>
> That might not be necessary. If you're able to build the git repo master
> branch, please try the attached patch.
Here's a better patch.
Ken
-------------- next part --------------
>From 3efd5a8cbff8d48b8cf9807070134bb79f591b7d Mon Sep 17 00:00:00 2001
From: Ken Brown <kbrown@cornell.edu>
Date: Thu, 26 Mar 2020 19:02:16 -0400
Subject: [PATCH] Cygwin: FIFO: fix a problem opening nonblocking writers
Make read_ready a manual-reset event. Previously, when it was an
auto-reset event, there was a brief period when read_ready was not set
after a writer opened. An attempt to open a second writer during this
period would fail with ENXIO if O_NONBLOCK was set, even if a reader
was open.
For the same reason, move ResetEvent(read_ready) from
listen_client_thread() to close().
Addresses: https://sourceware.org/pipermail/cygwin/2020-March/244201.html
---
winsup/cygwin/fhandler_fifo.cc | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index 19cd0e507..c7e27e883 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -463,7 +463,6 @@ fhandler_fifo::listen_client_thread ()
out:
if (evt)
CloseHandle (evt);
- ResetEvent (read_ready);
if (ret < 0)
debug_printf ("exiting with error, %E");
else
@@ -516,7 +515,7 @@ fhandler_fifo::open (int flags, mode_t)
char npbuf[MAX_PATH];
__small_sprintf (npbuf, "r-event.%08x.%016X", get_dev (), get_ino ());
- if (!(read_ready = CreateEvent (sa_buf, false, false, npbuf)))
+ if (!(read_ready = CreateEvent (sa_buf, true, false, npbuf)))
{
debug_printf ("CreateEvent for %s failed, %E", npbuf);
res = error_set_errno;
@@ -1016,6 +1015,8 @@ fhandler_fifo::close ()
handler or another thread. */
fifo_client_unlock ();
int ret = stop_listen_client ();
+ if (reader && read_ready)
+ ResetEvent (read_ready);
if (read_ready)
CloseHandle (read_ready);
if (write_ready)
--
2.21.0
More information about the Cygwin
mailing list