Skip to content

Commit

Permalink
test: improve variable names in pty_helper.py
Browse files Browse the repository at this point in the history
Using names like `parent_fd` and `child_fd` is more accurate here,
and doesn’t come with unnecessary negative connotations, even if
the previous naming is somewhat common terminology here.

PR-URL: #28688
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
addaleax authored and Trott committed Jul 17, 2019
1 parent 19618bd commit 971915e
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions test/pseudo-tty/pty_helper.py
Expand Up @@ -44,42 +44,42 @@ def pipe(sfd, dfd):
# Make select() interruptable by SIGCHLD.
signal.signal(signal.SIGCHLD, lambda nr, _: None)

master_fd, slave_fd = pty.openpty()
assert master_fd > STDIN
parent_fd, child_fd = pty.openpty()
assert parent_fd > STDIN

mode = termios.tcgetattr(slave_fd)
mode = termios.tcgetattr(child_fd)
# Don't translate \n to \r\n.
mode[1] = mode[1] & ~termios.ONLCR # oflag
# Disable ECHOCTL. It's a BSD-ism that echoes e.g. \x04 as ^D but it
# doesn't work on platforms like AIX and Linux. I checked Linux's tty
# driver and it's a no-op, the driver is just oblivious to the flag.
mode[3] = mode[3] & ~termios.ECHOCTL # lflag
termios.tcsetattr(slave_fd, termios.TCSANOW, mode)
termios.tcsetattr(child_fd, termios.TCSANOW, mode)

pid = os.fork()
if not pid:
os.setsid()
os.close(master_fd)
os.close(parent_fd)

# Ensure the pty is a controlling tty.
name = os.ttyname(slave_fd)
name = os.ttyname(child_fd)
fd = os.open(name, os.O_RDWR)
os.dup2(fd, slave_fd)
os.dup2(fd, child_fd)
os.close(fd)

os.dup2(slave_fd, STDIN)
os.dup2(slave_fd, STDOUT)
os.dup2(slave_fd, STDERR)
os.dup2(child_fd, STDIN)
os.dup2(child_fd, STDOUT)
os.dup2(child_fd, STDERR)

if slave_fd > STDERR:
os.close(slave_fd)
if child_fd > STDERR:
os.close(child_fd)

os.execve(argv[0], argv, os.environ)
raise Exception('unreachable')

os.close(slave_fd)
os.close(child_fd)

fds = [STDIN, master_fd]
fds = [STDIN, parent_fd]
while fds:
try:
rfds, _, _ = select.select(fds, [], [])
Expand All @@ -90,9 +90,9 @@ def pipe(sfd, dfd):
break

if STDIN in rfds:
if pipe(STDIN, master_fd):
if pipe(STDIN, parent_fd):
fds.remove(STDIN)

if master_fd in rfds:
if pipe(master_fd, STDOUT):
if parent_fd in rfds:
if pipe(parent_fd, STDOUT):
break

0 comments on commit 971915e

Please sign in to comment.