public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH 0/4] Some fixes for pty.
@ 2020-05-31  5:53 Takashi Yano
  2020-05-31  5:53 ` [PATCH 1/4] Cygwin: pty: Prevent garbage remained in read ahead buffer Takashi Yano
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Takashi Yano @ 2020-05-31  5:53 UTC (permalink / raw)
  To: cygwin-patches

Patches for https://cygwin.com/pipermail/cygwin/2020-May/245057.html
and three other issues that were noticed during this fix.

Takashi Yano (4):
  Cygwin: pty: Prevent garbage remained in read ahead buffer.
  Cygwin: console: Discard some unsupported escape sequences.
  Cygwin: pty: Clean up fhandler_pty_master::pty_master_fwd_thread().
  Cygwin: pty: Revise the code which prevents undesired window title.

 winsup/cygwin/fhandler.h          |  3 +-
 winsup/cygwin/fhandler_console.cc | 54 ++++++++++++++++++++++---------
 winsup/cygwin/fhandler_tty.cc     | 41 +++++++++++------------
 3 files changed, 59 insertions(+), 39 deletions(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] Cygwin: pty: Prevent garbage remained in read ahead buffer.
  2020-05-31  5:53 [PATCH 0/4] Some fixes for pty Takashi Yano
@ 2020-05-31  5:53 ` Takashi Yano
  2020-05-31  5:53 ` [PATCH 2/4] Cygwin: console: Discard some unsupported escape sequences Takashi Yano
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Takashi Yano @ 2020-05-31  5:53 UTC (permalink / raw)
  To: cygwin-patches

- 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.
---
 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;
-- 
2.26.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/4] Cygwin: console: Discard some unsupported escape sequences.
  2020-05-31  5:53 [PATCH 0/4] Some fixes for pty Takashi Yano
  2020-05-31  5:53 ` [PATCH 1/4] Cygwin: pty: Prevent garbage remained in read ahead buffer Takashi Yano
@ 2020-05-31  5:53 ` Takashi Yano
  2020-05-31  5:53 ` [PATCH 3/4] Cygwin: pty: Clean up fhandler_pty_master::pty_master_fwd_thread() Takashi Yano
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Takashi Yano @ 2020-05-31  5:53 UTC (permalink / raw)
  To: cygwin-patches

- If the cygwin vim is started from a non-cygwin process which is
  executed in pseudo console, shift key and ctrl key do not work.
  In this case, vim is executed under /dev/cons*. If vim outputs
  escape sequence which is not supported by pseudo console, the
  escape sequence is leaked into the parent pty. This causes
  unexpected results. This patch fixes the issue by discarding
  "CSI > Pm m". "OSC 10;? BEL/ST" and "OSC 11;? BEL/ST" are
  discarded as well.
---
 winsup/cygwin/fhandler_console.cc | 54 ++++++++++++++++++++++---------
 1 file changed, 38 insertions(+), 16 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 5cb4343ea..dd979fb8e 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -2186,6 +2186,14 @@ fhandler_console::char_command (char c)
 	  /* Just send the sequence */
 	  wpbuf.send (get_output_handle ());
 	  break;
+	case 'm':
+	  if (con.saw_greater_than_sign)
+	    break; /* Ignore unsupported CSI > Pm m */
+	  /* Text attribute settings */
+	  wpbuf.put (c);
+	  /* Just send the sequence */
+	  wpbuf.send (get_output_handle ());
+	  break;
 	default:
 	  /* Other escape sequences */
 	  wpbuf.put (c);
@@ -3077,6 +3085,13 @@ fhandler_console::write (const void *vsrc, size_t len)
 	      con.state = normal;
 	      wpbuf.empty();
 	    }
+	  else if (*src == ']')		/* OSC Operating System Command */
+	    {
+	      wpbuf.put (*src);
+	      con.rarg = 0;
+	      con.my_title_buf[0] = '\0';
+	      con.state = gotrsquare;
+	    }
 	  else if (wincap.has_con_24bit_colors () && !con_is_legacy)
 	    {
 	      if (*src == 'c') /* RIS Full reset */
@@ -3095,13 +3110,6 @@ fhandler_console::write (const void *vsrc, size_t len)
 	      con.state = normal;
 	      wpbuf.empty();
 	    }
