Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route "Device Status Report" responses correctly #72

Merged
merged 2 commits into from
Dec 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions winsup/cygwin/fhandler_tty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,11 @@ fhandler_pty_slave::reset_switch_to_pcon (void)
{
char pipe[MAX_PATH];
__small_sprintf (pipe,
#ifdef __MSYS__
"\\\\.\\pipe\\msys-%S-pty%d-master-ctl",
#else
"\\\\.\\pipe\\cygwin-%S-pty%d-master-ctl",
#endif
&cygheap->installation_key, get_minor ());
pipe_request req = { GetCurrentProcessId () };
pipe_reply repl;
Expand Down Expand Up @@ -1243,10 +1247,13 @@ fhandler_pty_slave::mask_switch_to_pcon_in (bool mask, bool xfer)
else if (InterlockedDecrement (&num_reader) == 0)
CloseHandle (slave_reading);

bool need_xfer =
get_ttyp ()->switch_to_pcon_in && !get_ttyp ()->pcon_activated;

/* In GDB, transfer input based on setpgid() does not work because
GDB may not set terminal process group properly. Therefore,
transfer input here if isHybrid is set. */
if (isHybrid && !!masked != mask && xfer
if ((isHybrid || need_xfer) && !!masked != mask && xfer
&& GetStdHandle (STD_INPUT_HANDLE) == get_handle ())
{
if (mask && get_ttyp ()->pcon_input_state_eq (tty::to_nat))
Expand Down Expand Up @@ -1540,7 +1547,7 @@ fhandler_pty_slave::read (void *ptr, size_t& len)
if (ptr0)
{ /* Not tcflush() */
bool saw_eol = totalread > 0 && strchr ("\r\n", ptr0[totalread -1]);
mask_switch_to_pcon_in (false, saw_eol);
mask_switch_to_pcon_in (false, saw_eol || len == 0);
}
}

Expand Down Expand Up @@ -2222,6 +2229,15 @@ fhandler_pty_master::write (const void *ptr, size_t len)
return len;
}

if (to_be_read_from_pcon () && !get_ttyp ()->pcon_activated
&& get_ttyp ()->pcon_input_state == tty::to_cyg)
{
WaitForSingleObject (input_mutex, INFINITE);
fhandler_pty_slave::transfer_input (tty::to_nat, from_master,
get_ttyp (), input_available_event);
ReleaseMutex (input_mutex);
}

line_edit_status status = line_edit (p, len, ti, &ret);
if (status > line_edit_signalled && status != line_edit_pipe_full)
ret = -1;
Expand Down Expand Up @@ -3738,7 +3754,11 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp,
{
char pipe[MAX_PATH];
__small_sprintf (pipe,
#ifdef __MSYS__
"\\\\.\\pipe\\msys-%S-pty%d-master-ctl",
#else
"\\\\.\\pipe\\cygwin-%S-pty%d-master-ctl",
#endif
&cygheap->installation_key, ttyp->get_minor ());
pipe_request req = { GetCurrentProcessId () };
pipe_reply repl;
Expand Down