[PATCH] Cygwin: pty: Use consistently first pty slave found in cygheap_fdenum

Johannes Schindelin Johannes.Schindelin@gmx.de
Sat Mar 7 08:27:17 GMT 2026


Hi Takashi,

On Sat, 28 Feb 2026, Takashi Yano wrote:

> If non-cygwin app is started in GDB and terminating it normally,
> re-running the non-cygwin app might fail in setup_pseudoconsole().

Could you paste the exact symptom into the commit message? That might help
readers like myself understand better what motivated/necessitated this
patch.

> This is because set_switch_to_nat_pipe() uses the last pty slave
> instance found in cygheap_fdenum while the clearnup uses the first
> pty salve.
> 
> With this patch, the first pty slave instance in cygheap_fdenum is
> used for setup and cleanup consistently.

That explanation makes sense to me. What I struggle with is to connect
this explanation with the change in the diff: an added `ptys == NULL`
condition in `set_switch_to_nat_pipe()`, which does not look related to
first vs last pty slave nor to setup/cleanup.

Maybe the commit message could be improved to help readers understand the
connection?

Thanks,
Johannes

> 
> Fixes: f20641789427 ("Cygwin: pty: Reduce unecessary input transfer.")
> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
> Reviewed-by:
> ---
>  winsup/cygwin/fhandler/pty.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
> index 663b0068a..d4b2896e1 100644
> --- a/winsup/cygwin/fhandler/pty.cc
> +++ b/winsup/cygwin/fhandler/pty.cc
> @@ -105,7 +105,7 @@ set_switch_to_nat_pipe (HANDLE *in, HANDLE *out, HANDLE *err)
>        if (*err == cfd->get_output_handle () ||
>  	  (fd == 2 && *err == GetStdHandle (STD_ERROR_HANDLE)))
>  	replace_err = (fhandler_base *) cfd;
> -      if (cfd->get_device () == (dev_t) myself->ctty)
> +      if (ptys == NULL && cfd->get_device () == (dev_t) myself->ctty)
>  	{
>  	  fhandler_base *fh = cfd;
>  	  if (*in == fh->get_handle ()
> -- 
> 2.51.0
> 
> 


More information about the Cygwin-patches mailing list