[PATCH v2 3/3] Cygwin: pty: Clear input_available_event if pipe is empty on close.

Takashi Yano takashi.yano@nifty.ne.jp
Sun Mar 21 23:26:47 GMT 2021


- If apps read input from get_handle_cyg() directly by ReadFile(),
  input_available_event may remains signalled. This patch clears
  input_available_event if the pipe is empty on closing pty slave.
---
 winsup/cygwin/fhandler_tty.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 682264130..43e83b807 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -982,6 +982,9 @@ fhandler_pty_slave::close ()
   termios_printf ("closing last open %s handle", ttyname ());
   if (inuse && !CloseHandle (inuse))
     termios_printf ("CloseHandle (inuse), %E");
+  DWORD n;
+  if (bytes_available (n) && !n)
+    ResetEvent (input_available_event);
   if (!ForceCloseHandle (input_available_event))
     termios_printf ("CloseHandle (input_available_event<%p>), %E", input_available_event);
   if (!ForceCloseHandle (get_output_handle_cyg ()))
-- 
2.30.2



More information about the Cygwin-patches mailing list