Skip to content

Commit 97f068c

Browse files
authored
Merge pull request #80 from Data-hYg/master
Fix: Fallback to internal PTY setup when os.login_tty is unavailable (improves AIX and Solaris support)
2 parents 5e59fec + f16b54e commit 97f068c

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

ptyprocess/_fork_pty.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
"""Substitute for the forkpty system call, to support Solaris.
1+
"""
2+
Provides an alternative PTY forking mechanism.
3+
4+
This implementation serves as a substitute for Python's standard `pty.fork()`
5+
functionality, especially on platforms where `os.login_tty()` is unavailable
6+
in the Python build (e.g., some AIX configurations) or where the standard
7+
implementation is problematic (e.g., historically on Solaris).
28
"""
39
import os
410
import errno
@@ -7,17 +13,26 @@
713
from .util import PtyProcessError
814

915
def fork_pty():
10-
'''This implements a substitute for the forkpty system call. This
11-
should be more portable than the pty.fork() function. Specifically,
12-
this should work on Solaris.
13-
14-
Modified 10.06.05 by Geoff Marshall: Implemented __fork_pty() method to
15-
resolve the issue with Python's pty.fork() not supporting Solaris,
16-
particularly ssh. Based on patch to posixmodule.c authored by Noah
17-
Spurrier::
18-
16+
'''This implements a substitute for the functionality of pty.fork(),
17+
aiming for greater portability, especially on systems where Python's
18+
os.login_tty() is unavailable or pty.fork() is problematic.
19+
20+
It is designed to work on:
21+
- Solaris systems (addressing historical issues with Python's pty.fork()).
22+
- AIX systems where os.login_tty() might not be compiled into Python.
23+
- Other Unix-like systems that might lack a functional os.login_tty().
24+
25+
The core logic for establishing a new session and making the pseudo-terminal
26+
the controlling terminal is handled herein, similar to the operations
27+
typically performed by login_tty().
28+
29+
Historical Context (Original Solaris solution by Geoff Marshall, 10.06.05):
30+
The method was initially implemented to resolve issues with Python's
31+
pty.fork() on Solaris, particularly for applications like ssh. It was
32+
inspired by a patch to Python's posixmodule.c authored by Noah Spurrier:
1933
http://mail.python.org/pipermail/python-dev/2003-May/035281.html
20-
34+
This approach has been generalized to cover other platforms or scenarios
35+
where os.login_tty() is not available.
2136
'''
2237

2338
parent_fd, child_fd = os.openpty()

ptyprocess/ptyprocess.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
_platform.startswith('solaris') or
2929
_platform.startswith('sunos'))
3030

31-
if _is_solaris:
31+
try:
32+
from os import login_tty
33+
except ImportError:
34+
_no_login_tty = True
35+
else:
36+
_no_login_tty = False
37+
38+
if _is_solaris or _no_login_tty:
3239
use_native_pty_fork = False
3340
from . import _fork_pty
3441
else:

0 commit comments

Comments
 (0)