Skip to content

Cygwin: console: backport mode handling changes (v15, experimental) - #364

Closed
dscho wants to merge 3 commits into
msys2:msys2-3.6.10from
dscho:try-console-mode-v15
Closed

dscho wants to merge 3 commits into
msys2:msys2-3.6.10from
dscho:try-console-mode-v15

Conversation

@dscho

@dscho dscho commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

This is not expected to be the final version of this patch.

This is an experimental backport of Takashi Yano's v15 patch to msys2-3.6.10 for investigating console-mode and cleanup hangs involving concurrent native processes.

The preceding commit backports the prerequisite console-mode guards, including the companion standard-handle lifetime change in dtable.cc. This preserves the assumptions behind v15 instead of retaining the release branch's older unconditional mode changes.

Upstream review remains ongoing. This is not a claim that msys2/MSYS2-packages#6445 is resolved.

Currently, when cygwin app is launched, the console input mode is
set to tty::cygwin, even if the stdin is not a console. However,
it is not necessary because the cygwin app does not use stdin.
This also applies to stdout and stderr.

With this patch, the console mode is set only when std{in,out,err}
is a console for the cygwin app for better coexistence with non-
cygwin apps.

This is a prerequisite for the experimental backport of Takashi Yano's
v15 console-mode patch to msys2-3.6.10. The release branch's later,
already-applied suspension-before-mode ordering is preserved.

(cherry picked from commit bbd3710)
Assisted-by: GPT-6
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Previously, if two non-cygwin apps are started and one of them
exits first, the other one loosed appropriate console mode, since
the first one restored it to tty::cygwin. This patch counts the
active console process whose pgid is pgid of the tty and if the
result is zero (means the last non-cygwin foreground process),
restore console mode. To avoid race issue between apps modifying
console mode simultaneously, this patch also introduce a mutex
named `cons_mode_mutex`.

Known limitation:
In the case of non-overlayed spawn, there still exists a small
window in which another non-cygwin process may restore tty::cygwin
mode even though new non-cygwin app is about to start.

This is an experimental backport of Takashi Yano's v15 console-mode
patch to msys2-3.6.10. Its prerequisite,
bbd3710, is included in full by the
preceding commit. Upstream review is ongoing.
Message-ID: 20260913060128.1453-1-takashi.yano@nifty.ne.jp

Fixes: 48285aa ("Cygwin: console: Fix handling of Ctrl-S in Win7.")
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Assisted-by: GPT-6
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
…in apps

Avoid the cleanup/startup deadlock: cleanup can hold `cons_mode_mutex`
while waiting for a console master that a new owner cannot start until
acquiring that mutex. Startup must precede the mode-mutex wait without
changing the handshake or mode serialization.

Also avoid waiting forever for an owner that exited without clearing
ownership. A confirmed exit permits ending the wait only while the
captured owner is still recorded, excluding the -1 normal-retirement
sentinel. Preserve the published request for a replacement worker;
a missing worker is not an acknowledgement.

Assisted-by: GPT-6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho

dscho commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants