2018-09-20 22:22:34 +00:00
|
|
|
import fcntl
|
|
|
|
import os
|
|
|
|
import pty
|
|
|
|
import termios
|
|
|
|
|
2018-09-20 22:22:35 +00:00
|
|
|
ctl = False
|
|
|
|
|
|
|
|
|
2015-12-25 19:23:00 +03:00
|
|
|
def child_prep(fd):
|
2019-09-07 15:46:22 +03:00
|
|
|
global ctl
|
|
|
|
if ctl:
|
|
|
|
return
|
|
|
|
ctl = True
|
|
|
|
fcntl.ioctl(fd.fileno(), termios.TIOCSCTTY, 1)
|
2015-12-25 19:23:00 +03:00
|
|
|
|
2018-09-20 22:22:34 +00:00
|
|
|
|
2015-12-25 19:23:00 +03:00
|
|
|
def create_fds():
|
2019-09-07 15:46:22 +03:00
|
|
|
ttys = []
|
|
|
|
for i in range(10):
|
|
|
|
(fd1, fd2) = pty.openpty()
|
|
|
|
newattr = termios.tcgetattr(fd1)
|
|
|
|
newattr[3] &= ~termios.ICANON & ~termios.ECHO
|
|
|
|
termios.tcsetattr(fd1, termios.TCSADRAIN, newattr)
|
|
|
|
ttys.append((os.fdopen(fd1, "wb"), os.fdopen(fd2, "rb")))
|
|
|
|
return ttys
|
2015-12-25 19:23:00 +03:00
|
|
|
|
2018-09-20 22:22:34 +00:00
|
|
|
|
2015-12-25 19:23:00 +03:00
|
|
|
def filename(pipef):
|
2019-09-07 15:46:22 +03:00
|
|
|
st = os.fstat(pipef.fileno())
|
|
|
|
return 'tty[%x:%x]' % (st.st_rdev, st.st_dev)
|
2015-12-25 19:23:00 +03:00
|
|
|
|
2018-09-20 22:22:34 +00:00
|
|
|
|
2015-12-25 19:23:00 +03:00
|
|
|
def dump_opts(sockf):
|
2019-09-07 15:46:22 +03:00
|
|
|
st = os.fstat(sockf.fileno())
|
|
|
|
return "--external", 'tty[%x:%x]' % (st.st_rdev, st.st_dev)
|