-	  else if (*src == ']')		/* OSC Operating System Command */
-	    {
-	      wpbuf.put (*src);
-	      con.rarg = 0;
-	      con.my_title_buf[0] = '\0';
-	      con.state = gotrsquare;
-	    }
 	  else if (*src == '(')		/* Designate G0 character set */
 	    {
 	      wpbuf.put (*src);
@@ -3179,7 +3187,8 @@ fhandler_console::write (const void *vsrc, size_t len)
 	    con.rarg = con.rarg * 10 + (*src - '0');
 	  else if (*src == ';' && (con.rarg == 2 || con.rarg == 0))
 	    con.state = gettitle;
-	  else if (*src == ';' && (con.rarg == 4 || con.rarg == 104))
+	  else if (*src == ';' && (con.rarg == 4 || con.rarg == 104
+				   || (con.rarg >= 10 && con.rarg <= 19)))
 	    con.state = eatpalette;
 	  else
 	    con.state = eattitle;
@@ -3189,10 +3198,13 @@ fhandler_console::write (const void *vsrc, size_t len)
 	case eattitle:
 	case gettitle:
 	  {
+	    wpbuf.put (*src);
 	    int n = strlen (con.my_title_buf);
 	    if (*src < ' ')
 	      {
-		if (*src == '\007' && con.state == gettitle)
+		if (wincap.has_con_24bit_colors () && !con_is_legacy)
+		  wpbuf.send (get_output_handle ());
+		else if (*src == '\007' && con.state == gettitle)
 		  set_console_title (con.my_title_buf);
 		con.state = normal;
 		wpbuf.empty();
@@ -3201,27 +3213,37 @@ fhandler_console::write (const void *vsrc, size_t len)
 	      {
 		con.my_title_buf[n++] = *src;
 		con.my_title_buf[n] = '\0';
-		wpbuf.put (*src);
 	      }
 	    src++;
 	    break;
 	  }
 	case eatpalette:
-	  if (*src == '\033')
-	    {
-	      wpbuf.put (*src);
-	      con.state = endpalette;
-	    }
+	  wpbuf.put (*src);
+	  if (*src == '?')
+	    con.saw_question_mark = true;
+	  else if (*src == '\033')
+	    con.state = endpalette;
 	  else if (*src == '\a')
 	    {
+	      /* Send OSC Ps; Pt BEL other than OSC Ps; ? BEL */
+	      if (wincap.has_con_24bit_colors () && !con_is_legacy
+		  && !con.saw_question_mark)
+		wpbuf.send (get_output_handle ());
 	      con.state = normal;
 	      wpbuf.empty();
 	    }
 	  src++;
 	  break;
 	case endpalette:
+	  wpbuf.put (*src);
 	  if (*src == '\\')
-	    con.state = normal;
+	    {
+	      /* Send OSC Ps; Pt ST other than OSC Ps; ? ST */
+	      if (wincap.has_con_24bit_colors () && !con_is_legacy
+		  && !con.saw_question_mark)
+		wpbuf.send (get_output_handle ());
+	      con.state = normal;
+	    }
 	  else
 	    /* Sequence error (abort) */
 	    con.state = normal;
-- 
2.26.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/4] Cygwin: pty: Clean up fhandler_pty_master::pty_master_fwd_thread().
  2020-05-31  5:53 [PATCH 0/4] Some fixes for pty Takashi Yano
  2020-05-31  5:53 ` [PATCH 1/4] Cygwin: pty: Prevent garbage remained in read ahead buffer Takashi Yano
  2020-05-31  5:53 ` [PATCH 2/4] Cygwin: console: Discard some unsupported escape sequences Takashi Yano
@ 2020-05-31  5:53 ` Takashi Yano
  2020-05-31  5:53 ` [PATCH 4/4] Cygwin: pty: Revise the code which prevents undesired window title Takashi Yano
  2020-05-31  8:40 ` [PATCH 0/4] Some fixes for pty Corinna Vinschen
  4 siblings, 0 replies; 6+ messages in thread
From: Takashi Yano @ 2020-05-31  5:53 UTC (permalink / raw)
  To: cygwin-patches

- Remove the code which is not necessary anymore.
---
 winsup/cygwin/fhandler_tty.cc | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index d017cde38..c3d49968d 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -3324,24 +3324,6 @@ fhandler_pty_master::pty_master_fwd_thread ()
 		continue;
 	      }
 
-	  /* Remove ESC sequence which returns results to console
-	     input buffer. Without this, cursor position report
-	     is put into the input buffer as a garbage. */
-	  /* Remove ESC sequence to report cursor position. */
-	  char *p0;
-	  while ((p0 = (char *) memmem (outbuf, rlen, "\033[6n", 4)))
-	    {
-	      memmove (p0, p0+4, rlen - (p0+4 - outbuf));
-	      rlen -= 4;
-	    }
-	  /* Remove ESC sequence to report terminal identity. */
-	  while ((p0 = (char *) memmem (outbuf, rlen, "\033[0c", 4)))
-	    {
-	      memmove (p0, p0+4, rlen - (p0+4 - outbuf));
-	      rlen -= 4;
-	    }
-	  wlen = rlen;
-
 	  size_t nlen;
 	  char *buf = convert_mb_str
 	    (get_ttyp ()->term_code_page, &nlen, CP_UTF8, ptr, wlen);
-- 
2.26.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/4] Cygwin: pty: Revise the code which prevents undesired window title.
  2020-05-31  5:53 [PATCH 0/4] Some fixes for pty Takashi Yano
                   ` (2 preceding siblings ...)
  2020-05-31  5:53 ` [PATCH 3/4] Cygwin: pty: Clean up fhandler_pty_master::pty_master_fwd_thread() Takashi Yano
@ 2020-05-31  5:53 ` Takashi Yano
  2020-05-31  8:40 ` [PATCH 0/4] Some fixes for pty Corinna Vinschen
  4 siblings, 0 replies; 6+ messages in thread
From: Takashi Yano @ 2020-05-31  5:53 UTC (permalink / raw)
  To: cygwin-patches

- In current pty, the window title can not be set from non-cygwin
  program due to the code which prevents overwriting the window
  title to "cygwin-console-helper.exe" in fhandler_pty_master::pty_
  master_fwd_thread(). This patch fixes the issue.
---
 winsup/cygwin/fhandler_tty.cc | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index c3d49968d..e434b7878 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -3313,9 +3313,14 @@ fhandler_pty_master::pty_master_fwd_thread ()
 	      }
 	    else if (state == 4 && outbuf[i] == '\a')
 	      {
-		memmove (&outbuf[start_at], &outbuf[i+1], rlen-i-1);
+		const char *helper_str = "\\bin\\cygwin-console-helper.exe";
+		if (memmem (&outbuf[start_at], i + 1 - start_at,
+			    helper_str, strlen (helper_str)))
+		  {
+		    memmove (&outbuf[start_at], &outbuf[i+1], rlen-i-1);
+		    rlen = wlen = start_at + rlen - i - 1;
+		  }
 		state = 0;
-		rlen = wlen = start_at + rlen - i - 1;
 		continue;
 	      }
 	    else if (outbuf[i] == '\a')
-- 
2.26.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] Some fixes for pty.
  2020-05-31  5:53 [PATCH 0/4] Some fixes for pty Takashi Yano
                   ` (3 preceding siblings ...)
  2020-05-31  5:53 ` [PATCH 4/4] Cygwin: pty: Revise the code which prevents undesired window title Takashi Yano
@ 2020-05-31  8:40 ` Corinna Vinschen
  4 siblings, 0 replies; 6+ messages in thread
From: Corinna Vinschen @ 2020-05-31  8:40 UTC (permalink / raw)
  To: cygwin-patches

On May 31 14:53, Takashi Yano via Cygwin-patches wrote:
> Patches for https://cygwin.com/pipermail/cygwin/2020-May/245057.html
> and three other issues that were noticed during this fix.
> 
> Takashi Yano (4):
>   Cygwin: pty: Prevent garbage remained in read ahead buffer.
>   Cygwin: console: Discard some unsupported escape sequences.
>   Cygwin: pty: Clean up fhandler_pty_master::pty_master_fwd_thread().
>   Cygwin: pty: Revise the code which prevents undesired window title.
> 
>  winsup/cygwin/fhandler.h          |  3 +-
>  winsup/cygwin/fhandler_console.cc | 54 ++++++++++++++++++++++---------
>  winsup/cygwin/fhandler_tty.cc     | 41 +++++++++++------------
>  3 files changed, 59 insertions(+), 39 deletions(-)
> 
> -- 
> 2.26.2

Pushed.

I'm going to create a developer snapshot for testing right now, should
take just a few minutes.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-05-31  8:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-31  5:53 [PATCH 0/4] Some fixes for pty Takashi Yano
2020-05-31  5:53 ` [PATCH 1/4] Cygwin: pty: Prevent garbage remained in read ahead buffer Takashi Yano
2020-05-31  5:53 ` [PATCH 2/4] Cygwin: console: Discard some unsupported escape sequences Takashi Yano
2020-05-31  5:53 ` [PATCH 3/4] Cygwin: pty: Clean up fhandler_pty_master::pty_master_fwd_thread() Takashi Yano
2020-05-31  5:53 ` [PATCH 4/4] Cygwin: pty: Revise the code which prevents undesired window title Takashi Yano
2020-05-31  8:40 ` [PATCH 0/4] Some fixes for pty Corinna Vinschen

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).