- When temporarily attaching a console, the timing of acquiring
attach_mutex was not appropriate. This sometimes caused master
forwarding thread to crash on Ctrl-C in Windows 7. This patch
fixes the issue.
- The internal handles in HPCON should not be inheritable, however,
the current code duplicates them as inheritable when handing over
ownership of the pseudo console. This patch fixes the issue.
Addresses: https://cygwin.com/pipermail/cygwin/2022-April/251222.html
- Currently, close_pseudoconsole() is called unconditionally from
fhandler_termios::process_sigs() on Ctrl-C. This causes deadlock
if Ctrl-C is pressed while setup_pseudoconsole() is called. With
this patch, close_pseudoconsole() is called only if the master
process is the owner of the nat-pipe to avoid the deadlock.
- Currently, tty::pcon_start flag is cleared before transfer_input()
in master::write(), however, the code in setup_pseudoconsole()
waits for transfer_input() using tty::pcon_start. This possibly
causes the race issue. The patch fixes this potential issue.
- This patch removes the old code which calls transfer_input() but
is no longer needed. These code was necessary indeed in the past,
however, as a result of recent frequent code changes, it is no
longer needed.
- Previously, reset_switch_to_nat_pipe() is called from many places
in pty code. This patch reorganizes that. With this patch, it is
called only from bg_check() and setpgid_aux(). The calls which
does not have enough reason have been omitted.
- To make read() work properly in canonical mode, writing to the pty
pipe should be done line by line. However, only CR was treated as
line separator previously in transfer_input(). This patch fixes
the issue.
- Previously, the PID_NEW_PG flag was also used as a marker for GDB
with non-cygwin inferior, unlike its original meaning. With this
patch, the condition exec_dwProcessId == dwProcessId is used as a
marker for that instead.
- transfer_input() function uses console api, so it should be guarded
by attach_mutex. However, in most cases, it is missing. This patch
fixes the issue.
- This patch communalizes the code for attaching another console
temporarily and resuming to the original attach state, because
there were a plurality of similar codes throughout.
- This patch revises the acquiring/releasing timing for attach_mutex
to make the period in which it is being acquired shorter. Further,
acquiring/releasing are added to where they are missing but needed.
- 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.
- When Ctrl-C terminates a non-cygwin process on a pseudo console,
pty master attaches to the pseudo console first, and send
CTRL_C_EVENT. If the non-cygwin process closes the pseudo console
before the pty master calls FreeConsole(), the pty master process
will crash. With this patch, pty master process takes over the
ownership of the pseudo console, and closes it by myself.
- With this patch, unique invisible consoles are created for each pty
to isolate CTRL_C_EVENTs between ptys. This is necessary by Ctrl-C
handling in fhandler_termios::process_sigs() for non-cygwin apps
started in pty if the pseudo console is disabled.
- The commit "Cygwin: console: Redesign handling of special keys."
removes special treatment for pty in with pseudo console activated,
however, it is necessary on second thought. This is because sending
CTRL_C_EVENT to non-cygwin apps will be done in pseudo console,
therefore, sending it in fhandler_pty_master::write() duplicates
that event for non-cygwin apps.
- After some recent changes for special keys handling break the
apps which open pty (such as script command). If the app which
opens pty is executed in console, the following issues occur.
1) If the script command was started from non-cygwin shell
(such as cmd.exe), another cygwin app started in pty slave
cannot receive Ctrl-C.
2) If non-cygwin app is executed in pty slave, the app which
opened the pty (e.g. script command) crashes by Ctrl-C.
This patch fixes these issues.
- The inferior of the GDB cannot be continued after SIGINT even
though nopass option is set. This seems because cygwin GDB does
not support hooking cygwin signal. Therefore, a workaround for
GDB is added. With this patch, only CTRL_C_EVENT is sent to the
GDB inferior by Ctrl-C and sending SIGINT is omitted. Note that
"handle SIGINT (no)pass" command does not take effect even with
or without this patch.
- This patch fixes the handle leak which occurs when exec() fails
with an error. The duplicated handles will be closed when the
exec'ed process is terminated. However, if exec() fails, the code
path does not reach to the code closing the duplicated handles.
To implement this fix more appropriately, the setup, cleanup and
closing pty codes which was previously located in spawn.cc are
encapsulated into the fhandler_pty_slave class functions.
- This patch commonize the code which processes special keys in pty
and console to improve maintanancibility. As a result, some small
bugs have been fixed.
- Currently, there is no chance to change console mode for non-cygwin
inferior of GDB. With this patch, the console mode is changed to
tty::native in CreateProcess() and ContinueDebugEvent() hooked in
fhandler_console.
- Currently, pty discards input only in from_master pipe on signal.
Due to this, if pty is started without pseudo console support and
start a non-cygwin process from cmd.exe, type adhead input is not
discarded on signals such as Ctrl-C. This patch fixes the issue.
- With this patch, the code to wait for completion of forwarding of
output from non-cygwin app is revised so that it can more reliably
detect the completion.
- If the slave process writes a lot of text output, doecho() can
cause deadlock. This is because output_mutex is held in slave::
write() and if WriteFile() is blocked due to pipe full, doecho()
tries to acquire output_mutex and gets into deadlock. With this
patch, the deadlock is prevented on the sacrifice of atomicity
of doecho().
- If the from_master is closed before cleaning up other pipes, such
as from_slave_nat, the same pty may be allocated and pty master may
try to open the pipe which is not closed yet, and it will fail.
This patch fixes the issue.
- Closing attach_mutex and recreating it causes the race issue
between pty and console codes. With this patch, attach_mutex
is created only once in a process which opens pty, and never
closed in order to avoid this issue.
Addresses:
https://cygwin.com/pipermail/cygwin-developers/2021-December/012548.html
- If master_fwd_thread is terminated by cygthread::terminate_thread(),
the opportunity to release tmp_pathbuf is missed, resulting in a
memory leak. This patch fixes the issue.
- GDB inferior may be suspended while the inferior grabs mutex.
This causes deadlock in terminal I/O. With this patch, timeout
for waiting mutex is set to 0 for the debugger process when the
process calls CreateProcess() with DEBUG_PROCESS flag to avoid
deadlock. This may cause the race issue in GDB, however, there
is no other way than that.
Addresses:
https://cygwin.com/pipermail/cygwin-developers/2021-December/012542.html
- This patch fixes the failure of input switching between io_handle
and io_handle_nat. This very rarely happens, however, input is
wrongly switched to io_handle_nat even though the non-cygwin app
is in the background.
- The recent commit "Cygwin: pty: Add missing input transfer when
switch_to_pcon_in state." causes regression that rlwrap cannot
work with cmd.exe. This patch fixes the issue.
- The recent commit: "Cygwin: pty: Fix Ctrl-C handling for non-cygwin
apps in background." causes the problem that cmd.exe is terminated
by Ctrl-C even if it is running in pseudo console. This patch fixes
the issue.
- With pseudo console enabled, if the non-cygwin app is started in
the background and put it into the foreground, the process cannot
be stopped by Ctrl-C. This patch fixes the issue.
- This patch fixes the bug that input is wrongly sent to io_handle_nat
rather than io_handle when neither read() nor select() is called
after the cygwin app is started from non-cygwin app. This happens
only if psuedo console is disabled.
Addresses:
https://cygwin.com/pipermail/cygwin-patches/2021q4/011587.html
xterm 368 and mintty 3.5.1 implement a new feature to support
notification of terminal scaling via font zooming also if the terminal
text dimensions (rows/columns) stay unchanged, using
ioctl(TIOCSWINSZ), raising SIGWINCH;
this patches cygwin to support that scenario