public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: pty: Disable pseudo console if TERM is dumb or not set.
@ 2020-08-26 12:00 Takashi Yano
  2020-08-26 17:36 ` Corinna Vinschen
  2020-08-28 13:45 ` Corinna Vinschen
  0 siblings, 2 replies; 18+ messages in thread
From: Takashi Yano @ 2020-08-26 12:00 UTC (permalink / raw)
  To: cygwin-patches

Pseudo console generates escape sequences on execution of non-cygwin
apps.  If the terminal does not support escape sequence, output will
be garbled. This patch prevents garbled output in dumb terminal by
disabling pseudo console.
---
 winsup/cygwin/spawn.cc | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 8308bccf3..b6d58e97a 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -647,13 +647,35 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
       ZeroMemory (&si_pcon, sizeof (si_pcon));
       STARTUPINFOW *si_tmp = &si;
       if (!iscygwin () && ptys_primary && is_console_app (runpath))
-	if (ptys_primary->setup_pseudoconsole (&si_pcon,
-			     mode != _P_OVERLAY && mode != _P_WAIT))
-	  {
-	    c_flags |= EXTENDED_STARTUPINFO_PRESENT;
-	    si_tmp = &si_pcon.StartupInfo;
-	    enable_pcon = true;
-	  }
+	{
+	  bool nopcon = mode != _P_OVERLAY && mode != _P_WAIT;
+	  /* If TERM is "dumb" or not set, disable pseudo console */
+	  if (envblock)
+	    {
+	      bool term_is_set = false;
+	      for (PWCHAR p = envblock; *p != L'\0'; p += wcslen (p) + 1)
+		{
+		  if (wcscmp (p, L"TERM=dumb") == 0)
+		    nopcon = true;
+		  if (wcsncmp (p, L"TERM=", 5) == 0)
+		    term_is_set = true;
+		}
+	      if (!term_is_set)
+		nopcon = true;
+	    }
+	  else
+	    {
+	      const char *term = getenv ("TERM");
+	      if (!term || strcmp (term, "dumb") == 0)
+		nopcon = true;
+	    }
+	  if (ptys_primary->setup_pseudoconsole (&si_pcon, nopcon))
+	    {
+	      c_flags |= EXTENDED_STARTUPINFO_PRESENT;
+	      si_tmp = &si_pcon.StartupInfo;
+	      enable_pcon = true;
+	    }
+	}
 
     loop:
       /* When ruid != euid we create the new process under the current original
-- 
2.28.0


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

end of thread, other threads:[~2020-08-31  9:48 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-26 12:00 [PATCH] Cygwin: pty: Disable pseudo console if TERM is dumb or not set Takashi Yano
2020-08-26 17:36 ` Corinna Vinschen
2020-08-27  4:07   ` Takashi Yano
2020-08-27  8:47     ` Corinna Vinschen
2020-08-27  8:59       ` Takashi Yano
2020-08-27  9:05         ` Corinna Vinschen
2020-08-28 13:45 ` Corinna Vinschen
2020-08-28 19:25   ` Takashi Yano
2020-08-29 11:12     ` Takashi Yano
2020-08-29 13:14       ` Takashi Yano
2020-08-29 20:25         ` Takashi Yano
2020-08-29 21:13           ` Takashi Yano
2020-08-30  7:42             ` Takashi Yano
2020-08-30  7:58               ` Takashi Yano
2020-08-30 12:49       ` Corinna Vinschen
2020-08-31  3:26         ` Takashi Yano
2020-08-31  8:16           ` Corinna Vinschen
2020-08-31  9:47             ` Takashi Yano

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