Hi Takashi,

On Aug 26 21:00, Takashi Yano via Cygwin-patches wrote:
> 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

Would you mind to encapsulate the TERM checks into a fhandler_pty_slave
method so the TERM specific stuff is done in the fhandler code, not
in spawn.cc?


Thanks,
Corinna

Reply via email to