public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pty: Prevent garbage remained in read ahead buffer. Date: Sun, 31 May 2020 08:39:15 +0000 (GMT) [thread overview] Message-ID: <20200531083915.EB4AC3851C09@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=0f7193f4fbbfdde52fe21639ca582a32a63eb851 commit 0f7193f4fbbfdde52fe21639ca582a32a63eb851 Author: Takashi Yano via Cygwin-patches <cygwin-patches@cygwin.com> Date: Sun May 31 14:53:17 2020 +0900 Cygwin: pty: Prevent garbage remained in read ahead buffer. - After commit 29431fcb5b14d4c5ac3b3161a076eb1a208349d9, 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. Diff: --- winsup/cygwin/fhandler.h | 3 ++- winsup/cygwin/fhandler_tty.cc | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index b2957e4ee..4035c7e56 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -328,7 +328,7 @@ class fhandler_base virtual bool get_readahead_valid () { return raixget () < ralen (); } int puts_readahead (const char *s, size_t len = (size_t) -1); - int put_readahead (char value); + virtual int put_readahead (char value); int get_readahead (); int peek_readahead (int queryput = 0); @@ -2381,6 +2381,7 @@ public: int process_slave_output (char *buf, size_t len, int pktmode_on); void doecho (const void *str, DWORD len); int accept_input (); + int put_readahead (char value); int open (int flags, mode_t mode = 0); void open_setup (int flags); ssize_t __stdcall write (const void *ptr, size_t len); diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index b091765b3..d017cde38 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -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;
reply other threads:[~2020-05-31 8:39 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20200531083915.EB4AC3851C09@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /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: linkBe 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).