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

Fix console mode restoring #262

Merged

Conversation

dscho
Copy link
Collaborator

@dscho dscho commented Mar 3, 2025

Under certain circumstances, when a non-MSYS process is spawned from an MSYS process that is spawned from a non-MSYS process that is spawned from an MSYS process, the console state can get corrupted by the MSYS2 runtime.

This is the case, for example, when spawning a background process that outputs to stdout from a Git hook.

This behavior is inherited from the Cygwin runtime which allows the same symptom to be reproduced as long as one is careful enough to force git.exe to use Cygwin's Bash to run its hooks.

The Cygwin core developer who is the only person to understand Cygwin's pseudo console handling was kind enough to fix this problem, and I backported it to the MSYS2 runtime v3.5.7.

This is a companion of git-for-windows/msys2-runtime#87

The required console mode for a non-cygwin process is different from
that for a cygwin process. There are currently three modes: tty::cygwin,
tty::native, and tty::restore. The latter two are for the non-cygwin
processes. tty::restore is the mode for the non-cygwin processes that
started the cygwin process, used to restore the previous behaviour.
tty::native is the mode that reflects some terminfo flags. The issue
below is caused because the console mode fails to be restored to the
previous console mode used by cmd.exe.
This patch redesigns the strategy to determine which mode should be
set on console close() to fix all similar problems. Previously, the
number of handle count is used to determine the appropriate console
mode. However, the handle count seems uncertain for that purpose.
In the new design, the relation ship between the master process and
the process that is about to close the console is mainly used. This
can provide more certain result than previous one.

Addresses: microsoft/git#730
Backported-from: 3312f2d (Cygwin: console: Redesign mode set strategy on close()., 2025-03-03)
Fixes: 30d2669 ("Cygwin: console: Fix clean up conditions in close()")
Reported-by: Mike Marcelais, Johannes Schindelin <[email protected]>
Signed-off-by: Takashi Yano <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
@lazka lazka merged commit cd64230 into msys2:msys2-3.5.7 Mar 3, 2025
1 check passed
@dscho
Copy link
Collaborator Author

dscho commented Mar 3, 2025

That was quick ;-)

@dscho
Copy link
Collaborator Author

dscho commented Mar 3, 2025

@lazka do you want me to take care of msys2/MSYS2-packages? (We should probably think about some sort of automation in the long run, so that this does not have to be done manually all the time.)

@lazka
Copy link
Member

lazka commented Mar 3, 2025

sure, will do.

@dscho
Copy link
Collaborator Author

dscho commented Mar 3, 2025

sure, will do.

Thank you!

lazka added a commit to lazka/MSYS2-packages that referenced this pull request Mar 3, 2025
lazka added a commit to msys2/MSYS2-packages that referenced this pull request Mar 3, 2025
@dscho dscho deleted the fix-non-cygwin-console-mode-on-close branch March 3, 2025 17:22
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.

3 participants