aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/spawn.cc
diff options
context:
space:
mode:
authorTakashi Yano via Cygwin-patches <cygwin-patches@cygwin.com>2021-01-28 12:26:14 +0900
committerCorinna Vinschen <corinna@vinschen.de>2021-01-28 11:21:12 +0100
commit253352e796ff9ec9a447e5375f5bc3e2b92b5293 (patch)
treeb8242b05afaf8efa46ad6b7a4f547c2f4870f93b /winsup/cygwin/spawn.cc
parent8aeb3f3e50373ecc300a32caab1e91980aabb40b (diff)
downloadnewlib-253352e796ff9ec9a447e5375f5bc3e2b92b5293.zip
newlib-253352e796ff9ec9a447e5375f5bc3e2b92b5293.tar.gz
newlib-253352e796ff9ec9a447e5375f5bc3e2b92b5293.tar.bz2
Cygwin: pty: Allow multiple apps to enable pseudo console simultaneously.
- After commit bb428520, there has been the disadvantage: 7) Pseudo console cannot be activated if it is already activated for another process on same pty. This patch clears this disadvantage.
Diffstat (limited to 'winsup/cygwin/spawn.cc')
-rw-r--r--winsup/cygwin/spawn.cc44
1 files changed, 30 insertions, 14 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 383a5a0..c4b6128 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -656,6 +656,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
bool enable_pcon = false;
HANDLE ptys_from_master = NULL;
HANDLE ptys_input_available_event = NULL;
+ HANDLE ptys_output_mutex = NULL;
tty *ptys_ttyp = NULL;
_minor_t ptys_unit = 0;
if (!iscygwin () && ptys_primary && is_console_app (runpath))
@@ -676,6 +677,9 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
DuplicateHandle (GetCurrentProcess (), ptys_input_available_event,
GetCurrentProcess (), &ptys_input_available_event,
0, 0, DUPLICATE_SAME_ACCESS);
+ DuplicateHandle (GetCurrentProcess (), ptys_primary->output_mutex,
+ GetCurrentProcess (), &ptys_output_mutex,
+ 0, 0, DUPLICATE_SAME_ACCESS);
if (!enable_pcon)
fhandler_pty_slave::transfer_input (fhandler_pty_slave::to_nat,
ptys_primary->get_handle_cyg (),
@@ -965,16 +969,22 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
if (ptys_ttyp)
{
ptys_ttyp->wait_pcon_fwd ();
- fhandler_pty_slave::transfer_input (fhandler_pty_slave::to_cyg,
- ptys_from_master,
- ptys_ttyp, ptys_unit,
- ptys_input_available_event);
+ /* Do not transfer input if another process using pseudo
+ console exists. */
+ WaitForSingleObject (ptys_output_mutex, INFINITE);
+ if (!fhandler_pty_common::get_console_process_id
+ (myself->exec_dwProcessId, false, true, true))
+ fhandler_pty_slave::transfer_input (fhandler_pty_slave::to_cyg,
+ ptys_from_master,
+ ptys_ttyp, ptys_unit,
+ ptys_input_available_event);
CloseHandle (ptys_from_master);
CloseHandle (ptys_input_available_event);
+ fhandler_pty_slave::close_pseudoconsole (ptys_ttyp);
+ ReleaseMutex (ptys_output_mutex);
+ CloseHandle (ptys_output_mutex);
}
- if (enable_pcon)
- fhandler_pty_slave::close_pseudoconsole (ptys_ttyp);
- else if (cons_native)
+ if (cons_native)
{
fhandler_console::request_xterm_mode_output (true,
&cons_handle_set);
@@ -992,16 +1002,22 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
if (ptys_ttyp)
{
ptys_ttyp->wait_pcon_fwd ();
- fhandler_pty_slave::transfer_input (fhandler_pty_slave::to_cyg,
- ptys_from_master,
- ptys_ttyp, ptys_unit,
- ptys_input_available_event);
+ /* Do not transfer input if another process using pseudo
+ console exists. */
+ WaitForSingleObject (ptys_output_mutex, INFINITE);
+ if (!fhandler_pty_common::get_console_process_id
+ (myself->exec_dwProcessId, false, true, true))
+ fhandler_pty_slave::transfer_input (fhandler_pty_slave::to_cyg,
+ ptys_from_master,
+ ptys_ttyp, ptys_unit,
+ ptys_input_available_event);
CloseHandle (ptys_from_master);
CloseHandle (ptys_input_available_event);
+ fhandler_pty_slave::close_pseudoconsole (ptys_ttyp);
+ ReleaseMutex (ptys_output_mutex);
+ CloseHandle (ptys_output_mutex);
}
- if (enable_pcon)
- fhandler_pty_slave::close_pseudoconsole (ptys_ttyp);
- else if (cons_native)
+ if (cons_native)
{
fhandler_console::request_xterm_mode_output (true,
&cons_handle_set);