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

Change || to && for whether MSYS is a tty #24

Merged
merged 1 commit into from Mar 7, 2018

Conversation

alexcrichton
Copy link
Contributor

The MSYS terminal appears to create pipes with the name msys- but don't
contain -pty, so this changes the || logic to && to ensure that the logic
here doesn't fire for MSYS terminals where piping is used to erroneously
diagnose a stdio stream as a tty.

Closes #23

The MSYS terminal appears to create pipes with the name `msys-` but *don't*
contain `-pty`, so this changes the `||` logic to `&&` to ensure that the logic
here doesn't fire for MSYS terminals where piping is used to erroneously
diagnose a stdio stream as a tty.

Closes softprops#23
@BurntSushi
Copy link
Contributor

Has someone tested this change in an MSYS terminal on Windows? Does detection still work as expected?

@BurntSushi
Copy link
Contributor

(I can test it later today if not.)

@alexcrichton
Copy link
Contributor Author

Oh certainly! I've tested this locally in an MSYS2 shell at least:

$ cargo run --example atty
   Compiling atty v0.2.6 (file:///C:/msys64/home/alex/code/atty)
    Finished dev [unoptimized + debuginfo] target(s) in 0.80 secs
     Running `target\debug\examples\atty.exe`
stdout? true
stderr? true
stdin? true
$ cargo run --example atty > test
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target\debug\examples\atty.exe`
[MSYS] ~/code/atty[master] $ cat test                                                                                                               [alex@DESKTOP-F3OQ4VV]
stdout? false
stderr? true
stdin? true
$ cargo run --example atty 2> test
stdout? true
stderr? false
stdin? true
$ echo a | cargo run --example atty
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target\debug\examples\atty.exe`
stdout? true
stderr? true
stdin? false

Copy link
Contributor

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, LGTM then!

@softprops softprops merged commit 7551d61 into softprops:master Mar 7, 2018
@softprops
Copy link
Owner

thanks folks

@softprops
Copy link
Owner

pushed these changes up in a new release on crates.io

BurntSushi added a commit to BurntSushi/atty that referenced this pull request Apr 21, 2018
This commit fixes a recent regression in pty detection for the cygwin
terminal. In particular, in 0.2.6, things worked:

    $ git checkout 0.2.6
    $ cargo run --example atty
    stdout? true
    stderr? true
    stdin? true

But in 0.2.7, things stopped working:

    $ git checkout 0.2.7
    $ cargo run --example atty
    stdout? false
    stderr? false
    stdin? false

Namely, all three of these should have returned `true`. The specific
reason why this stopped working was because softprops#24 introduced a change to
the detection logic where *both* the 'msys' and 'pty' strings needed to
be in the file descriptor's name, where the previous logic merely
required either of them. It turns out that both were wrong. For example,
in my cygwin terminal, the name of the stdout/stderr file descriptors is
(from the above example):

    \\cygwin-c5e39b7a9d22bafb-pty2-to-master

and stdin is:

    \\cygwin-c5e39b7a9d22bafb-pty2-from-master

This makes it clear why the regression happened, since this string only
contains `pty` but not `msys`.

If I run

    echo foo | cargo run --example atty

then the stdin file name is `\\cygwin-c5e39b7a9d22bafb-8728-pipe-0x5`.
My guess is that softprops#24 fixes the case when the stdin file name is
something like `\\msys-c5e39b7a9d22bafb-8728-pipe-0x5`, where the
previous logic would have falsely reported that as a tty on stdin.

In this commit, we change the logic to require the `pty` substring, and
additionally require *either* the `cygwin` or `msys` strings. The latter
check is strictly to reduce the rate of false positives (in the case
that an actual file name contains the substring `pty`).
@BurntSushi BurntSushi mentioned this pull request Apr 21, 2018
@BurntSushi
Copy link
Contributor

I think this PR caused a regression in cygwin terminals. I sat down and thought about it for a bit, and submitted a patch in #25 that I think should fix the regression and, I suspect, also keep the fix from this PR as well.

BurntSushi added a commit to BurntSushi/atty that referenced this pull request Apr 21, 2018
This commit fixes a recent regression in pty detection for the cygwin
terminal. In particular, in 0.2.6, things worked:

    $ git checkout 0.2.6
    $ cargo run --example atty
    stdout? true
    stderr? true
    stdin? true

But in 0.2.7, things stopped working:

    $ git checkout 0.2.7
    $ cargo run --example atty
    stdout? false
    stderr? false
    stdin? false

Namely, all three of these should have returned `true`. The specific
reason why this stopped working was because softprops#24 introduced a change to
the detection logic where *both* the 'msys' and 'pty' strings needed to
be in the file descriptor's name, where the previous logic merely
required either of them. It turns out that both were wrong. For example,
in my cygwin terminal, the name of the stdout/stderr file descriptors is
(from the above example):

    \\cygwin-c5e39b7a9d22bafb-pty2-to-master

and stdin is:

    \\cygwin-c5e39b7a9d22bafb-pty2-from-master

This makes it clear why the regression happened, since this string only
contains `pty` but not `msys`.

If I run

    echo foo | cargo run --example atty

then the stdin file name is `\\cygwin-c5e39b7a9d22bafb-8728-pipe-0x5`.
My guess is that softprops#24 fixes the case when the stdin file name is
something like `\\msys-c5e39b7a9d22bafb-8728-pipe-0x5`, where the
previous logic would have falsely reported that as a tty on stdin.

In this commit, we change the logic to require the `pty` substring, and
additionally require *either* the `cygwin` or `msys` strings. The latter
check is strictly to reduce the rate of false positives (in the case
that an actual file name contains the substring `pty`).
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.

None yet

3 participants