[newlib-cygwin] Cygwin: pty: Fix cursor position on new nat app in existing pcon

Takashi Yano via Cygwin-cvs <[email protected]> Mon, 3 Aug 2026 02:46:05 +0000 (GMT)
Newsgroups gmane.os.cygwin.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D9e2f67d8b4a=
d7f229dc0e8d3e74f00a07ec0952e

commit 9e2f67d8b4ad7f229dc0e8d3e74f00a07ec0952e
Author: Takashi Yano <[email protected]>
Date:   Tue Jul 21 04:59:09 2026 +0900

    Cygwin: pty: Fix cursor position on new nat app in existing pcon
   =20
    Previously, the steps: cmd.exe -> bash -> cmd.exe exhibit broken
    cursor position even with the commit b34394d456b6 ("Cygwin: pty:
    Fixup pty state after a cygwin app exits").
   =20
    This patch sets req_fixup_pcon_cur_pos also when reusing existing
    pseudo console as well as req_xfer_input. In addition, clearing
    `pcon_start_pid` has been moved inside `input_mutex`, to addess
    the race condition that becomes harmfull with this patch.
   =20
    Signed-off-by: Takashi Yano <[email protected]>
    Reviewed-by: Johannes Schindelin <[email protected]>

Diff:
---
 winsup/cygwin/fhandler/pty.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index f3df55f34..6d8f6d5c1 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -2671,8 +2671,8 @@ fhandler_pty_master::write (const void *ptr, size_t l=
en)
 	      release_attach_mutex ();
 	    }
 	  get_ttyp ()->req_xfer_input =3D false;
-	  ReleaseMutex (input_mutex);
 	  get_ttyp ()->pcon_start_pid =3D 0;
+	  ReleaseMutex (input_mutex);
 	}
       if (len =3D=3D 0)
 	return orig_len;
@@ -3850,6 +3850,7 @@ fhandler_pty_slave::setup_pseudoconsole ()
 	  WaitForSingleObject (input_mutex, mutex_timeout);
 	  get_ttyp ()->req_xfer_input =3D true; /* indicates that this "ESC[6n"
 						 is just for transfer input */
+	  get_ttyp ()->req_fixup_pcon_cur_pos =3D true;
 	  get_ttyp ()->pcon_start =3D true;
 	  get_ttyp ()->pcon_start_pid =3D myself->pid;
 	  WriteFile (get_output_handle (), "\033[6n", 4, &n, NULL);