Skip to content

Commit f304ab8

Browse files
committed
core: split preserve_tty_fp() out into a function
1 parent f4cee16 commit f304ab8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

mitogen/core.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3680,20 +3680,24 @@ def _nullify_stdio(self):
36803680
os.dup2(fd, stdfd)
36813681
os.close(fd)
36823682

3683-
def _setup_stdio(self):
3684-
# #481: when stderr is a TTY due to being started via
3685-
# tty_create_child()/hybrid_tty_create_child(), and some privilege
3686-
# escalation tool like prehistoric versions of sudo exec this process
3687-
# over the top of itself, there is nothing left to keep the slave PTY
3688-
# open after we replace our stdio. Therefore if stderr is a TTY, keep
3689-
# around a permanent dup() to avoid receiving SIGHUP.
3683+
def _preserve_tty_fp(self):
3684+
"""
3685+
#481: when stderr is a TTY due to being started via tty_create_child()
3686+
or hybrid_tty_create_child(), and some privilege escalation tool like
3687+
prehistoric versions of sudo exec this process over the top of itself,
3688+
there is nothing left to keep the slave PTY open after we replace our
3689+
stdio. Therefore if stderr is a TTY, keep around a permanent dup() to
3690+
avoid receiving SIGHUP.
3691+
"""
36903692
try:
36913693
if os.isatty(2):
36923694
self.reserve_tty_fp = os.fdopen(os.dup(2), 'r+b', 0)
36933695
set_cloexec(self.reserve_tty_fp.fileno())
36943696
except OSError:
36953697
pass
36963698

3699+
def _setup_stdio(self):
3700+
self._preserve_tty_fp()
36973701
# When sys.stdout was opened by the runtime, overwriting it will not
36983702
# close FD 1. However when forking from a child that previously used
36993703
# fdopen(), overwriting it /will/ close FD 1. So we must swallow the

0 commit comments

Comments
 (0)