-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
std: /dev/ptmx
in MSYS2 is not recognized as a tty in std::io::IsTerminal
#119658
Comments
Cannot check the behavior on Linux right now, but if nobody complains about failing run-make tests, then |
Does it work with For msys2 without pseudoconsole support there's no way to really know if something is a tty or not so we use heuristics based on the pipe name, these may need updated. If msys2 is using the Windows pseudoconsole then it should just work as it should be detected as a normal Windows console handle (unless |
No, it doesn't help.
I did assume it was some missing heuristic in |
Ah, actually the problem is this check: rust/library/std/src/sys/windows/io.rs Lines 100 to 112 in efb3f11
The trouble is even if |
I created a fix in #119664 by simply removing the above code. This decreases the chances of a false negative at the cost of increasing the chances of a false positive. But I think simply inspecting the pipe name is overall the most reliable way to detect an msys2 tty. |
Why |
You'd have to ask msys2 why that is. Maybe it's a bug or maybe there's some reason for it. I don't know.
I don't think so. |
@mati865, maybe you know? |
Unfortunately I don't know much about Cygwin's internals. |
Unfortunately I am not familiar with Rust language. I assumed the rust code looks like following C code. #include <stdio.h>
#include <windows.h>
int main(void)
{
DWORD mode;
printf("%d\n", GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode));
printf("%d\n", GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &mode));
printf("%d\n", GetConsoleMode(GetStdHandle(STD_ERROR_HANDLE), &mode));
} That program prints 1 (TRUE) for all handles in msys2 environment with conpty enabled. |
@Biswa96 if that program is called
prints:
|
@tyan0 may provide some information about that. |
Fix tty detection for msys2's `/dev/ptmx` Our "true negative" detection assumes that if at least one std handle is a Windows console then no other handle will be a msys2 tty pipe. This turns out to be a faulty assumption in the case of redirection to `/dev/ptmx` in an msys2 shell. Maybe this is an msys2 bug but in any case we should try to make it work. An alternative to this would be to replace the "true negative" detection with an attempt to detect if we're in an msys environment (e.g. by sniffing environment variables) but that seems like it'd be flaky too. Fixes rust-lang#119658
/dev/ptmx is a device for native msys2 (cygwin) programs. I guess you are using native windows rust compiler. In that case, the program built is also native windows program. /dev/ptmx is a tty for native msys2 program, however it is just a pipe for native windows program. So, the result is as the author reported. You can confirm the behaviour with the code:
If you compile this using /usr/bin/gcc and run
however, with /mingw64/bin/gcc, the result is:
I do not think there is much meaning to check behaviour with /dev/ptmx for native windows program, because it does not provide any meaningful functions for native windows program. |
Rollup merge of rust-lang#119664 - ChrisDenton:mingw-pty, r=thomcc Fix tty detection for msys2's `/dev/ptmx` Our "true negative" detection assumes that if at least one std handle is a Windows console then no other handle will be a msys2 tty pipe. This turns out to be a faulty assumption in the case of redirection to `/dev/ptmx` in an msys2 shell. Maybe this is an msys2 bug but in any case we should try to make it work. An alternative to this would be to replace the "true negative" detection with an attempt to detect if we're in an msys environment (e.g. by sniffing environment variables) but that seems like it'd be flaky too. Fixes rust-lang#119658
I am bit curious why a test for native Windows platform runs a command like |
Test file is here: https://github.com/rust-lang/rust/blob/master/tests/run-make/emit-to-stdout/Makefile On Windows our "run-make" tests use msys2 (or git bash, but same difference) so the Makefile is cross-platform, This particular test is testing that emitting binary data to a tty correctly fails. This is definitely something that should be tested on Windows. I'm not totally sure why |
Yes, that's the purpose of adding such (failure) tests.
If I remember correctly, in the test I initially tried
but found that the tests would then fail, because stdout was already redirected in the test environment, so the expected error didn't happen. I used |
How to reproduce:
That test (
tests\run-make\emit-to-stdout\Makefile
) checks that rustc's behavior with options like--emit obj
is different depending on whether stdout is tty or not.That test uses
/dev/ptmx
as stdout and fails when run under MSYS2.cc @ChrisDenton
The text was updated successfully, but these errors were encountered: