Skip to content

Commit

Permalink
Use os.login_tty() in pty.fork() fallback code.
Browse files Browse the repository at this point in the history
Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
  • Loading branch information
8vasu committed May 6, 2022
1 parent 329afe7 commit fd37005
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions Lib/pty.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,8 @@ def fork():
master_fd, slave_fd = openpty()
pid = os.fork()
if pid == CHILD:
# Establish a new session.
os.setsid()
os.close(master_fd)

# Slave becomes stdin/stdout/stderr of child.
os.dup2(slave_fd, STDIN_FILENO)
os.dup2(slave_fd, STDOUT_FILENO)
os.dup2(slave_fd, STDERR_FILENO)
if slave_fd > STDERR_FILENO:
os.close(slave_fd)

# Explicitly open the tty to make it become a controlling tty.
tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR)
os.close(tmp_fd)
os.login_tty(slave_fd)
else:
os.close(slave_fd)

Expand Down

0 comments on commit fd37005

Please sign in to comment.