From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 4922A385800C; Fri, 4 Mar 2022 13:37:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4922A385800C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pty: Update some comments in pty code. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: bb98c26e168bdd407ac6a67abd72d4d40186662c X-Git-Newrev: 3d46583d4fa89f1c188bb169da939d769765bc67 Message-Id: <20220304133738.4922A385800C@sourceware.org> Date: Fri, 4 Mar 2022 13:37:38 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2022 13:37:38 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D3d46583d4fa= 89f1c188bb169da939d769765bc67 commit 3d46583d4fa89f1c188bb169da939d769765bc67 Author: Takashi Yano Date: Fri Mar 4 22:00:24 2022 +0900 Cygwin: pty: Update some comments in pty code. Diff: --- winsup/cygwin/fhandler_tty.cc | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index a0a5a70ba..cba25ee84 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -525,8 +525,11 @@ fhandler_pty_master::accept_input () if (to_be_read_from_nat_pipe () && get_ttyp ()->pty_input_state =3D=3D tty::to_nat) { - write_to =3D to_slave_nat; + /* This code is reached if non-cygwin app is foreground and + pseudo console is not enabled. */ + write_to =3D to_slave_nat; /* write to nat pipe rather than cyg pipe= . */ =20 + /* Charset conversion for non-cygwin apps. */ UINT cp_to; pinfo pinfo_target =3D pinfo (get_ttyp ()->invisible_console_pid); DWORD target_pid =3D 0; @@ -607,7 +610,8 @@ fhandler_pty_master::accept_input () } =20 if (write_to =3D=3D get_output_handle ()) - SetEvent (input_available_event); + SetEvent (input_available_event); /* Set input_available_event only wh= en + the data is written to cyg pipe. */ ReleaseMutex (input_mutex); return ret; } @@ -1113,7 +1117,7 @@ nat_pipe_owner_self (DWORD pid) return (pid =3D=3D (myself->exec_dwProcessId ?: myself->dwProcessId)); } =20 -/* This function is called from many pty slave functions. The purpose +/* This function is called from some pty slave functions. The purpose of this function is cleaning up the nat pipe state which is marked as active but actually not used anymore. This is needed only when non-cygwin process is not terminated cleanly. */ @@ -1207,7 +1211,7 @@ fhandler_pty_slave::reset_switch_to_nat_pipe (void) } if (isHybrid) return; - if (get_ttyp ()->pcon_start) /* Pseudo console is initialization on goin= g */ + if (get_ttyp ()->pcon_start) /* Pseudo console initialization is on goin= g */ return; DWORD wait_ret =3D WaitForSingleObject (pipe_sw_mutex, mutex_timeout); if (wait_ret =3D=3D WAIT_TIMEOUT) @@ -2161,7 +2165,7 @@ fhandler_pty_master::write (const void *ptr, size_t l= en) push_process_state process_state (PID_TTYOU); =20 if (get_ttyp ()->pcon_start) - { + { /* Reaches here when pseudo console initialization is on going. */ /* Pseudo condole support uses "CSI6n" to get cursor position. If the reply for "CSI6n" is divided into multiple writes, pseudo console sometimes does not recognize it. Therefore, @@ -2201,6 +2205,9 @@ fhandler_pty_master::write (const void *ptr, size_t l= en) } if (state =3D=3D 2) { + /* req_xfer_input is true if "ESC[6n" was sent just for + triggering transfer_input() in master. In this case, + the responce sequence should not be written. */ if (!get_ttyp ()->req_xfer_input) WriteFile (to_slave_nat, wpbuf, ixput, &n, NULL); ixput =3D 0; @@ -2211,7 +2218,7 @@ fhandler_pty_master::write (const void *ptr, size_t l= en) ReleaseMutex (input_mutex); =20 if (!get_ttyp ()->pcon_start) - { + { /* Pseudo console initialization has been done in above code. */ pinfo pp (get_ttyp ()->pcon_start_pid); bool pcon_fg =3D (pp && get_ttyp ()->getpgid () =3D=3D pp->pgid); /* GDB may set WINPID rather than cygwin PID to process group @@ -2243,7 +2250,8 @@ fhandler_pty_master::write (const void *ptr, size_t l= en) WaitForSingleObject (input_mutex, mutex_timeout); if (to_be_read_from_nat_pipe () && get_ttyp ()->pcon_activated && get_ttyp ()->pty_input_state =3D=3D tty::to_nat) - { + { /* Reaches here when non-cygwin app is foreground and pseudo console + is activated. */ tmp_pathbuf tp; char *buf =3D (char *) ptr; size_t nlen =3D len; @@ -2277,6 +2285,10 @@ fhandler_pty_master::write (const void *ptr, size_t = len) return len; } =20 + /* The code path reaches here when pseudo console is not activated + or cygwin process is foreground even though pseudo console is + activated. */ + /* This input transfer is needed when cygwin-app which is started from non-cygwin app is terminated if pseudo console is disabled. */ if (to_be_read_from_nat_pipe () && !get_ttyp ()->pcon_activated @@ -3197,7 +3209,8 @@ fhandler_pty_slave::setup_pseudoconsole () { /* Send CSI6n just for requesting transfer input. */ DWORD n; WaitForSingleObject (input_mutex, mutex_timeout); - get_ttyp ()->req_xfer_input =3D true; + get_ttyp ()->req_xfer_input =3D true; /* indicates that this "ESC[6n" + is just for transfer input */ get_ttyp ()->pcon_start =3D true; get_ttyp ()->pcon_start_pid =3D myself->pid; WriteFile (get_output_handle (), "\033[6n", 4, &n, NULL);