Skip to content

Commit

Permalink
Use os.login_tty() in pty.fork() on systems that lack os.forkpty().
Browse files Browse the repository at this point in the history
Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
  • Loading branch information
8vasu committed Feb 5, 2023
1 parent ffcb822 commit 287d09a
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 287d09a

Please sign in to comment.