From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 4BD1F3858422; Tue, 1 Mar 2022 13:23:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BD1F3858422 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: Rename some functions/variables with the name *pcon*. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 3e11a002b3eb78784190ebdd382ef3720afbb16a X-Git-Newrev: aec053c60c29da9df1740530923604ddc59dc36e Message-Id: <20220301132302.4BD1F3858422@sourceware.org> Date: Tue, 1 Mar 2022 13:23:02 +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: Tue, 01 Mar 2022 13:23:02 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Daec053c60c2= 9da9df1740530923604ddc59dc36e commit aec053c60c29da9df1740530923604ddc59dc36e Author: Takashi Yano Date: Tue Mar 1 22:09:01 2022 +0900 Cygwin: pty: Rename some functions/variables with the name *pcon*. =20 - With this patch, some pty functions/variables have been renamed so that the name *pcon* is not used for those that are called even when the pseudo console is not active. Diff: --- winsup/cygwin/fhandler.h | 14 +- winsup/cygwin/fhandler_tty.cc | 314 ++++++++++++++++++++++----------------= ---- winsup/cygwin/select.cc | 6 +- winsup/cygwin/tty.cc | 26 ++-- winsup/cygwin/tty.h | 22 +-- 5 files changed, 203 insertions(+), 179 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 919479948..dd1ab0422 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -2269,13 +2269,13 @@ class fhandler_pty_common: public fhandler_termios public: fhandler_pty_common () : fhandler_termios (), - output_mutex (NULL), input_mutex (NULL), pcon_mutex (NULL), + output_mutex (NULL), input_mutex (NULL), pipe_sw_mutex (NULL), input_available_event (NULL) { pc.file_attributes (FILE_ATTRIBUTE_NORMAL); } static const unsigned pipesize =3D 128 * 1024; - HANDLE output_mutex, input_mutex, pcon_mutex; + HANDLE output_mutex, input_mutex, pipe_sw_mutex; HANDLE input_available_event; =20 bool use_archetype () const {return true;} @@ -2311,7 +2311,7 @@ class fhandler_pty_common: public fhandler_termios static DWORD get_console_process_id (DWORD pid, bool match, bool cygwin =3D false, bool stub_only =3D false); - bool to_be_read_from_pcon (void); + bool to_be_read_from_nat_pipe (void); =20 protected: static BOOL process_opost_output (HANDLE h, const void *ptr, ssize_t& le= n, @@ -2337,7 +2337,7 @@ class fhandler_pty_slave: public fhandler_pty_common HANDLE from_master_nat; HANDLE input_available_event; HANDLE input_mutex; - HANDLE pcon_mutex; + HANDLE pipe_sw_mutex; }; =20 /* Constructor */ @@ -2394,9 +2394,9 @@ class fhandler_pty_slave: public fhandler_pty_common static void close_pseudoconsole (tty *ttyp, DWORD force_switch_to =3D 0); static void hand_over_only (tty *ttyp, DWORD force_switch_to =3D 0); bool term_has_pcon_cap (const WCHAR *env); - void set_switch_to_pcon (void); - void reset_switch_to_pcon (void); - void mask_switch_to_pcon_in (bool mask, bool xfer); + void set_switch_to_nat_pipe (void); + void reset_switch_to_nat_pipe (void); + void mask_switch_to_nat_pipe (bool mask, bool xfer); void setup_locale (void); void create_invisible_console (void); static void transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp, diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 3d74f9a0c..673f4167a 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -48,6 +48,8 @@ struct pipe_request { DWORD pid; }; =20 +/* The name *nat* comes from 'native' which means non-cygwin + (native windows). They are used for non-cygwin process. */ struct pipe_reply { HANDLE from_master_nat; HANDLE from_master; @@ -74,7 +76,7 @@ void release_attach_mutex (void) ReleaseMutex (attach_mutex); } =20 -inline static bool pcon_pid_alive (DWORD pid); +inline static bool nat_pipe_owner_alive (DWORD pid); =20 DWORD fhandler_pty_common::get_console_process_id (DWORD pid, bool match, @@ -107,7 +109,7 @@ fhandler_pty_common::get_console_process_id (DWORD pid,= bool match, res_pri =3D stub_only ? p->exec_dwProcessId : list[i]; break; } - if (!p && !res && pcon_pid_alive (list[i]) && stub_only) + if (!p && !res && nat_pipe_owner_alive (list[i]) && stub_only) res =3D list[i]; if (!!p && !res && !stub_only) res =3D list[i]; @@ -116,16 +118,17 @@ fhandler_pty_common::get_console_process_id (DWORD pi= d, bool match, return res_pri ?: res; } =20 -static bool isHybrid; -static HANDLE h_gdb_process; +static bool isHybrid; /* Set true if the active pipe is set to nat pipe ev= en + though the current process is a cygwin process. */ +static HANDLE h_gdb_inferior; /* Handle of GDB inferior process. */ =20 static void -set_switch_to_pcon (HANDLE *in, HANDLE *out, HANDLE *err, bool iscygwin) +set_switch_to_nat_pipe (HANDLE *in, HANDLE *out, HANDLE *err, bool iscygwi= n) { cygheap_fdenum cfd (false); int fd; fhandler_base *replace_in =3D NULL, *replace_out =3D NULL, *replace_err = =3D NULL; - fhandler_pty_slave *ptys_pcon =3D NULL; + fhandler_pty_slave *ptys_nat =3D NULL; while ((fd =3D cfd.next ()) >=3D 0) { if (*in =3D=3D cfd->get_handle () || @@ -144,11 +147,11 @@ set_switch_to_pcon (HANDLE *in, HANDLE *out, HANDLE *= err, bool iscygwin) if (*in =3D=3D ptys->get_handle () || *out =3D=3D ptys->get_output_handle () || *err =3D=3D ptys->get_output_handle ()) - ptys_pcon =3D ptys; + ptys_nat =3D ptys; } } - if (!iscygwin && ptys_pcon) - ptys_pcon->set_switch_to_pcon (); + if (!iscygwin && ptys_nat) + ptys_nat->set_switch_to_nat_pipe (); if (replace_in) *in =3D replace_in->get_handle_nat (); if (replace_out) @@ -230,9 +233,9 @@ atexit_func (void) if (cfd->get_device () =3D=3D (dev_t) myself->ctty) { DWORD force_switch_to =3D 0; - if (WaitForSingleObject (h_gdb_process, 0) =3D=3D WAIT_TIMEOUT + if (WaitForSingleObject (h_gdb_inferior, 0) =3D=3D WAIT_TIMEOUT && !debug_process) - force_switch_to =3D GetProcessId (h_gdb_process); + force_switch_to =3D GetProcessId (h_gdb_inferior); fhandler_base *fh =3D cfd; fhandler_pty_slave *ptys =3D (fhandler_pty_slave *) fh; tty *ttyp =3D (tty *) ptys->tc (); @@ -243,14 +246,14 @@ atexit_func (void) ptys->get_handle_nat (), ptys->get_input_available_event (), ptys->input_mutex, - ptys->pcon_mutex + ptys->pipe_sw_mutex }; fhandler_pty_slave::cleanup_for_non_cygwin_app (&handles, ttyp, stdin_is_ptys, force_switch_to); break; } - CloseHandle (h_gdb_process); + CloseHandle (h_gdb_inferior); } } =20 @@ -279,12 +282,12 @@ CreateProcessA_Hooked siov->hStdError =3D GetStdHandle (STD_ERROR_HANDLE); } bool path_iscygexec =3D fhandler_termios::path_iscygexec_a (n, c); - set_switch_to_pcon (&siov->hStdInput, &siov->hStdOutput, &siov->hStdErro= r, - path_iscygexec); + set_switch_to_nat_pipe (&siov->hStdInput, &siov->hStdOutput, + &siov->hStdError, path_iscygexec); BOOL ret =3D CreateProcessA_Orig (n, c, pa, ta, inh, f, e, d, siov, pi); - h_gdb_process =3D pi->hProcess; - DuplicateHandle (GetCurrentProcess (), h_gdb_process, - GetCurrentProcess (), &h_gdb_process, + h_gdb_inferior =3D pi->hProcess; + DuplicateHandle (GetCurrentProcess (), h_gdb_inferior, + GetCurrentProcess (), &h_gdb_inferior, 0, 0, DUPLICATE_SAME_ACCESS); debug_process =3D !!(f & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS)); if (debug_process) @@ -317,12 +320,12 @@ CreateProcessW_Hooked siov->hStdError =3D GetStdHandle (STD_ERROR_HANDLE); } bool path_iscygexec =3D fhandler_termios::path_iscygexec_w (n, c); - set_switch_to_pcon (&siov->hStdInput, &siov->hStdOutput, &siov->hStdErro= r, - path_iscygexec); + set_switch_to_nat_pipe (&siov->hStdInput, &siov->hStdOutput, + &siov->hStdError, path_iscygexec); BOOL ret =3D CreateProcessW_Orig (n, c, pa, ta, inh, f, e, d, siov, pi); - h_gdb_process =3D pi->hProcess; - DuplicateHandle (GetCurrentProcess (), h_gdb_process, - GetCurrentProcess (), &h_gdb_process, + h_gdb_inferior =3D pi->hProcess; + DuplicateHandle (GetCurrentProcess (), h_gdb_inferior, + GetCurrentProcess (), &h_gdb_inferior, 0, 0, DUPLICATE_SAME_ACCESS); debug_process =3D !!(f & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS)); if (debug_process) @@ -519,8 +522,8 @@ fhandler_pty_master::accept_input () =20 HANDLE write_to =3D get_output_handle (); tmp_pathbuf tp; - if (to_be_read_from_pcon () - && get_ttyp ()->pcon_input_state =3D=3D tty::to_nat) + if (to_be_read_from_nat_pipe () + && get_ttyp ()->pty_input_state =3D=3D tty::to_nat) { write_to =3D to_slave_nat; =20 @@ -776,7 +779,7 @@ fhandler_pty_slave::open (int flags, mode_t) { &from_master_nat_local, &input_available_event, &input_mutex, &inuse, &output_mutex, &to_master_nat_local, &pty_owner, &to_master_local, - &from_master_local, &pcon_mutex, + &from_master_local, &pipe_sw_mutex, NULL }; =20 @@ -804,9 +807,10 @@ fhandler_pty_slave::open (int flags, mode_t) errmsg =3D "open input mutex failed, %E"; goto err; } - if (!(pcon_mutex =3D get_ttyp ()->open_mutex (PCON_MUTEX, MAXIMUM_ALLOWE= D))) + if (!(pipe_sw_mutex + =3D get_ttyp ()->open_mutex (PIPE_SW_MUTEX, MAXIMUM_ALLOWED))) { - errmsg =3D "open pcon mutex failed, %E"; + errmsg =3D "open pipe switch mutex failed, %E"; goto err; } shared_name (buf, INPUT_AVAILABLE_EVENT, get_minor ()); @@ -1079,21 +1083,21 @@ fhandler_pty_slave::init (HANDLE h, DWORD a, mode_t) } =20 void -fhandler_pty_slave::set_switch_to_pcon (void) +fhandler_pty_slave::set_switch_to_nat_pipe (void) { if (!isHybrid) { isHybrid =3D true; setup_locale (); myself->exec_dwProcessId =3D myself->dwProcessId; - myself->process_state |=3D PID_NEW_PG; /* Marker for pcon_fg */ + myself->process_state |=3D PID_NEW_PG; /* Marker for nat_fg */ bool stdin_is_ptys =3D GetStdHandle (STD_INPUT_HANDLE) =3D=3D get_ha= ndle (); setup_for_non_cygwin_app (false, NULL, stdin_is_ptys); } } =20 inline static bool -pcon_pid_alive (DWORD pid) +nat_pipe_owner_alive (DWORD pid) { if (pid =3D=3D 0) return false; @@ -1109,31 +1113,35 @@ pcon_pid_alive (DWORD pid) } =20 inline static bool -pcon_pid_self (DWORD pid) +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 + 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. */ void -fhandler_pty_slave::reset_switch_to_pcon (void) +fhandler_pty_slave::reset_switch_to_nat_pipe (void) { - if (h_gdb_process) + if (h_gdb_inferior) { - if (WaitForSingleObject (h_gdb_process, 0) =3D=3D WAIT_TIMEOUT) + if (WaitForSingleObject (h_gdb_inferior, 0) =3D=3D WAIT_TIMEOUT) { if (isHybrid) - get_ttyp ()->wait_pcon_fwd (); + get_ttyp ()->wait_fwd (); } else { - CloseHandle (h_gdb_process); - h_gdb_process =3D NULL; + CloseHandle (h_gdb_inferior); + h_gdb_inferior =3D NULL; mutex_timeout =3D INFINITE; if (isHybrid) { if (get_ttyp ()->getpgid () =3D=3D myself->pgid && GetStdHandle (STD_INPUT_HANDLE) =3D=3D get_handle () - && get_ttyp ()->pcon_input_state_eq (tty::to_nat)) + && get_ttyp ()->pty_input_state_eq (tty::to_nat)) { WaitForSingleObject (input_mutex, mutex_timeout); transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), @@ -1147,12 +1155,12 @@ fhandler_pty_slave::reset_switch_to_pcon (void) Therefore, never close pseudo console here. */ return; bool need_restore_handles =3D get_ttyp ()->pcon_activated; - WaitForSingleObject (pcon_mutex, INFINITE); + WaitForSingleObject (pipe_sw_mutex, INFINITE); if (get_ttyp ()->pcon_activated) close_pseudoconsole (get_ttyp ()); else hand_over_only (get_ttyp ()); - ReleaseMutex (pcon_mutex); + ReleaseMutex (pipe_sw_mutex); if (need_restore_handles) { pinfo p (get_ttyp ()->master_pid); @@ -1199,22 +1207,22 @@ fhandler_pty_slave::reset_switch_to_pcon (void) } if (isHybrid) return; - if (get_ttyp ()->pcon_start) + if (get_ttyp ()->pcon_start) /* Pseudo console is initialization on goin= g */ return; - DWORD wait_ret =3D WaitForSingleObject (pcon_mutex, mutex_timeout); + DWORD wait_ret =3D WaitForSingleObject (pipe_sw_mutex, mutex_timeout); if (wait_ret =3D=3D WAIT_TIMEOUT) return; - if (!pcon_pid_self (get_ttyp ()->pcon_pid) - && pcon_pid_alive (get_ttyp ()->pcon_pid)) + if (!nat_pipe_owner_self (get_ttyp ()->nat_pipe_owner_pid) + && nat_pipe_owner_alive (get_ttyp ()->nat_pipe_owner_pid)) { - /* There is a process which is grabbing pseudo console. */ - if (!to_be_read_from_pcon () - && get_ttyp ()->pcon_input_state_eq (tty::to_nat)) + /* There is a process which owns nat pipe. */ + if (!to_be_read_from_nat_pipe () + && get_ttyp ()->pty_input_state_eq (tty::to_nat)) { if (get_ttyp ()->pcon_activated) { - HANDLE pcon_owner =3D - OpenProcess (PROCESS_DUP_HANDLE, FALSE, get_ttyp ()->pcon_pid); + HANDLE pcon_owner =3D OpenProcess (PROCESS_DUP_HANDLE, FALSE, + get_ttyp ()->nat_pipe_owner_pid); if (pcon_owner) { pinfo pinfo_resume =3D pinfo (myself->ppid); @@ -1231,7 +1239,7 @@ fhandler_pty_slave::reset_switch_to_pcon (void) GetCurrentProcess (), &h_pcon_in, 0, TRUE, DUPLICATE_SAME_ACCESS); FreeConsole (); - AttachConsole (get_ttyp ()->pcon_pid); + AttachConsole (get_ttyp ()->nat_pipe_owner_pid); init_console_handler (false); WaitForSingleObject (input_mutex, mutex_timeout); transfer_input (tty::to_cyg, h_pcon_in, get_ttyp (), @@ -1245,8 +1253,8 @@ fhandler_pty_slave::reset_switch_to_pcon (void) CloseHandle (pcon_owner); } } - else if (!get_ttyp ()->pcon_fg (get_ttyp ()->getpgid ()) - && get_ttyp ()->switch_to_pcon_in) + else if (!get_ttyp ()->nat_fg (get_ttyp ()->getpgid ()) + && get_ttyp ()->switch_to_nat_pipe) { WaitForSingleObject (input_mutex, mutex_timeout); transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), @@ -1254,22 +1262,23 @@ fhandler_pty_slave::reset_switch_to_pcon (void) ReleaseMutex (input_mutex); } } - ReleaseMutex (pcon_mutex); + ReleaseMutex (pipe_sw_mutex); return; } /* This input transfer is needed if non-cygwin app is terminated by Ctrl-C or killed. */ WaitForSingleObject (input_mutex, mutex_timeout); - if (get_ttyp ()->switch_to_pcon_in && !get_ttyp ()->pcon_activated - && get_ttyp ()->pcon_input_state_eq (tty::to_nat)) + if (get_ttyp ()->switch_to_nat_pipe && !get_ttyp ()->pcon_activated + && get_ttyp ()->pty_input_state_eq (tty::to_nat)) transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), input_available_event); ReleaseMutex (input_mutex); - get_ttyp ()->pcon_input_state =3D tty::to_cyg; - get_ttyp ()->pcon_pid =3D 0; - get_ttyp ()->switch_to_pcon_in =3D false; + /* Clean up nat pipe state */ + get_ttyp ()->pty_input_state =3D tty::to_cyg; + get_ttyp ()->nat_pipe_owner_pid =3D 0; + get_ttyp ()->switch_to_nat_pipe =3D false; get_ttyp ()->pcon_activated =3D false; - ReleaseMutex (pcon_mutex); + ReleaseMutex (pipe_sw_mutex); } =20 ssize_t __stdcall @@ -1285,7 +1294,7 @@ fhandler_pty_slave::write (const void *ptr, size_t le= n) =20 push_process_state process_state (PID_TTYOU); =20 - reset_switch_to_pcon (); + reset_switch_to_nat_pipe (); =20 acquire_output_mutex (mutex_timeout); if (!process_opost_output (get_output_handle (), ptr, towrite, false, @@ -1308,8 +1317,14 @@ fhandler_pty_slave::write (const void *ptr, size_t l= en) return towrite; } =20 +/* This function is called from some slave pty reading functions + to switch active pipe to cygwin pipe (not nat pipe) temporarily + even though there is another process which owns nat pipe. This + is needed if cygwin process reads input while another non-cygwin + process is running at the same time. + (e.g. Something like "cat | non-cygwin-app") */ void -fhandler_pty_slave::mask_switch_to_pcon_in (bool mask, bool xfer) +fhandler_pty_slave::mask_switch_to_nat_pipe (bool mask, bool xfer) { char name[MAX_PATH]; shared_name (name, TTY_SLAVE_READING, get_minor ()); @@ -1327,8 +1342,8 @@ fhandler_pty_slave::mask_switch_to_pcon_in (bool mask= , bool xfer) =20 /* This is needed when cygwin-app is started from non-cygwin app if pseudo console is disabled. */ - bool need_xfer =3D get_ttyp ()->pcon_fg (get_ttyp ()->getpgid ()) - && get_ttyp ()->switch_to_pcon_in && !get_ttyp ()->pcon_activated; + bool need_xfer =3D get_ttyp ()->nat_fg (get_ttyp ()->getpgid ()) + && get_ttyp ()->switch_to_nat_pipe && !get_ttyp ()->pcon_activated; =20 /* In GDB, transfer input based on setpgid() does not work because GDB may not set terminal process group properly. Therefore, @@ -1337,20 +1352,21 @@ fhandler_pty_slave::mask_switch_to_pcon_in (bool ma= sk, bool xfer) isHybrid && GetStdHandle (STD_INPUT_HANDLE) =3D=3D get_handle (); if (!!masked !=3D mask && xfer && (need_gdb_xfer || need_xfer)) { - if (mask && get_ttyp ()->pcon_input_state_eq (tty::to_nat)) + if (mask && get_ttyp ()->pty_input_state_eq (tty::to_nat)) transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), input_available_event); - else if (!mask && get_ttyp ()->pcon_input_state_eq (tty::to_cyg)) + else if (!mask && get_ttyp ()->pty_input_state_eq (tty::to_cyg)) transfer_input (tty::to_nat, get_handle (), get_ttyp (), input_available_event); } ReleaseMutex (input_mutex); } =20 +/* Return true when the non-cygwin app is reading the input. */ bool -fhandler_pty_common::to_be_read_from_pcon (void) +fhandler_pty_common::to_be_read_from_nat_pipe (void) { - if (!get_ttyp ()->switch_to_pcon_in) + if (!get_ttyp ()->switch_to_nat_pipe) return false; =20 char name[MAX_PATH]; @@ -1365,7 +1381,7 @@ fhandler_pty_common::to_be_read_from_pcon (void) /* GDB may set invalid process group for non-cygwin process. */ return true; =20 - return get_ttyp ()->pcon_fg (get_ttyp ()->getpgid ()); + return get_ttyp ()->nat_fg (get_ttyp ()->getpgid ()); } =20 void __reg3 @@ -1393,8 +1409,8 @@ fhandler_pty_slave::read (void *ptr, size_t& len) =20 if (ptr) /* Indicating not tcflush(). */ { - mask_switch_to_pcon_in (true, true); - reset_switch_to_pcon (); + mask_switch_to_nat_pipe (true, true); + reset_switch_to_nat_pipe (); } =20 if (is_nonblocking () || !ptr) /* Indicating tcflush(). */ @@ -1513,7 +1529,7 @@ wait_retry: if (ptr && !bytes_in_pipe && !vmin && !time_to_wait) { ReleaseMutex (input_mutex); - mask_switch_to_pcon_in (false, false); + mask_switch_to_nat_pipe (false, false); len =3D (size_t) bytes_in_pipe; return; } @@ -1621,7 +1637,7 @@ out: if (ptr0) { /* Not tcflush() */ bool saw_eol =3D totalread > 0 && strchr ("\r\n", ptr0[totalread -1]= ); - mask_switch_to_pcon_in (false, saw_eol || len =3D=3D 0); + mask_switch_to_nat_pipe (false, saw_eol || len =3D=3D 0); } } =20 @@ -1652,7 +1668,7 @@ fhandler_pty_master::dup (fhandler_base *child, int) int fhandler_pty_slave::tcgetattr (struct termios *t) { - reset_switch_to_pcon (); + reset_switch_to_nat_pipe (); *t =3D get_ttyp ()->ti; =20 /* Workaround for rlwrap */ @@ -1673,7 +1689,7 @@ fhandler_pty_slave::tcgetattr (struct termios *t) int fhandler_pty_slave::tcsetattr (int, const struct termios *t) { - reset_switch_to_pcon (); + reset_switch_to_nat_pipe (); acquire_output_mutex (mutex_timeout); get_ttyp ()->ti =3D *t; release_output_mutex (); @@ -1687,7 +1703,7 @@ fhandler_pty_slave::tcflush (int queue) =20 termios_printf ("tcflush(%d) handle %p", queue, get_handle ()); =20 - reset_switch_to_pcon (); + reset_switch_to_nat_pipe (); =20 if (queue =3D=3D TCIFLUSH || queue =3D=3D TCIOFLUSH) { @@ -1708,7 +1724,7 @@ int fhandler_pty_slave::ioctl (unsigned int cmd, void *arg) { termios_printf ("ioctl (%x)", cmd); - reset_switch_to_pcon (); + reset_switch_to_nat_pipe (); int res =3D fhandler_termios::ioctl (cmd, arg); if (res <=3D 0) return res; @@ -1781,7 +1797,7 @@ fhandler_pty_slave::ioctl (unsigned int cmd, void *ar= g) || get_ttyp ()->winsize.ws_xpixel !=3D ((struct winsize *) arg)->ws_xpi= xel ) { - if (get_ttyp ()->pcon_activated && get_ttyp ()->pcon_pid) + if (get_ttyp ()->pcon_activated && get_ttyp ()->nat_pipe_owner_pid) resize_pseudo_console ((struct winsize *) arg); get_ttyp ()->arg.winsize =3D *(struct winsize *) arg; get_ttyp ()->winsize =3D *(struct winsize *) arg; @@ -1903,7 +1919,7 @@ fhandler_pty_slave::fch_open_handles (bool chown) TRUE, buf); output_mutex =3D get_ttyp ()->open_output_mutex (write_access); input_mutex =3D get_ttyp ()->open_input_mutex (write_access); - pcon_mutex =3D get_ttyp ()->open_mutex (PCON_MUTEX, write_access); + pipe_sw_mutex =3D get_ttyp ()->open_mutex (PIPE_SW_MUTEX, write_access); inuse =3D get_ttyp ()->open_inuse (write_access); if (!input_available_event || !output_mutex || !input_mutex || !inuse) { @@ -2057,8 +2073,8 @@ fhandler_pty_common::close () get_minor (), get_handle (), get_output_handle ()); if (!ForceCloseHandle (input_mutex)) termios_printf ("CloseHandle (input_mutex<%p>), %E", input_mutex); - if (!ForceCloseHandle (pcon_mutex)) - termios_printf ("CloseHandle (pcon_mutex<%p>), %E", pcon_mutex); + if (!ForceCloseHandle (pipe_sw_mutex)) + termios_printf ("CloseHandle (pipe_sw_mutex<%p>), %E", pipe_sw_mutex); if (!ForceCloseHandle1 (get_handle (), from_pty)) termios_printf ("CloseHandle (get_handle ()<%p>), %E", get_handle ()); if (!ForceCloseHandle1 (get_output_handle (), to_pty)) @@ -2076,7 +2092,7 @@ fhandler_pty_common::resize_pseudo_console (struct wi= nsize *ws) size.Y =3D ws->ws_row; HPCON_INTERNAL hpcon_local; HANDLE pcon_owner =3D - OpenProcess (PROCESS_DUP_HANDLE, FALSE, get_ttyp ()->pcon_pid); + OpenProcess (PROCESS_DUP_HANDLE, FALSE, get_ttyp ()->nat_pipe_owner_pi= d); DuplicateHandle (pcon_owner, get_ttyp ()->h_pcon_write_pipe, GetCurrentProcess (), &hpcon_local.hWritePipe, 0, TRUE, DUPLICATE_SAME_ACCESS); @@ -2255,8 +2271,8 @@ fhandler_pty_master::write (const void *ptr, size_t l= en) /* GDB may set WINPID rather than cygwin PID to process group when the debugged process is a non-cygwin process.*/ pcon_fg |=3D !pinfo (get_ttyp ()->getpgid ()); - if (get_ttyp ()->switch_to_pcon_in && pcon_fg - && get_ttyp ()->pcon_input_state_eq (tty::to_cyg)) + if (get_ttyp ()->switch_to_nat_pipe && pcon_fg + && get_ttyp ()->pty_input_state_eq (tty::to_cyg)) { /* This accept_input() call is needed in order to transfer input which is not accepted yet to non-cygwin pipe. */ @@ -2277,8 +2293,8 @@ fhandler_pty_master::write (const void *ptr, size_t l= en) /* Write terminal input to to_slave_nat pipe instead of output_handle if current application is native console application. */ WaitForSingleObject (input_mutex, mutex_timeout); - if (to_be_read_from_pcon () && get_ttyp ()->pcon_activated - && get_ttyp ()->pcon_input_state =3D=3D tty::to_nat) + if (to_be_read_from_nat_pipe () && get_ttyp ()->pcon_activated + && get_ttyp ()->pty_input_state =3D=3D tty::to_nat) { tmp_pathbuf tp; char *buf =3D (char *) ptr; @@ -2315,8 +2331,8 @@ fhandler_pty_master::write (const void *ptr, size_t l= en) =20 /* 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_pcon () && !get_ttyp ()->pcon_activated - && get_ttyp ()->pcon_input_state =3D=3D tty::to_cyg) + if (to_be_read_from_nat_pipe () && !get_ttyp ()->pcon_activated + && get_ttyp ()->pty_input_state =3D=3D tty::to_cyg) fhandler_pty_slave::transfer_input (tty::to_nat, from_master, get_ttyp (), input_available_event); ReleaseMutex (input_mutex); @@ -2399,7 +2415,7 @@ fhandler_pty_master::ioctl (unsigned int cmd, void *a= rg) || get_ttyp ()->winsize.ws_xpixel !=3D ((struct winsize *) arg)->ws_xpi= xel ) { - if (get_ttyp ()->pcon_activated && get_ttyp ()->pcon_pid) + if (get_ttyp ()->pcon_activated && get_ttyp ()->nat_pipe_owner_pid) resize_pseudo_console ((struct winsize *) arg); get_ttyp ()->winsize =3D *(struct winsize *) arg; get_ttyp ()->kill_pgrp (SIGWINCH); @@ -2473,7 +2489,7 @@ fhandler_pty_slave::fixup_after_fork (HANDLE parent) void fhandler_pty_slave::fixup_after_exec () { - reset_switch_to_pcon (); + reset_switch_to_nat_pipe (); create_invisible_console (); =20 if (!close_on_exec ()) @@ -2685,9 +2701,9 @@ fhandler_pty_master::pty_master_fwd_thread (const mas= ter_fwd_thread_param_t *p) termios_printf ("Started."); for (;;) { - p->ttyp->pcon_last_time =3D GetTickCount (); + p->ttyp->fwd_last_time =3D GetTickCount (); DWORD n; - p->ttyp->pcon_fwd_not_empty =3D + p->ttyp->fwd_not_empty =3D ::bytes_available (n, p->from_slave_nat) && n; if (!ReadFile (p->from_slave_nat, outbuf, NT_MAX_PATH, &rlen, NULL)) { @@ -2900,6 +2916,7 @@ fhandler_pty_master::setup () SECURITY_ATTRIBUTES sa =3D { sizeof (SECURITY_ATTRIBUTES), NULL, TRUE }; =20 /* Find an unallocated pty to use. */ + /* Create a pipe for cygwin app (master to slave) simultaneously. */ int unit =3D cygwin_shared->tty.allocate (from_master, get_output_handle= ()); if (unit < 0) return false; @@ -2918,6 +2935,7 @@ fhandler_pty_master::setup () termios_printf ("can't set output_handle(%p) to non-blocking mode", get_output_handle ()); =20 + /* Pipe for non-cygwin apps (slave to master) */ char pipename[sizeof ("ptyNNNN-from-master-nat")]; __small_sprintf (pipename, "pty%d-to-master-nat", unit); res =3D fhandler_pipe::create (&sec_none, &from_slave_nat, &to_master_na= t, @@ -2928,6 +2946,7 @@ fhandler_pty_master::setup () goto err; } =20 + /* Pipe for cygwin apps (slave to master) */ __small_sprintf (pipename, "pty%d-to-master", unit); res =3D fhandler_pipe::create (&sec_none, &get_handle (), &to_master, fhandler_pty_common::pipesize, pipename, 0); @@ -2937,6 +2956,7 @@ fhandler_pty_master::setup () goto err; } =20 + /* Pipe for non-cygwin apps (master to slave) */ __small_sprintf (pipename, "pty%d-from-master-nat", unit); /* FILE_FLAG_OVERLAPPED is specified here in order to prevent PeekNamedPipe() from blocking in transfer_input(). @@ -2990,8 +3010,8 @@ fhandler_pty_master::setup () if (!(input_mutex =3D CreateMutex (&sa, FALSE, buf))) goto err; =20 - errstr =3D shared_name (buf, PCON_MUTEX, unit); - if (!(pcon_mutex =3D CreateMutex (&sa, FALSE, buf))) + errstr =3D shared_name (buf, PIPE_SW_MUTEX, unit); + if (!(pipe_sw_mutex =3D CreateMutex (&sa, FALSE, buf))) goto err; =20 if (!attach_mutex) @@ -3239,8 +3259,8 @@ fhandler_pty_slave::setup_pseudoconsole () Sleep (1); } /* Attach to the pseudo console which already exits. */ - HANDLE pcon_owner =3D - OpenProcess (PROCESS_DUP_HANDLE, FALSE, get_ttyp ()->pcon_pid); + HANDLE pcon_owner =3D OpenProcess (PROCESS_DUP_HANDLE, FALSE, + get_ttyp ()->nat_pipe_owner_pid); if (pcon_owner =3D=3D NULL) return false; DuplicateHandle (pcon_owner, get_ttyp ()->h_pcon_in, @@ -3251,7 +3271,7 @@ fhandler_pty_slave::setup_pseudoconsole () 0, TRUE, DUPLICATE_SAME_ACCESS); CloseHandle (pcon_owner); FreeConsole (); - AttachConsole (get_ttyp ()->pcon_pid); + AttachConsole (get_ttyp ()->nat_pipe_owner_pid); init_console_handler (false); goto skip_create; } @@ -3408,10 +3428,10 @@ skip_create: } while (false); =20 - if (!pcon_pid_alive (get_ttyp ()->pcon_pid)) - get_ttyp ()->pcon_pid =3D myself->exec_dwProcessId; + if (!nat_pipe_owner_alive (get_ttyp ()->nat_pipe_owner_pid)) + get_ttyp ()->nat_pipe_owner_pid =3D myself->exec_dwProcessId; =20 - if (hpcon && pcon_pid_self (get_ttyp ()->pcon_pid)) + if (hpcon && nat_pipe_owner_self (get_ttyp ()->nat_pipe_owner_pid)) { HPCON_INTERNAL *hp =3D (HPCON_INTERNAL *) hpcon; get_ttyp ()->h_pcon_write_pipe =3D hp->hWritePipe; @@ -3506,7 +3526,7 @@ fhandler_pty_slave::get_winpid_to_hand_over (tty *tty= p, switch_to =3D force_switch_to; ttyp->setpgid (force_switch_to + MAX_PID); } - else if (pcon_pid_self (ttyp->pcon_pid)) + else if (nat_pipe_owner_self (ttyp->nat_pipe_owner_pid)) { /* Search another native process which attaches to the same console = */ DWORD current_pid =3D myself->exec_dwProcessId ?: myself->dwProcessI= d; @@ -3520,17 +3540,17 @@ fhandler_pty_slave::get_winpid_to_hand_over (tty *t= typ, void fhandler_pty_slave::hand_over_only (tty *ttyp, DWORD force_switch_to) { - if (pcon_pid_self (ttyp->pcon_pid)) + if (nat_pipe_owner_self (ttyp->nat_pipe_owner_pid)) { DWORD switch_to =3D get_winpid_to_hand_over (ttyp, force_switch_to); if (switch_to) /* The process switch_to takes over the ownership of the nat pipe. */ - ttyp->pcon_pid =3D switch_to; + ttyp->nat_pipe_owner_pid =3D switch_to; else { /* Abandon the ownership of the nat pipe */ - ttyp->pcon_pid =3D 0; - ttyp->switch_to_pcon_in =3D false; + ttyp->nat_pipe_owner_pid =3D 0; + ttyp->switch_to_nat_pipe =3D false; } } } @@ -3543,7 +3563,7 @@ fhandler_pty_slave::close_pseudoconsole (tty *ttyp, D= WORD force_switch_to) DWORD switch_to =3D get_winpid_to_hand_over (ttyp, force_switch_to); ttyp->previous_code_page =3D GetConsoleCP (); ttyp->previous_output_code_page =3D GetConsoleOutputCP (); - if (pcon_pid_self (ttyp->pcon_pid)) + if (nat_pipe_owner_self (ttyp->nat_pipe_owner_pid)) { /* I am owner of the nat pipe. */ if (switch_to) { @@ -3578,7 +3598,7 @@ fhandler_pty_slave::close_pseudoconsole (tty *ttyp, D= WORD force_switch_to) CloseHandle (ttyp->h_pcon_conhost_process); CloseHandle (ttyp->h_pcon_in); CloseHandle (ttyp->h_pcon_out); - ttyp->pcon_pid =3D switch_to; + ttyp->nat_pipe_owner_pid =3D switch_to; ttyp->h_pcon_write_pipe =3D new_write_pipe; ttyp->h_pcon_condrv_reference =3D new_condrv_reference; ttyp->h_pcon_conhost_process =3D new_conhost_process; @@ -3608,8 +3628,8 @@ fhandler_pty_slave::close_pseudoconsole (tty *ttyp, D= WORD force_switch_to) ClosePseudoConsole ((HPCON) hp); CloseHandle (ttyp->h_pcon_conhost_process); ttyp->pcon_activated =3D false; - ttyp->switch_to_pcon_in =3D false; - ttyp->pcon_pid =3D 0; + ttyp->switch_to_nat_pipe =3D false; + ttyp->nat_pipe_owner_pid =3D 0; ttyp->pcon_start =3D false; ttyp->pcon_start_pid =3D 0; } @@ -3710,7 +3730,7 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *e= nv) goto maybe_dumb; =20 /* Check if terminal has CSI6n */ - WaitForSingleObject (pcon_mutex, INFINITE); + WaitForSingleObject (pipe_sw_mutex, INFINITE); WaitForSingleObject (input_mutex, mutex_timeout); /* Set pcon_activated and pcon_start so that the response will sent to io_handle_nat rather than io_handle. */ @@ -3745,8 +3765,8 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *e= nv) } while (len); get_ttyp ()->pcon_activated =3D false; - get_ttyp ()->pcon_pid =3D 0; - ReleaseMutex (pcon_mutex); + get_ttyp ()->nat_pipe_owner_pid =3D 0; + ReleaseMutex (pipe_sw_mutex); if (len =3D=3D 0) goto not_has_csi6n; =20 @@ -3762,7 +3782,7 @@ not_has_csi6n: get_ttyp ()->pcon_start =3D false; get_ttyp ()->pcon_activated =3D false; ReleaseMutex (input_mutex); - ReleaseMutex (pcon_mutex); + ReleaseMutex (pipe_sw_mutex); maybe_dumb: get_ttyp ()->pcon_cap_checked =3D true; return false; @@ -3974,7 +3994,7 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir dir= , HANDLE from, tty *ttyp, ResetEvent (input_available_event); else if (transfered) SetEvent (input_available_event); - ttyp->pcon_input_state =3D dir; + ttyp->pty_input_state =3D dir; ttyp->discard_input =3D false; } =20 @@ -3982,7 +4002,7 @@ void fhandler_pty_slave::cleanup_before_exit () { if (myself->process_state & PID_NOTCYGWIN) - get_ttyp ()->wait_pcon_fwd (); + get_ttyp ()->wait_fwd (); } =20 void @@ -3997,8 +4017,8 @@ fhandler_pty_slave::get_duplicated_handle_set (handle= _set_t *p) DuplicateHandle (GetCurrentProcess (), input_mutex, GetCurrentProcess (), &p->input_mutex, 0, 0, DUPLICATE_SAME_ACCESS); - DuplicateHandle (GetCurrentProcess (), pcon_mutex, - GetCurrentProcess (), &p->pcon_mutex, + DuplicateHandle (GetCurrentProcess (), pipe_sw_mutex, + GetCurrentProcess (), &p->pipe_sw_mutex, 0, 0, DUPLICATE_SAME_ACCESS); } =20 @@ -4011,8 +4031,8 @@ fhandler_pty_slave::close_handle_set (handle_set_t *p) p->input_available_event =3D NULL; CloseHandle (p->input_mutex); p->input_mutex =3D NULL; - CloseHandle (p->pcon_mutex); - p->pcon_mutex =3D NULL; + CloseHandle (p->pipe_sw_mutex); + p->pipe_sw_mutex =3D NULL; } =20 void @@ -4021,24 +4041,24 @@ fhandler_pty_slave::setup_for_non_cygwin_app (bool = nopcon, PWCHAR envblock, { if (disable_pcon || !term_has_pcon_cap (envblock)) nopcon =3D true; - WaitForSingleObject (pcon_mutex, INFINITE); - /* Setting switch_to_pcon_in is necessary even if pseudo console + WaitForSingleObject (pipe_sw_mutex, INFINITE); + /* Setting switch_to_nat_pipe is necessary even if pseudo console will not be activated. */ fhandler_base *fh =3D ::cygheap->fdtab[0]; if (fh && fh->get_major () =3D=3D DEV_PTYS_MAJOR) { fhandler_pty_slave *ptys =3D (fhandler_pty_slave *) fh; - ptys->get_ttyp ()->switch_to_pcon_in =3D true; - if (!pcon_pid_alive (ptys->get_ttyp ()->pcon_pid)) - ptys->get_ttyp ()->pcon_pid =3D myself->exec_dwProcessId; + ptys->get_ttyp ()->switch_to_nat_pipe =3D true; + if (!nat_pipe_owner_alive (ptys->get_ttyp ()->nat_pipe_owner_pid)) + ptys->get_ttyp ()->nat_pipe_owner_pid =3D myself->exec_dwProcessId; } bool pcon_enabled =3D false; if (!nopcon) pcon_enabled =3D setup_pseudoconsole (); - ReleaseMutex (pcon_mutex); + ReleaseMutex (pipe_sw_mutex); /* For pcon enabled case, transfer_input() is called in master::write() = */ if (!pcon_enabled && get_ttyp ()->getpgid () =3D=3D myself->pgid - && stdin_is_ptys && get_ttyp ()->pcon_input_state_eq (tty::to_cyg)) + && stdin_is_ptys && get_ttyp ()->pty_input_state_eq (tty::to_cyg)) { WaitForSingleObject (input_mutex, mutex_timeout); transfer_input (tty::to_nat, get_handle (), get_ttyp (), @@ -4052,53 +4072,53 @@ fhandler_pty_slave::cleanup_for_non_cygwin_app (han= dle_set_t *p, tty *ttyp, bool stdin_is_ptys, DWORD force_switch_to) { - ttyp->wait_pcon_fwd (); + ttyp->wait_fwd (); if (ttyp->getpgid () =3D=3D myself->pgid && stdin_is_ptys - && ttyp->pcon_input_state_eq (tty::to_nat)) + && ttyp->pty_input_state_eq (tty::to_nat)) { WaitForSingleObject (p->input_mutex, mutex_timeout); transfer_input (tty::to_cyg, p->from_master_nat, ttyp, p->input_available_event); ReleaseMutex (p->input_mutex); } - WaitForSingleObject (p->pcon_mutex, INFINITE); + WaitForSingleObject (p->pipe_sw_mutex, INFINITE); if (ttyp->pcon_activated) close_pseudoconsole (ttyp, force_switch_to); else hand_over_only (ttyp, force_switch_to); - ReleaseMutex (p->pcon_mutex); + ReleaseMutex (p->pipe_sw_mutex); } =20 void fhandler_pty_slave::setpgid_aux (pid_t pid) { - WaitForSingleObject (pcon_mutex, INFINITE); - bool was_pcon_fg =3D get_ttyp ()->pcon_fg (tc ()->pgid); - bool pcon_fg =3D get_ttyp ()->pcon_fg (pid); - if (!was_pcon_fg && pcon_fg && get_ttyp ()->switch_to_pcon_in - && get_ttyp ()->pcon_input_state_eq (tty::to_cyg)) + WaitForSingleObject (pipe_sw_mutex, INFINITE); + bool was_nat_fg =3D get_ttyp ()->nat_fg (tc ()->pgid); + bool nat_fg =3D get_ttyp ()->nat_fg (pid); + if (!was_nat_fg && nat_fg && get_ttyp ()->switch_to_nat_pipe + && get_ttyp ()->pty_input_state_eq (tty::to_cyg)) { WaitForSingleObject (input_mutex, mutex_timeout); transfer_input (tty::to_nat, get_handle (), get_ttyp (), input_available_event); ReleaseMutex (input_mutex); } - else if (was_pcon_fg && !pcon_fg && get_ttyp ()->switch_to_pcon_in - && get_ttyp ()->pcon_input_state_eq (tty::to_nat)) + else if (was_nat_fg && !nat_fg && get_ttyp ()->switch_to_nat_pipe + && get_ttyp ()->pty_input_state_eq (tty::to_nat)) { bool attach_restore =3D false; HANDLE from =3D get_handle_nat (); - if (get_ttyp ()->pcon_activated && get_ttyp ()->pcon_pid - && !get_console_process_id (get_ttyp ()->pcon_pid, true)) + if (get_ttyp ()->pcon_activated && get_ttyp ()->nat_pipe_owner_pid + && !get_console_process_id (get_ttyp ()->nat_pipe_owner_pid, true)) { - HANDLE pcon_owner =3D - OpenProcess (PROCESS_DUP_HANDLE, FALSE, get_ttyp ()->pcon_pid); + HANDLE pcon_owner =3D OpenProcess (PROCESS_DUP_HANDLE, FALSE, + get_ttyp ()->nat_pipe_owner_pid); DuplicateHandle (pcon_owner, get_ttyp ()->h_pcon_in, GetCurrentProcess (), &from, 0, TRUE, DUPLICATE_SAME_ACCESS); CloseHandle (pcon_owner); FreeConsole (); - AttachConsole (get_ttyp ()->pcon_pid); + AttachConsole (get_ttyp ()->nat_pipe_owner_pid); init_console_handler (false); attach_restore =3D true; } @@ -4114,7 +4134,7 @@ fhandler_pty_slave::setpgid_aux (pid_t pid) init_console_handler (false); } } - ReleaseMutex (pcon_mutex); + ReleaseMutex (pipe_sw_mutex); } =20 bool @@ -4124,8 +4144,8 @@ fhandler_pty_master::need_send_ctrl_c_event () apps will be done in pseudo console, therefore, sending it in fhandler_pty_master::write() duplicates that event for non-cygwin apps. So return false if pseudo console is activated. */ - return !(to_be_read_from_pcon () && get_ttyp ()->pcon_activated - && get_ttyp ()->pcon_input_state =3D=3D tty::to_nat); + return !(to_be_read_from_nat_pipe () && get_ttyp ()->pcon_activated + && get_ttyp ()->pty_input_state =3D=3D tty::to_nat); } =20 void @@ -4135,11 +4155,11 @@ fhandler_pty_slave::release_ownership_of_nat_pipe (= tty *ttyp, if (fh->get_major () =3D=3D DEV_PTYM_MAJOR) { fhandler_pty_master *ptym =3D (fhandler_pty_master *) fh; - WaitForSingleObject (ptym->pcon_mutex, INFINITE); + WaitForSingleObject (ptym->pipe_sw_mutex, INFINITE); if (ttyp->pcon_activated) close_pseudoconsole (ttyp); else hand_over_only (ttyp); - ReleaseMutex (ptym->pcon_mutex); + ReleaseMutex (ptym->pipe_sw_mutex); } } diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index b20cef78f..80a9527dc 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -1351,7 +1351,7 @@ peek_pty_slave (select_record *s, bool from_select) fhandler_base *fh =3D (fhandler_base *) s->fh; fhandler_pty_slave *ptys =3D (fhandler_pty_slave *) fh; =20 - ptys->reset_switch_to_pcon (); + ptys->reset_switch_to_nat_pipe (); =20 if (s->read_selected) { @@ -1437,7 +1437,7 @@ pty_slave_startup (select_record *me, select_stuff *s= tuff) fhandler_base *fh =3D (fhandler_base *) me->fh; fhandler_pty_slave *ptys =3D (fhandler_pty_slave *) fh; if (me->read_selected) - ptys->mask_switch_to_pcon_in (true, true); + ptys->mask_switch_to_nat_pipe (true, true); =20 select_pipe_info *pi =3D stuff->device_specific_ptys; if (pi->start) @@ -1464,7 +1464,7 @@ pty_slave_cleanup (select_record *me, select_stuff *s= tuff) if (!pi) return; if (me->read_selected && pi->start) - ptys->mask_switch_to_pcon_in (false, false); + ptys->mask_switch_to_nat_pipe (false, false); if (pi->thread) { pi->stop_thread =3D true; diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index 25b621227..b2218fef7 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -236,11 +236,11 @@ tty::init () is_console =3D false; column =3D 0; pcon_activated =3D false; - switch_to_pcon_in =3D false; - pcon_pid =3D 0; + switch_to_nat_pipe =3D false; + nat_pipe_owner_pid =3D 0; term_code_page =3D 0; - pcon_last_time =3D 0; - pcon_fwd_not_empty =3D false; + fwd_last_time =3D 0; + fwd_not_empty =3D false; pcon_start =3D false; pcon_start_pid =3D 0; pcon_cap_checked =3D false; @@ -251,7 +251,7 @@ tty::init () previous_output_code_page =3D 0; master_is_running_as_service =3D false; req_xfer_input =3D false; - pcon_input_state =3D to_cyg; + pty_input_state =3D to_cyg; last_sig =3D 0; mask_flusho =3D false; discard_input =3D false; @@ -313,27 +313,27 @@ tty_min::setpgid (int pid) } =20 void -tty::wait_pcon_fwd () +tty::wait_fwd () { /* The forwarding in pseudo console sometimes stops for 16-32 msec even if it already has data to transfer. If the time without transfer exceeds 32 msec, the - forwarding is supposed to be finished. pcon_last_time + forwarding is supposed to be finished. fwd_last_time is reset to GetTickCount() in pty master forwarding thread when the last data is transfered. */ - const int sleep_in_pcon =3D 16; - const int time_to_wait =3D sleep_in_pcon * 2 + 1/* margine */; + const int sleep_in_nat_pipe =3D 16; + const int time_to_wait =3D sleep_in_nat_pipe * 2 + 1/* margine */; int elapsed; - while (pcon_fwd_not_empty - || (elapsed =3D GetTickCount () - pcon_last_time) < time_to_wait) + while (fwd_not_empty + || (elapsed =3D GetTickCount () - fwd_last_time) < time_to_wait) { - int tw =3D pcon_fwd_not_empty ? 10 : (time_to_wait - elapsed); + int tw =3D fwd_not_empty ? 10 : (time_to_wait - elapsed); cygwait (tw); } } =20 bool -tty::pcon_fg (pid_t pgid) +tty::nat_fg (pid_t pgid) { /* Check if the terminal pgid matches with the pgid of the non-cygwin process. */ diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h index 87ff43ea2..3a8711039 100644 --- a/winsup/cygwin/tty.h +++ b/winsup/cygwin/tty.h @@ -20,7 +20,7 @@ details. */ #define INPUT_AVAILABLE_EVENT "cygtty.input.avail" #define OUTPUT_MUTEX "cygtty.output.mutex" #define INPUT_MUTEX "cygtty.input.mutex" -#define PCON_MUTEX "cygtty.pcon.mutex" +#define PIPE_SW_MUTEX "cygtty.pipe_sw.mutex" #define TTY_SLAVE_ALIVE "cygtty.slave_alive" #define TTY_SLAVE_READING "cygtty.slave_reading" =20 @@ -80,6 +80,10 @@ public: const __reg1 char *ttyname () __attribute (()); }; =20 + +/* The name *nat* comes from 'native' which means non-cygwin + (native windows). They are used for non-cygwin process. */ + class fhandler_pty_master; =20 class tty: public tty_min @@ -112,11 +116,11 @@ private: bool pcon_activated; bool pcon_start; pid_t pcon_start_pid; - bool switch_to_pcon_in; - DWORD pcon_pid; + bool switch_to_nat_pipe; + DWORD nat_pipe_owner_pid; UINT term_code_page; - DWORD pcon_last_time; - bool pcon_fwd_not_empty; + DWORD fwd_last_time; + bool fwd_not_empty; HANDLE h_pcon_write_pipe; HANDLE h_pcon_condrv_reference; HANDLE h_pcon_conhost_process; @@ -130,7 +134,7 @@ private: UINT previous_output_code_page; bool master_is_running_as_service; bool req_xfer_input; - xfer_dir pcon_input_state; + xfer_dir pty_input_state; bool mask_flusho; bool discard_input; bool stop_fwd_thread; @@ -167,9 +171,9 @@ public: void set_master_ctl_closed () {master_pid =3D -1;} static void __stdcall create_master (int); static void __stdcall init_session (); - void wait_pcon_fwd (); - bool pcon_input_state_eq (xfer_dir x) { return pcon_input_state =3D=3D x= ; } - bool pcon_fg (pid_t pgid); + void wait_fwd (); + bool pty_input_state_eq (xfer_dir x) { return pty_input_state =3D=3D x; } + bool nat_fg (pid_t pgid); friend class fhandler_pty_common; friend class fhandler_pty_master; friend class fhandler_pty_slave;