Cygwin: pty: Prevent garbage remained in read ahead buffer.

- After commit 29431fcb5b, the issue
  reported in https://cygwin.com/pipermail/cygwin/2020-May/245057.html
  occurs. This is caused by the following mechanism. Cygwin less
  called from non-cygwin git is executed under /dev/cons* rather
  than /dev/pty* because parent git process only inherits pseudo
  console handle. Therefore, less sets ICANON flag for /dev/cons*
  rather than original /dev/pty*. When pty is switched to non-cygwin
  git process, line_edit() is used in fhandler_pty_master::write()
  only to set input_available_event and read ahead buffer is supposed
  to be flushed in accept_input(). However, ICANON flag is not set
  for /dev/pty*, so accept_input() is not called unless newline
  is entered. As a result, the input data remains in the read ahead
  buffer. This patch fixes the issue.
This commit is contained in:
Takashi Yano via Cygwin-patches
2020-05-31 14:53:17 +09:00
committed by Corinna Vinschen
parent d6242d8733
commit 0f7193f4fb
2 changed files with 14 additions and 3 deletions

View File

@@ -532,6 +532,14 @@ fhandler_pty_master::doecho (const void *str, DWORD len)
release_output_mutex ();
}
int
fhandler_pty_master::put_readahead (char value)
{
if (to_be_read_from_pcon ())
return 1;
return fhandler_base::put_readahead (value);
}
int
fhandler_pty_master::accept_input ()
{
@@ -542,12 +550,14 @@ fhandler_pty_master::accept_input ()
bytes_left = eat_readahead (-1);
if (!bytes_left)
if (to_be_read_from_pcon ())
; /* Do nothing */
else if (!bytes_left)
{
termios_printf ("sending EOF to slave");
get_ttyp ()->read_retval = 0;
}
else if (!to_be_read_from_pcon ())
else
{
char *p = rabuf ();
DWORD rc;