File: tty.py

package info (click to toggle)
criu 4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 11,500 kB
  • sloc: ansic: 139,280; python: 7,484; sh: 3,824; java: 2,799; makefile: 2,659; asm: 1,137; perl: 206; xml: 117; exp: 45
file content (35 lines) | stat: -rwxr-xr-x 750 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import fcntl
import os
import pty
import termios

ctl = False


def child_prep(fd):
    global ctl
    if ctl:
        return
    ctl = True
    fcntl.ioctl(fd.fileno(), termios.TIOCSCTTY, 1)


def create_fds():
    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


def filename(pipef):
    st = os.fstat(pipef.fileno())
    return 'tty[%x:%x]' % (st.st_rdev, st.st_dev)


def dump_opts(sockf):
    st = os.fstat(sockf.fileno())
    return "--external", 'tty[%x:%x]' % (st.st_rdev, st.st_dev)