|
|
|
@ -173,6 +173,33 @@ class CreateChildStderrPipeTest(StdinSockMixin, StdoutSockMixin,
|
|
|
|
|
class TtyCreateChildTest(testlib.TestCase):
|
|
|
|
|
func = staticmethod(mitogen.parent.tty_create_child)
|
|
|
|
|
|
|
|
|
|
def test_dev_tty_open_succeeds(self):
|
|
|
|
|
# In the early days of UNIX, a process that lacked a controlling TTY
|
|
|
|
|
# would acquire one simply by opening an existing TTY. Linux and OS X
|
|
|
|
|
# continue to follow this behaviour, however at least FreeBSD moved to
|
|
|
|
|
# requiring an explicit ioctl(). Linux supports it, but we don't yet
|
|
|
|
|
# use it there and anyway the behaviour will never change, so no point
|
|
|
|
|
# in fixing things that aren't broken. Below we test that
|
|
|
|
|
# getpass-loving apps like sudo and ssh get our slave PTY when they
|
|
|
|
|
# attempt to open /dev/tty, which is what they both do on attempting to
|
|
|
|
|
# read a password.
|
|
|
|
|
tf = tempfile.NamedTemporaryFile()
|
|
|
|
|
try:
|
|
|
|
|
proc = self.func([
|
|
|
|
|
'bash', '-c', 'exec 2>%s; echo hi > /dev/tty' % (tf.name,)
|
|
|
|
|
])
|
|
|
|
|
deadline = time.time() + 5.0
|
|
|
|
|
mitogen.core.set_block(proc.stdin.fileno())
|
|
|
|
|
# read(3) below due to https://bugs.python.org/issue37696
|
|
|
|
|
self.assertEquals(mitogen.core.b('hi\n'), proc.stdin.read(3))
|
|
|
|
|
waited_pid, status = os.waitpid(proc.pid, 0)
|
|
|
|
|
self.assertEquals(proc.pid, waited_pid)
|
|
|
|
|
self.assertEquals(0, status)
|
|
|
|
|
self.assertEquals(mitogen.core.b(''), tf.read())
|
|
|
|
|
proc.stdout.close()
|
|
|
|
|
finally:
|
|
|
|
|
tf.close()
|
|
|
|
|
|
|
|
|
|
def test_stdin(self):
|
|
|
|
|
proc, info, _ = run_fd_check(self.func, 0, 'read',
|
|
|
|
|
lambda proc: proc.stdin.write(b('TEST')))
|
|
|
|
|