From 87c8ab432391335e72d7146d59d3252471ce91c4 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 23 Feb 2019 15:52:52 +0000 Subject: [PATCH] issue #550: fix up TTY ioctls on WSL 2016 Anniversary Update --- mitogen/core.py | 9 ++++++++- mitogen/parent.py | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mitogen/core.py b/mitogen/core.py index 607c4bfb..578337f7 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -140,7 +140,6 @@ try: except NameError: BaseException = Exception -IS_WSL = 'Microsoft' in os.uname()[2] PY24 = sys.version_info < (2, 5) PY3 = sys.version_info > (3,) if PY3: @@ -164,6 +163,14 @@ try: except NameError: next = lambda it: it.next() +# #550: prehistoric WSL did not advertise itself in uname output. +try: + fp = open('/proc/sys/kernel/osrelease') + IS_WSL = 'Microsoft' in fp.read() + fp.close() +except IOError: + IS_WSL = False + #: Default size for calls to :meth:`Side.read` or :meth:`Side.write`, and the #: size of buffers configured by :func:`mitogen.parent.create_socketpair`. This diff --git a/mitogen/parent.py b/mitogen/parent.py index f25bd6c2..a05bcbef 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -371,11 +371,11 @@ def create_child(args, merge_stdio=False, stderr_pipe=False, preexec_fn=None): def _acquire_controlling_tty(): os.setsid() - if sys.platform == 'linux2': + if sys.platform in ('linux', 'linux2'): # On Linux, the controlling tty becomes the first tty opened by a # process lacking any prior tty. os.close(os.open(os.ttyname(2), os.O_RDWR)) - if hasattr(termios, 'TIOCSCTTY'): + if hasattr(termios, 'TIOCSCTTY') and not mitogen.core.IS_WSL: # On BSD an explicit ioctl is required. For some inexplicable reason, # Python 2.6 on Travis also requires it. fcntl.ioctl(2, termios.TIOCSCTTY)