From 22bab87821a02ed8cb6b3eb4b52c766a8f5cfee7 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Fri, 27 Jul 2018 02:31:34 +0100 Subject: [PATCH] issue #319: avoid TCSAFLUSH flag on WSL. Closes #319. --- docs/changelog.rst | 4 ++++ mitogen/parent.py | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index f55ab6d8..6726aa9f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -79,6 +79,10 @@ Core Library * `#307 `_: SSH login banner output containing the word 'password' is no longer confused for a password prompt. +* `#319 `_: SSH connections would + fail immediately on Windows Subsystem for Linux, due to use of `TCSAFLUSH` + with :func:`termios.tcsetattr`. The flag is omitted if WSL is detected. + * Debug logs containing command lines are printed with the minimal quoting and escaping required. diff --git a/mitogen/parent.py b/mitogen/parent.py index 54412717..4299d3cd 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -69,6 +69,8 @@ from mitogen.core import LOG from mitogen.core import IOLOG +IS_WSL = 'Microsoft' in os.uname()[2] + if mitogen.core.PY3: xrange = range @@ -125,10 +127,11 @@ def cfmakeraw(tflags): def disable_echo(fd): old = termios.tcgetattr(fd) new = cfmakeraw(old) - flags = ( - termios.TCSAFLUSH | - getattr(termios, 'TCSASOFT', 0) - ) + flags = getattr(termios, 'TCSASOFT', 0) + if not IS_WSL: + # issue #319: Windows Subsystem for Linux as of July 2018 throws EINVAL + # if TCSAFLUSH is specified. + flags |= termios.TCSAFLUSH termios.tcsetattr(fd, flags, new)